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

Non-sense error using multi-time frame code

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

    Non-sense error using multi-time frame code

    Hi Ninjas,

    Imagine that you code a multi-time frame script, where you have added two Bars Object besides the serie 0 in a Range Bar chart.

    protected override void Initialize()
    {
    Add("$EURUSD", PeriodType.Range, 13);
    Add("$EURUSD", PeriodType.Range, 14);
    CalculateOnBarClose = true;
    }

    protected override void OnBarUpdate()
    {
    if (BarsInProgress == 0 || BarsInProgress == 1 || BarsInProgress == 2)
    {
    // Analyze every Range Bar when an anynew bar comes and take a position according all analysis
    }
    }

    So far, so good. The issue pops up in this case: imagine that the Algo now ONLY take positions according to Bars 0 analysis, BUT I let this command the same:

    " if (BarsInProgress == 0 || BarsInProgress == 1 || BarsInProgress == 2) "

    Allegedly you'd get the same final result as if the command would be:

    " if (BarsInProgress == 0 ) "

    but the final results are totally different. So, if I have set the method OnBarUpdate with OnBarClose=True, how's possible to get two different results, if I'm working allegedly with Bars 0?

    I need to find why cause I have to do several combinations test, and I need a reliable behaviour.


    Thanks
    Last edited by pstrusi; 10-07-2013, 01:32 PM.

    #2
    I would not expect the results to be the same if you're checking BIP 0,1,2 as if you checked only BIP 0.

    There would be more events recorded with the first filter, and your strategy would calculate more frequently as each additional series closes.
    MatthewNinjaTrader Product Management

    Comment


      #3
      Thanks for your response Matthew.

      I understand what you say about too many records, but since the Algo is pretty simple taking positions according to Bar 0, it has not much sense that it could vary too much when the position would be the same for whatever record else coming. What worries me about this, it's that under combinations of two or more time-frames, could lose its reliability, unless you assure me that if I use just the BarsInProgress necessary the results will be reliable. Are reliable multi-time frame script?

      Thanks

      Comment


        #4
        What I'd suggest is adding some debug statements to understand how adding another bar array would check the calculation of the script

        Print("BarsInProgress: " + BarsInProgress);

        If your strategy is taking positions on bar 0, but we get an update on 1 or 2 shortly after, the additional events are going to be processed regardless where the update occurred.
        MatthewNinjaTrader Product Management

        Comment


          #5
          Matthew let me explain this simple test that I'd just made to prove what you said.

          I have a simple Algo that works just with a range bar, just one. I simply have added some several Bars Object, and set again the command calling for every record on any Bars Object:
          if (BarsInProgress == 0 || BarsInProgress == 1 || BarsInProgress == 2)

          Since the Algo JUST works and takes decisions with the Bar Object 0, the original, the results should be pretty similar as if I was using just BarsInProgress == 0, BUT the results are amazingly opposite, incredible.

          As you well said, I understand that there are more records than original only, but how can decisions on Bar 0 change if it's the same serie ?

          Excuse me if I insist with this but this makes me doubtful about coding multi-time frame scripts, and I need to do this. The other solution is having separate Algos through Ninja and the final positions would be the net into your account, but this is not practical if you had more than 10 Algos on this.

          How can I be sure that a well coded multi-time script would work as it should be?

          By the way: reviewing all trades done, I've realized that the algo takes position above its natural limit when it must just take positions just for one Bar, in this case Bar 0. I can't understand this. How can NT trade if there's no any order for the rest of the Bars Object ?

          Thanks
          Last edited by pstrusi; 10-07-2013, 01:32 PM.

          Comment


            #6
            My friend, I've just realized what's happening. A basic error. Any time that a Bar Object is called the arrays for close, High...etc etc changes according to the new event, I mean if the Bar Oject 5 was called, despite the Bar 0 not, the decision process will use the arrays for the bar object 5 and not 0.

            Thanks anyway, but doubt solved. Now I must code in a proper way.

            Comment


              #7
              Originally posted by pstrusi View Post
              My friend, I've just realized what's happening. A basic error. Any time that a Bar Object is called the arrays for close, High...etc etc changes according to the new event, I mean if the Bar Oject 5 was called, despite the Bar 0 not, the decision process will use the arrays for the bar object 5 and not 0.

              Thanks anyway, but doubt solved. Now I must code in a proper way.
              I'm glad to hear you were able to solve the error. Please let us know if you have any other questions on this topic.
              MatthewNinjaTrader Product Management

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by pechtri, 06-22-2023, 02:31 AM
              10 responses
              124 views
              0 likes
              Last Post Leeroy_Jenkins  
              Started by judysamnt7, 03-13-2023, 09:11 AM
              4 responses
              59 views
              0 likes
              Last Post DynamicTest  
              Started by ScottWalsh, Yesterday, 06:52 PM
              4 responses
              36 views
              0 likes
              Last Post ScottWalsh  
              Started by olisav57, Yesterday, 07:39 PM
              0 responses
              7 views
              0 likes
              Last Post olisav57  
              Started by trilliantrader, Yesterday, 03:01 PM
              2 responses
              22 views
              0 likes
              Last Post helpwanted  
              Working...
              X