build/strategies.py
def next(self):
        """
        For every bar in the csv, runs the moving average strategy and creates a buy, sell, or close order
        when needed. If 50 day moving average is above 200 day moving average, buy order is created. If opposite
        then sell order is created. 

        """
        # Check for open orders
        if self.order:
            return

        # dummy initialization for testing, doesn't actually do anything except log if volatile or not
        self.log(f'Volatile?: {self.tvi[0]}')
        
        # Check if we are in the market
        if not self.position:
            # We are not in the market, look for a signal to OPEN trades 

            #If the Trends Volatility Indicator returns a positive, orders a sell order
            if self.tvi[0] == 1:
                self.log(f'SELL CREATE {self.dataclose[0]:2f}')
                self.order = self.sell()
            
            #If the 50 SMA is above the 200 SMA
            if self.fast_sma[0] > self.slow_sma[0] and self.fast_sma[-1] < self.slow_sma[-1]:
                self.log(f'BUY CREATE {self.dataclose[0]:2f}')
                # Keep track of the created order to avoid a 2nd order
                self.order = self.buy()
            #Otherwise if the 50 SMA is below the 200 SMA   
            elif self.fast_sma[0] < self.slow_sma[0] and self.fast_sma[-1] > self.slow_sma[-1]:
                self.log(f'SELL CREATE {self.dataclose[0]:2f}')
                # Keep track of the created order to avoid a 2nd order
                self.order = self.sell()
        else:
            # We are already in the market, look for a signal to CLOSE trades
            if len(self) >= (self.bar_executed + 5):
                self.log(f'CLOSE CREATE {self.dataclose[0]:2f}')
                #self.order = self.close() 

        For every bar in the csv, runs the moving average strategy and creates a buy, sell, or close order
        when needed. If 50 day moving average is above 200 day moving average, buy order is created. If opposite
        then sell order is created. 

        
For every bar in the csv, runs the moving average strategy and creates a buy, sell, or close order
when needed. If 50 day moving average is above 200 day moving average, buy order is created. If opposite
then sell order is created.
For every bar in the csv runs the moving average strategy and creates a buy sell or close order when needed . If 50 day moving average is above 200 day moving average buy order is created . If opposite then sell order is created .
def next(self):
        if self.order:
            return
        self.log(f'Volatile?: {self.tvi[0]}')
        if not self.position:
            if self.tvi[0] == 1:
                self.log(f'SELL CREATE {self.dataclose[0]:2f}')
                self.order = self.sell()
            if self.fast_sma[0] > self.slow_sma[0] and self.fast_sma[-1] < self.slow_sma[-1]:
                self.log(f'BUY CREATE {self.dataclose[0]:2f}')
                self.order = self.buy()
            elif self.fast_sma[0] < self.slow_sma[0] and self.fast_sma[-1] > self.slow_sma[-1]:
                self.log(f'SELL CREATE {self.dataclose[0]:2f}')
                self.order = self.sell()
        else:
            if len(self) >= (self.bar_executed + 5):
                self.log(f'CLOSE CREATE {self.dataclose[0]:2f}')
def next ( self ) : if self . order : return self . log ( f'Volatile?: {self.tvi[0]}' ) if not self . position : if self . tvi [ 0 ] == 1 : self . log ( f'SELL CREATE {self.dataclose[0]:2f}' ) self . order = self . sell ( ) if self . fast_sma [ 0 ] > self . slow_sma [ 0 ] and self . fast_sma [ - 1 ] < self . slow_sma [ - 1 ] : self . log ( f'BUY CREATE {self.dataclose[0]:2f}' ) self . order = self . buy ( ) elif self . fast_sma [ 0 ] < self . slow_sma [ 0 ] and self . fast_sma [ - 1 ] > self . slow_sma [ - 1 ] : self . log ( f'SELL CREATE {self.dataclose[0]:2f}' ) self . order = self . sell ( ) else : if len ( self ) >= ( self . bar_executed + 5 ) : self . log ( f'CLOSE CREATE {self.dataclose[0]:2f}' )
For every bar in the csv, runs the moving average strategy and creates a buy, sell, or close order
when needed.
For every bar in the csv runs the moving average strategy and creates a buy sell or close order when needed .
"""
        For every bar in the csv, runs the moving average strategy and creates a buy, sell, or close order
        when needed. If 50 day moving average is above 200 day moving average, buy order is created. If opposite
        then sell order is created. 

        """ # Check for open orders # dummy initialization for testing, doesn't actually do anything except log if volatile or not # Check if we are in the market # We are not in the market, look for a signal to OPEN trades  #If the Trends Volatility Indicator returns a positive, orders a sell order #If the 50 SMA is above the 200 SMA # Keep track of the created order to avoid a 2nd order #Otherwise if the 50 SMA is below the 200 SMA    # Keep track of the created order to avoid a 2nd order # We are already in the market, look for a signal to CLOSE trades #self.order = self.close() 
self