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

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
    Paul H.NinjaTrader Customer Service

    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 wzgy0920, 04-20-2024, 06:09 PM
      2 responses
      26 views
      0 likes
      Last Post wzgy0920  
      Started by wzgy0920, 02-22-2024, 01:11 AM
      5 responses
      32 views
      0 likes
      Last Post wzgy0920  
      Started by wzgy0920, 04-23-2024, 09:53 PM
      2 responses
      49 views
      0 likes
      Last Post wzgy0920  
      Started by Kensonprib, 04-28-2021, 10:11 AM
      5 responses
      193 views
      0 likes
      Last Post Hasadafa  
      Started by GussJ, 03-04-2020, 03:11 PM
      11 responses
      3,235 views
      0 likes
      Last Post xiinteractive  
      Working...
      X