Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multiple Time Frame

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

    Multiple Time Frame

    I am trying to put certain conditions in a larger time frame using BarsInProgress ==1 and then some conditions in smaller time frame using BarsInProgress == 0, but the execution is not happening.

    There is no coding error but it doesn't execute.

    protected override void Initialize()
    {
    CalculateOnBarClose = true;

    Add(PeriodType.Minute, 240);

    }


    protected override void OnBarUpdate()
    {

    if (BarsInProgress == 1)
    {
    if (
    Close[0] > EMA(Close, 14)[0] // CONDITIONS IN LARGER TIME FRAME LIKE 240-MINUTE
    )
    {
    if (BarsInProgress == 0)
    {
    if (CrossAbove(Close, EMA(Close, 14), 1)) // CONDITIONS IN SMALLER TIME FRAME LIKE 60-MINUTE
    {
    EnterLong(1, "");
    }

    }
    }


    }



    }

    #2
    Hello piyushc,

    Thanks for your post.

    The sequence of your coding would prohibit entry because you cannot have BarsInProgress == 0 true and BarsInProgress == 1 true at the same time, it will always be one or the other that calls OnBarUpdate.

    You might try:

    Code:
    if (CurrentBars[1] < 14) return;  // Do not process until enough bars loaded for EMA on 240 minute (I am assuming 240 minute is the higher time frame)
    
    if (BarsInProgress != 0) return;  // only process on the chart bars
    
    if (Close[0] >EMA(Closes[1], 14)[0] && CrossAbove(Close, EMA(Close, 14), 1))
    {
    EnterLong (1, "");
    }
    Closes[1] refers to the close series of the added data series so the statement Close[0] >EMA(Closes[1] is comparing the current value of Close to the 14 period EMA on the 240 minute data series.

    References:
    http://ninjatrader.com/support/helpG...t7/?closes.htm
    http://ninjatrader.com/support/helpG...urrentbars.htm
    http://ninjatrader.com/support/helpG...nstruments.htm

    Comment


      #3
      This works perfectly.
      Thanks a lot Paul.
      Especially, for clearing this aspect "you cannot have BarsInProgress == 0 true and BarsInProgress == 1 true at the same time, it will always be one or the other that calls OnBarUpdate"

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by charlesugo_1, 05-26-2026, 05:03 PM
      0 responses
      57 views
      0 likes
      Last Post charlesugo_1  
      Started by DannyP96, 05-18-2026, 02:38 PM
      1 response
      143 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 05-11-2026, 05:56 AM
      0 responses
      161 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 05-10-2026, 08:12 PM
      0 responses
      97 views
      0 likes
      Last Post CarlTrading  
      Started by Hwop38, 05-04-2026, 07:02 PM
      0 responses
      276 views
      0 likes
      Last Post Hwop38
      by Hwop38
       
      Working...
      X