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 andrewtrades, Today, 04:57 PM
      0 responses
      3 views
      0 likes
      Last Post andrewtrades  
      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
      6 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