Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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, 05: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 andrewtrades, Today, 04:57 PM
    1 response
    5 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by chbruno, Today, 04:10 PM
    0 responses
    3 views
    0 likes
    Last Post chbruno
    by chbruno
     
    Started by josh18955, 03-25-2023, 11:16 AM
    6 responses
    436 views
    0 likes
    Last Post Delerium  
    Started by FAQtrader, Today, 03:35 PM
    0 responses
    7 views
    0 likes
    Last Post FAQtrader  
    Started by rocketman7, Today, 09:41 AM
    5 responses
    19 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Working...
    X