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 DJ888, 04-16-2024, 06:09 PM
      4 responses
      12 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by terofs, Today, 04:18 PM
      0 responses
      11 views
      0 likes
      Last Post terofs
      by terofs
       
      Started by nandhumca, Today, 03:41 PM
      0 responses
      7 views
      0 likes
      Last Post nandhumca  
      Started by The_Sec, Today, 03:37 PM
      0 responses
      3 views
      0 likes
      Last Post The_Sec
      by The_Sec
       
      Started by GwFutures1988, Today, 02:48 PM
      1 response
      9 views
      0 likes
      Last Post NinjaTrader_Clayton  
      Working...
      X