• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Create a Series<T> Bool object from a Multi-Time Frame Custom Method

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Create a Series<T> Bool object from a Multi-Time Frame Custom Method

    I need help in understanding how a Series<T> Bool object performs calculations in a Multi-Time Frame strategy.

    Below are some specific bits of code from a strategy that are needed to clarify my issue.


    Strategy specifics

    Primary bars object: 3 minutes


    Code:
    Series<bool> primaryCodeLongOK;
    
    protected override void OnStateChange()
         {
              if (State == State.SetDefaults)
              {
                   Calculate          = Calculate.OnEachTick;
    
                   primaryCodeLongOK = new Series<bool>(this,MaximumBarsLookBack.Infinite);
    
              }
              else if (State == State.Configure)
              {
                   AddDataSeries(Instrument.FullName, Data.BarsPeriodType.Minute, 6, Data.MarketDataType.Last);
                   AddDataSeries(Instrument.FullName, Data.BarsPeriodType.Minute, 15, Data.MarketDataType.Last);
                   AddDataSeries(Instrument.FullName, Data.BarsPeriodType.Minute, 65, Data.MarketDataType.Last);
              }
         }
    
         protected override void OnBarUpdate()
         {
              // ENTRIES
    
              // First Tick Of Bar is the bar Open, on the chart timeframe
              if (IsFirstTickOfBar && BarsInProgress == 0 && Position.MarketPosition == MarketPosition.Flat)
              {
                   // gather criteria flags
                   bool primary_Long = PrimaryCodeLong();     // go to the custom Method, execute the code, then come back here
    
                   // store in the boolean series
                   primaryCodeLongOK[0] = primary_Long;
    
    
                   // try to open a new trade
                   if (primary_Long)
                   {
                        EnterLong("LE1");
                   }
              }
         }
    
    
         // custom Methods
    
         private bool PrimaryCodeLong()
         {
              //LONG FORMULA - OPEN
              bool signalValid =      (MACD(BarsArray[0], 10, 20, 9).Diff[0] > 0)
                             &&
                             (EMA(BarsArray[1], 10)[2] < EMA(BarsArray[1], 10)[1])
                             &&
                             (Stochastics(BarsArray[2], 6, 7, 8).K[1] >= 90)
                             &&
                             (RSI(BarsArray[3], 19, 1)[1] >= 20);
    
              return signalValid;
         }



    The time frames of 3, 6, 15, and 65 minutes are all part of the custom Method. All of these component time frames have different times when their “bars ago” will change. Sometimes they will be aligned, sometimes they won’t.

    Let’s say that “primaryCodeLongOK[0]” was valid at the 10:42 bar of the “3 min. Primary Bars object” and LongEntry was entered.

    Once Long, print statements are also triggered at the same time.

    Print (Instrument.FullName + " "+Times[0][0].ToString("MM/dd/yy HH:mm:ss")+" primaryCodeLongOK[1]: "+primaryCodeLongOK[1]);
    Print (Instrument.FullName + " "+Times[0][0].ToString("MM/dd/yy HH:mm:ss")+" primaryCodeLongOK[2]: "+primaryCodeLongOK[2]);
    Print (Instrument.FullName + " "+Times[0][0].ToString("MM/dd/yy HH:mm:ss")+" primaryCodeLongOK[3]: "+primaryCodeLongOK[3]);
    Print (Instrument.FullName + " "+Times[0][0].ToString("MM/dd/yy HH:mm:ss")+" primaryCodeLongOK[4]: "+primaryCodeLongOK[4]);
    Print (Instrument.FullName + " "+Times[0][0].ToString("MM/dd/yy HH:mm:ss")+" primaryCodeLongOK[5]: "+primaryCodeLongOK[5]);
    Print (Instrument.FullName + " "+Times[0][0].ToString("MM/dd/yy HH:mm:ss")+" primaryCodeLongOK[6]: "+primaryCodeLongOK[6]);

    Would the True/False print calculations take into account the component parts and the alignment of the varying multi-time frames within the custom Method when deciding if the previous “3 min. Primary Bars objects” were valid?


    Another hypothetical. A “for loop” is created to be calculate if “primaryCodeLongOK[i]” was TRUE for any of the previous XX “3 min. Primary Bars objects”.

    Would the “for loop” calculations take into account the component parts and the alignment of the varying multi-time frames within the custom Method when deciding if the previous “3 min. Primary Bars objects” were valid?

    Thanks in advance.
    Last edited by ArmKnuckle; 11-19-2019, 04:09 AM.

    #2
    Hello ArmKnuckle,

    I need help in understanding how a Series<T> Bool object performs calculations in a Multi-Time Frame strategy.
    The bool series would not do any calculations specifically, this is just a series of bool placeholders which can be true or false depending on what you set that slot to. This series is synced with the Primary series so it would have slots in the same pattern as your primary.


    Would the True/False print calculations take into account the component parts and the alignment of the varying multi-time frames within the custom Method when deciding if the previous “3 min. Primary Bars objects” were valid?

    Would the “for loop” calculations take into account the component parts and the alignment of the varying multi-time frames within the custom Method when deciding if the previous “3 min. Primary Bars objects” were valid?
    I am not certain I understand the wording you used here: "component parts and the alignment", can you clarify your questions?

    Very likely for these questions you can use a Print to output what your script is doing to better understand the context of what the script sees.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by faisamtrader, Today, 10:31 AM
    1 response
    16 views
    0 likes
    Last Post NinjaTrader_Tyler  
    Started by ChazJ, Today, 09:48 AM
    1 response
    3 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by maxie, Today, 10:01 AM
    1 response
    7 views
    0 likes
    Last Post NinjaTrader_Melissa  
    Started by Bionian, Today, 09:36 AM
    1 response
    8 views
    0 likes
    Last Post NinjaTrader_PaulH  
    Started by tomd, Today, 09:48 AM
    1 response
    14 views
    0 likes
    Last Post NinjaTrader_Ariana  
    Working...
    X