Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

MTF question

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

    MTF question

    Code:
    // Primary bars 60 min //
    protected override void Initialize()
    {
    Add(PeriodType.Minute, 15);
    }
    
    protected override void OnBarUpdate()
    {
        if (BarsInProgress == 1)
        {
            Var.Set(<my_custom_dataseries>(using "close" as input and not index "closes");
        }
    
        if (BarsInProgress == 0)
        {
            if (Var[0] > 0)
            {
                EnterLong(DefaultQuantity, "")
            }
            if (Var[0] < 0)
            {
                EnterShort(DefaultQuantity, "")
            }
        }
            
        if (BarsInProgress == 1)
        {
            if (Var[0] < 0)
            {
                ExitLong("", "")
            }
            if (Var[0] > 0)
            {
                ExitShort("", "")
            }
        }
    }
    Please look at the code above. 60 min primary bars and 15 min secondary bars. I have the following question.
    1. In theory would value of "Var" be identical for both primary(60min) and secondary(15min) series since 60 is divisable by 15?

    My strategy will enter on the primary bars, 8:30am for example, and then the exit order will take place at 8:30am with the secondary bar. Running realtime a order is entered and then 15 minutes later it exits. Since both enter and exit occur at the same time (8:30am), how can I prevent the enter order to take in the first place?
    Last edited by eleven; 07-18-2010, 09:27 AM.

    #2
    Hello,

    I am sorry, I can't tell from your code and question.

    Can you explain your question in general terms?
    DenNinjaTrader Customer Service

    Comment


      #3
      Ben, Thanks for your quick reply. I will try to clarify in general terms.

      I have a MTF strategy. I enter on the primary (60 min) and exit on the secondary (15 min).

      Occasionally, I have an EnterLong (from the primary) and ExitLong (from the secondary) at the same exact time (60 is divisible by 15).

      In backtesting, this shows up as a trade that enters and exits at the same time/same price.

      In realtime, this results in a trade placed and exited at the next secondary bar close. (For example, EnterLong at 8:30 and and ExitLong at 8:45 am)

      How can I cancel or prevent the trade if I get a EnterLong and ExitLong at the same exact time?

      Thanks

      Comment


        #4
        eleven, you will have to create some sort of true/false flag, like 'enteredTradeThisBar' and set it to true when you enter and then in your exit code, you can check that flag and decide whether or not to exit the position.
        AustinNinjaTrader Customer Service

        Comment


          #5
          Thanks Austin.

          Can you please help me with the logic of the following code? Specifically can you explain why VarP and VarS print different results. I have a 60 min primary and a 15 min secondary (15 is divisible into 60). Really what I am after is a good explanation of VarS. VarS seems to produce a delayed result (ie. close from many bars ago).

          Thanks.

          Code:
                      if (BarsInProgress == 0)
                      {
                          VarP.Set(Close[0]);
                      }
                      if (BarsInProgress == 1)
                      {
                          VarS.Set(Close[0]);
                      }
                      
                      if (BarsInProgress == 0)
                      {
                      Print(Time[0] + "  prim   " + VarP[0].ToString());
                      Print(Time[0] + "  secd   " + VarS[0].ToString());
                      }
          Last edited by eleven; 07-19-2010, 07:42 AM.

          Comment


            #6
            In this case, VarS will be set every time the 15 minute bar series receives an OnBarUpdate() call to the close of said 15 minute bar because it is in the secondary bars check. VarP will update every time the 60 minute bar updates, and will be set to the close of the most recent 60 minute bar close.
            AustinNinjaTrader Customer Service

            Comment


              #7
              Thanks Austin. As far as the print statement, can you review my logic below and let me know if it is correct?

              1. With BarsInProgress == 0, both VarP and VarS will print every 60 minutes.
              2. Since VarS recieves an OnBarUpdate() every 15 min, VarS will print every 4th value.
              3. When VarP and VarS print they should have identical values.

              Comment


                #8
                Hello eleven,

                This reference sample is good for explaining the sequence of OnBarUpdate() calls in a multi time frame strategy.

                1) BIP == 0 only refers to updates to the primary series. VarS is equal to the primary series close but is only Set during updates to the secondary series.

                2) It prints both values during every update to the primary series - 60 minutes.

                3) Yes, the close of a 15 minute bar should equal the close the 60 minute bar when their time stamps are equal.
                Ryan M.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                666 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                376 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                110 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                575 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                580 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X