Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Backtest OnEachTick strategy

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

    #16
    Hi Chelsea, my bad! somehow it didnt copy it. I am sending you a new version with the times 12.25-12.35 below:
    https://wetransfer.com/downloads/27fa8cf556ffd4e6554768e9f762557420231211163619/5e1b53cebf0a152eb10f92f47a35ce0320231211163619/5f3a07

    Comment


      #17
      Hello,

      Thank you for the output.

      06/12/2023 12:30:00 | Close[0]: 16107,25 <= LLL1: 16107,25 && MyProjectedVOL[0]: 2892,85714285714 < SMA(Volume, 10)[0]: 4828,5 && BarsSinceExitExecution(1, ExitStopLong, 0): 12 != 0 && BarsSinceExitExecution(1, ExitLimitLong, 0) != 0

      The last value for BarsSinceExitExecution(1, ExitLimitLong, 0) was not included in the print.
      May I have you add this?

      I'm guessing that you are using commas as the decimal point and not a period? (Windows regional settings)

      Chelsea B.NinjaTrader Customer Service

      Comment


        #18
        Thanks Chelsea.

        That's what i dont understand. If you look at the output, the last exit execution happened at 12:20:04 in the 12:25 bar. So both BarsSinceExitExecution should be != 0 in the 12:30 bar correct?


        And therefore it should have taken a trade based on the conditions you shared above.

        Best,

        Comment


          #19
          Hello linkcou,

          Print "condition true" inside the action block for the condition set, one line above where the exit method is called.
          (In addition to adding the value for BarsSinceExitExecution(1, ExitLimitLong, 0).)

          What exit order method is being called in that action block?
          Chelsea B.NinjaTrader Customer Service

          Comment


            #20
            Hi Chelsea,

            The strategy generates 2 exit orders (one stoploss + one dynamic limit exit order that is updated in each bar).

            Like this?
            Click image for larger version

Name:	image.png
Views:	82
Size:	14.5 KB
ID:	1281725

            Comment


              #21
              Hello linkcou,

              What is the action block of the condition we were investigating from your post # 10?
              Is there no exit method called here?

              May I have you clarify why you provided a screenshot of that condition in post # 10?
              Chelsea B.NinjaTrader Customer Service

              Comment


                #22
                Hello Chelsea,

                The action block I shared in post #10 is the entry conditions. I shared this because the condition using the "BarsSinceExitExecution" is not working when i am doing the backtest.

                Maybe it would be easier if I share the code for both the entry and exit logic:

                Action block for the entry positions:
                Click image for larger version

Name:	image.png
Views:	73
Size:	51.3 KB
ID:	1281729
                Action block for the exit position (both the code in the OnBarUpdate + code in the OnOrderExecution):
                Click image for larger version

Name:	image.png
Views:	68
Size:	29.2 KB
ID:	1281730Click image for larger version

Name:	image.png
Views:	68
Size:	35.6 KB
ID:	1281731
                Let me know if you see any anomaly here?​

                Comment


                  #23
                  Hello linkcou,

                  In the action block of the condition set you are investigating, print condition true. This is in addition to printing all values used in the condition set one line above the condition.

                  We want to know why the condition is evaluating as true or false. Printing condition true would confirm the condition is evaluating as true and running the code in the action block.

                  It might be that the 'if' part of the condition evaluated as true, so the 'else if' was not evaluated.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #24
                    Hello Chelsea, i added 4 prints in each condition set action block and added with different names. Let me know if this is what you wanted to do:
                    Click image for larger version

Name:	image.png
Views:	64
Size:	43.2 KB
ID:	1281743
                    Results when i do this are also attached in the text file:
                    https://wetransfer.com/downloads/bd6a9be037df86b7c06c621ac886bc1020231211181619/2e228f8e1d60760616a36a168031d95a20231211181619/2e01e8

                    Comment


                      #25
                      Hello linkcou,

                      06/12/2023 12:30:00 | Close[0]: 16107,25 <= LLL1: 16107,25 && MyProjectedVOL[0]: 2880 < SMA(Volume, 10)[0]: 4828,2 && BarsSinceExitExecution(1, ExitStopLong, 0): 12 != 0 && BarsSinceExitExecution(1, ExitLimitLong, 0) != 0

                      There is no print of "Condition true in entry long limit" after this. So we know the code in that action block was not run.

                      The most likely means the 'if' above the 'else if' was true so the 'else if' was not evaluated.

                      Try adding a different print to the action block of the 'if' above to confirm if that has evaluated as true.
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #26
                        Hi Chelsea,

                        I actually did. If you look in the screenshot of post Strategy Development it's the "Condition true in entry short limit".

                        I think the problem is in the BarsSinceExitExecution(1, ExitLimitLong, 0) that at 06/12/2023 12:30:00 should be already 1 instead of 0 which is weird right?. Do you know why this is the case?

                        I added a print of this specific function and as you can see, the result is 0 both at 12:25 and 12:30 which is weird right?

                        See below the new output text:
                        https://wetransfer.com/downloads/c10695d48b9d49a45a48e3377915047720231211184154/6c51f9f72344d37f21a365365a50d25420231211184154/6d0958

                        Comment


                          #27
                          Hello linkcou,

                          The value for this is not in the print so I would not be able to confirm.

                          Add index {6} to the format print string to show the value for this if you would like me to confirm.

                          If you feel that BarsSinceExitExecution is not providing the correct value, print the order object in OnOrderUpdate() so that we can see the time when the last exit has filled.

                          This appears to be a 5 minute chart correct? So the previous bar is 12:25?
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #28
                            Hello Chelsea, indeed. 5 min chart

                            Added the index {6} and added the print on OnOrderUpdate. Results below:
                            https://wetransfer.com/downloads/b7cb3dabdf6e264b38e168e373dab5d520231211191532/25c969b488b45c14a3580acffc50bff020231211191532/e61b55

                            Comment


                              #29
                              Hello linkcou,

                              This may be an issue with using a secondary series.

                              "Note: When working with a multi-series strategy the BarsSinceEntryExecution() will return you the elapsed bars as determined by the first Bars object for the instrument specified by the barsInProgressIndex."


                              It may necessary to track the number of bars for the secondary series using an integer as a counter. Initialize the int with a value of -1. When the exit fills in OnOrderUpdate() or OnExecutionUpdate() set the int to 0. On each BarsInProgress 1 update and IsFirstTickOfBar is true, increment the counter.
                              Chelsea B.NinjaTrader Customer Service

                              Comment


                                #30
                                Hi Chelsea, thanks for this!

                                I think now it works. I run the backtest in that specific example and it seems to be working now

                                I want to have your eyes one last time on how I implemented this in the code in case you see any anomaly that needs to be fixed. Below the steps I followed:

                                1. I initialize the 4 variables at -1 at the beginning of the code.
                                Click image for larger version

Name:	image.png
Views:	67
Size:	3.5 KB
ID:	1281778

                                ​2. In OnOrderUpdate, I created the following condition to get the order name and see when the state is filled:
                                Click image for larger version

Name:	image.png
Views:	55
Size:	14.5 KB
ID:	1281779

                                3. In OnBarUpdate, added the incremental with the function IsFirstTickOfBar:
                                Click image for larger version

Name:	image.png
Views:	55
Size:	9.6 KB
ID:	1281780

                                4. In OnBarUpdate, remove the BarsSinceExitExecution functions and update with each of these variable when necessary for the entry conditions:​​
                                Click image for larger version

Name:	image.png
Views:	53
Size:	11.5 KB
ID:	1281781

                                Thoughts?
                                Thank you again for the great support on this

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by NullPointStrategies, Today, 05:17 AM
                                0 responses
                                50 views
                                0 likes
                                Last Post NullPointStrategies  
                                Started by argusthome, 03-08-2026, 10:06 AM
                                0 responses
                                126 views
                                0 likes
                                Last Post argusthome  
                                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                                0 responses
                                69 views
                                0 likes
                                Last Post NabilKhattabi  
                                Started by Deep42, 03-06-2026, 12:28 AM
                                0 responses
                                42 views
                                0 likes
                                Last Post Deep42
                                by Deep42
                                 
                                Started by TheRealMorford, 03-05-2026, 06:15 PM
                                0 responses
                                46 views
                                0 likes
                                Last Post TheRealMorford  
                                Working...
                                X