Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Two timeframe strategy

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

    Two timeframe strategy

    Hello,

    I have here a strategy with two timeframes. My question is: is this handsight trading?
    Here's the strategy:

    PHP Code:
            protected override void Initialize()
            {
            
                Add(PeriodType.Minute, 120);//this is index1
                Add(RSI(4,1));
                Add(SMA(200));            
                CalculateOnBarClose = true;
                    ExitOnClose        = false; 
                    EntriesPerDirection = 1; 
        EntryHandling = EntryHandling.UniqueEntries; 
            } 
    
    PHP Code:
            protected override void OnBarUpdate()
            {
                // Condition for longs
                if(BarsInProgress != 0)
                    return;
                //check for 120min chart
                if (Close[1] > SMA(BarsArray[1]20)[1]&&
                    //check loaded chart.
                    RSI(14, 1)[0] < 25)
                {
                    EnterLong(DefaultQuantity, "long1");
                } 
    

    This is my intention:
    Check if close above SMA on 120min chart.
    RSI below 25, then long

    So:
    - Is this handsight trading?
    - When I backtest this on a 5minute chart, does it check the 120 bar every 5minutes? or every two hours?

    thank you!

    #2
    Hello no111,

    This will work differently in a backtest versus real time. In a backtest, you don't have the opportunity to peak into the future with multiple series. You can't access the 120 minute bar until it's time stamp is <= the 5 minute bar. Please see here for more info on how bars are processed.

    A good way to verify is with this statement:
    Print ("Primary Series: " + Time[0] + " Secondary Series:" + Times[1][0]);

    This works differently in real time since the 120 minute bar is available to access before actual time reaches the time stamp.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_RyanM View Post
      Hello no111,

      This will work differently in a backtest versus real time. In a backtest, you don't have the opportunity to peak into the future with multiple series. You can't access the 120 minute bar until it's time stamp is <= the 5 minute bar. Please see here for more info on how bars are processed.

      A good way to verify is with this statement:
      Print ("Primary Series: " + Time[0] + " Secondary Series:" + Times[1][0]);

      This works differently in real time since the 120 minute bar is available to access before actual time reaches the time stamp.
      So when adding the Print statement to protected override void Initialize()
      then I will get the same results in backtest and realtime?

      Comment


        #4
        No, the print statements won't change the behavior. They're useful in comparing time stamps for each series, and belong in OnBarUpdate(). You can view output with tools > output window.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Ok what I want is this:
          Just check the last completed bar on 120minute chart, the close comparing with indicator e.g.
          So i get the same results in backtesting and realtime

          Comment


            #6
            Use CalculateOnBarClose = true and events are processed at the close of the bar. If you want to evaluate on the close of 120 minute bar, then structure your strategy so that this is the primary series and the 5 minute series is added.
            Ryan M.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Today, 05:17 AM
            0 responses
            23 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            120 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            63 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            41 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            45 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X