Overall Statistics
Total Trades
0
Average Win
0%
Average Loss
0%
Compounding Annual Return
0%
Drawdown
0%
Expectancy
0
Net Profit
0%
Sharpe Ratio
0
Probabilistic Sharpe Ratio
0%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0
Beta
0
Annual Standard Deviation
0
Annual Variance
0
Information Ratio
0
Tracking Error
0
Treynor Ratio
0
Total Fees
$0.00
# This import statement causes AddForex() to fail when the market is set. Why?
from AJS_PB01_TF1 import *

class AJS_PB01(QCAlgorithm):
    '''
    A development system for trading intra-day pull-backs in trends.
    Intended for Forex.
    '''

    def Initialize(self):
        
        self.SetTimeZone("America/New_York")
        
        # Backtest variables
        self.SetStartDate(2020, 8, 5)   # Set Start Date
        self.SetEndDate(2020, 8, 5)     # Set End Date
        self.SetCash(100000)            # Set Strategy Cash
        
        # System variables
        tf1 = timedelta(minutes=5)
        ema1_len = 8
        ema2_len = 21
        ema3_len = 40
        
        # Instrument(s)
        instrument = "EURUSD"
        
        # Why does this not work with the import statement above?
        # symbol = self.AddForex(instrument, Resolution.Minute, Market.Oanda, False).Symbol
        symbol = self.AddForex(instrument, Resolution.Minute).Symbol
        
        self.Consolidate(instrument, tf1, self.tf1_bar_handler)
        
        self.tf1_setup = AJS_PB01_TF1(ema1_len, ema2_len, ema3_len)


    def OnData(self, data):
        pass
        
        
    def tf1_bar_handler(self, bar):
        '''
        Once every TF1 bar, update set-up time frame objects.
        '''
        # Update TF1 set-up object.
        self.tf1_setup.Update(bar)
        
        # Test
        self.Plot("Test Plot", "Output 1", self.tf1_setup.Test()[0])
        self.Plot("Test Plot", "Output 2", self.tf1_setup.Test()[1])
        self.Plot("Test Plot", "Output 3", self.tf1_setup.Test()[2])
class AJS_PB01_TF1():
    '''
    Holds TF1 information and functionality, including set-up detection.
    '''
    
    def __init__(self,  ema1_len,
                        ema2_len,
                        ema3_len
                        ):
        
        self.ema1_len = ema1_len
        self.ema2_len = ema2_len
        self.ema3_len = ema3_len
        
        self.ema1 = ExponentialMovingAverage(ema1_len)
        self.ema2 = ExponentialMovingAverage(ema2_len)
        self.ema3 = ExponentialMovingAverage(ema3_len)
    
    
    def Update(self, bar):
        # Indicator values
        self.ema1.Update(bar.EndTime, bar.Close)
        self.ema2.Update(bar.EndTime, bar.Close)
        self.ema3.Update(bar.EndTime, bar.Close)
    
    
    def Test(self):
        return [self.ema1.Current.Value,
                self.ema2.Current.Value,
                self.ema3.Current.Value]