original_docstring: Define what will be done in a single step, including creating and closing trades
docstring: Define what will be done in a single step, including creating and closing trades
docstring_tokens: Define what will be done in a single step including creating and closing trades
code: def next(self):
          """Define what will be done in a single step, including creating and closing trades"""
  
          # Determine which set of moving averages to use
          curdate = self.datetime.date(0)
          dtidx = None    # Will be index
          # Determine which period (if any) we are in
          for sd, ed in self.date_combos:
              # Debug output
              #print('{}: {} < {}: {}, {} < {}: {}'.format(
              #    len(self), sd, curdate, (sd <= curdate), curdate, ed, (curdate <= ed)))
              if sd <= curdate and curdate <= ed:
                  dtidx = (sd, ed)
          # Debug output
          #print('{}: the dtixdx is {}, and curdate is {};'.format(len(self), dtidx, curdate))
          for d in self.getdatanames():    # Looping through all symbols
              pos = self.getpositionbyname(d).size or 0
              if dtidx is None:    # Not in any window
                  break            # Don't engage in trades
              if pos == 0:    # Are we out of the market?
                  # Consider the possibility of entrance
                  # Notice the indexing; [0] always mens the present bar, and [-1] the bar immediately preceding
                  # Thus, the condition below translates to: "If today the regime is bullish (greater than
                  # 0) and yesterday the regime was not bullish"
                  if self.regime[d][dtidx][0] > 0 and self.regime[d][dtidx][-1] <= 0:    # A buy signal
                      self.buy(data=self.getdatabyname(d))
  
              else:    # We have an open position
                  if self.regime[d][dtidx][0] <= 0 and self.regime[d][dtidx][-1] > 0:    # A sell signal
                      self.sell(data=self.getdatabyname(d))
code_tokens: def next ( self ) : curdate = self . datetime . date ( 0 ) dtidx = None for sd , ed in self . date_combos : if sd <= curdate and curdate <= ed : dtidx = ( sd , ed ) for d in self . getdatanames ( ) : pos = self . getpositionbyname ( d ) . size or 0 if dtidx is None : break if pos == 0 : if self . regime [ d ] [ dtidx ] [ 0 ] > 0 and self . regime [ d ] [ dtidx ] [ - 1 ] <= 0 : self . buy ( data = self . getdatabyname ( d ) ) else : if self . regime [ d ] [ dtidx ] [ 0 ] <= 0 and self . regime [ d ] [ dtidx ] [ - 1 ] > 0 : self . sell ( data = self . getdatabyname ( d ) )
short_docstring: Define what will be done in a single step, including creating and closing trades
short_docstring_tokens: Define what will be done in a single step including creating and closing trades
comment: """Define what will be done in a single step, including creating and closing trades"""$SEP$# Determine which set of moving averages to use$SEP$# Will be index$SEP$# Determine which period (if any) we are in$SEP$# Debug output$SEP$#print('{}: {} < {}: {}, {} < {}: {}'.format($SEP$#    len(self), sd, curdate, (sd <= curdate), curdate, ed, (curdate <= ed)))$SEP$# Debug output$SEP$#print('{}: the dtixdx is {}, and curdate is {};'.format(len(self), dtidx, curdate))$SEP$# Looping through all symbols$SEP$# Not in any window$SEP$# Don't engage in trades$SEP$# Are we out of the market?$SEP$# Consider the possibility of entrance$SEP$# Notice the indexing; [0] always mens the present bar, and [-1] the bar immediately preceding$SEP$# Thus, the condition below translates to: "If today the regime is bullish (greater than$SEP$# 0) and yesterday the regime was not bullish"$SEP$# A buy signal$SEP$# We have an open position$SEP$# A sell signal