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

Can i set time frame based on value from yesterday?

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

    Can i set time frame based on value from yesterday?

    Hi

    I wish to set some values - of a strategy - based on values from last day or hour.

    It makes good sense to do for values that i use in the script in the OnBarUpdate - but if i want to set/change the actual series - so lest say that all is calculated on 5 minutes bars instead of 1 minut bars - how can i do that? Or 500 ticks instead of 200?

    I imagine that before i "run" the OnBarUpdate() - i need to somehow calculate whatever value i need from yesterday or last hour bar - and then set AddDataSeries(Data.BarsPeriodType.Tick, 1) or minutes etc.

    So i also guess that my question is - how do i define - any vlaue from a "bar" from the day ago - or hour ago - before having defined the data timeseries?

    Hope anyone can help

    Thanks.




    #2
    Hello KarstenKafl,

    Thank you for your note.

    Data series cannot be added dynamically. You would need to include all data series that you would want to reference within State.Configure. You would then be able to configure your logic to look at your value and then calculate using the chosen data series depending on what that value from the previous bar is.

    Here's a link to our help guide with an example of a strategy that uses multiple data series to submit orders - it will enter on one series and exit on the other. You could use this example as a jumping off point for designing logic that would use your different data series.

    Also, here's a link to our help guide going over multi-time frame scripts:



    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      ok thanks.

      So just to be completely sure that i understand you - it is not possible to change time - (not going from tick to minutes) but just going from 10 to 11, 12 etc. minutes? is that correct?

      Comment


        #4
        Hello KarstenKafl,

        Thank you for your reply.

        It is not supported to dynamically change the interval of a data series. If you need different intervals, for example 10 minute, 12 minute, etc a separate data series would need to be added in State.Configure and then you would need to design your logic to use the appropriate data series given your conditions.

        Please let us know if we may be of further assistance to you.
        Kate W.NinjaTrader Customer Service

        Comment


          #5
          Hi again

          I have been working with the multi timeframe/instrument setup now - but i have one more issue that dont understand.
          I have tested and have a performance on the ES arround 3,5

          This was with 2000 tick.

          Now im just trying to use that ES ## strategy to enter a trade on MES ##.

          So i tried adding the folllowing

          AddDataSeries("MES 09-20", Data.BarsPeriodType.Tick, 10); (or a lot differenct tick and second numbers. )

          and then for entering i use:

          EnterLong(1, Convert.ToInt32(OrdersToTrades), "Long2");

          I then also use
          SetStopLoss("Long2", CalculationMode.Price, (Close[1] - LimitStopLong), false);

          I dont see any set stop loss numner to decde which bars in progress.

          and for exit -
          ExitLong(1, Convert.ToInt32(OrdersToTrades), "Long2", "Long2");


          So while still in the analyzer - i now get performance on 2,5 instead of 3,5.

          Is this "true/coirrect"?
          As far as i understand the micro MES - is exactly same "graph" as the ES? - so if es moves up one point - then MES will do exactly the same?

          Thanks in advance for replies.

          Comment


            #6
            i have few ideas - on why it is not the same performance - so i would also like to ask how i could solve it.

            1. is that on analyzer it is only using on bar close - right? - that means that on bar close - it calculates an buy order from ES - and then it have to wait for a new on bar close to submit that to the new on MES?

            2. i tried using the same logic as above - to enter long on the ES # - but from a second adddata - and the perfoamcnce was again 2,5
            Maybe this is caused by the above 1. issue.


            3. I also understand that using stop loss is a problem = it will never work the same - no matter what values i use - sinse it have different tick... so is there a way to use same idea as stop loss - but setup to be called from the ES to the MES?
            Last edited by KarstenKafl; 08-25-2020, 04:52 AM.

            Comment


              #7
              Hello KarstenKafl,

              Thank you for your replies.

              ES and MES are two different instruments and the graphs are not identical. Here's an illustration where the ES bars are red/green and the MES bars are pink/blue:

              Click image for larger version

Name:	ESvsMES.png
Views:	237
Size:	35.9 KB
ID:	1115483
              You'll notice at several points that you see red or green sticking out from behind the blue and pink, showing that there are differing movements happening. They're pretty close to the same, but not identical, so we would expect that since the two are not the same data, number of ticks, etc, that you would not get the same results running a strategy on the ES as the MES.

              That's just on a minute chart, where all the bars would have the same start and end times. The differences between tick based charts would be even more pronounced. Here's a 2000 tick chart of ES and MES together in one panel. You'll note most of the bars are sort of staggered and have differing time stamps:

              Click image for larger version

Name:	ESvsMES2000tick.png
Views:	218
Size:	87.2 KB
ID:	1115484


              You're correct that the Strategy Analyzer only processes OnBarClose. If you are submitting the order on the close of the ES bar, it would be submitted on the close of that bar to the secondary series.

              3. I also understand that using stop loss is a problem = it will never work the same - no matter what values i use - sinse it have different tick... so is there a way to use same idea as stop loss - but setup to be called from the ES to the MES?
              I'm not sure what you mean by this. Could you clarify further?

              Thanks in advance; I look forward to assisting you further.

              Kate W.NinjaTrader Customer Service

              Comment


                #8
                Thanks for clearing up a bit Kate.

                Im using 2000 tick – so it is “very” different”.

                The 3. Question. I mean that now im using the ES to enter long (which I wish is on MES)
                In Analyzer you say that it does not work on tick – so it is actually only doing stoploss based on bars? – so I can not really check if the behavious is better or worse on tick vs. bars right?

                Even though the graphs are different – and even though the analyzer shows different performance because of stoposs – I assume that the performance would be very close to eachoter for the stoploss – when using on tick –in real lift… is that correct assumption?

                But my question I guess is - Is there an alternative to using stoploss?

                Comment


                  #9
                  Also - is it true that you can not set the stoploss - to go on the specific added ekstra series
                  AddDataSeries("MES 09-20", Data.BarsPeriodType.Tick, 10);

                  Like we can with the EnterLong(1, Convert.ToInt32(OrdersToTrades), "Long2"); ?

                  Comment


                    #10
                    Hello KarstenKafl,

                    You can still enter on a secondary MES series. Just know that they aren't identical. I've attached an example strategy that has an added 10 tick MES 09-20 series and ran it on a 1000 tick ES chart. If you run it, then view the Strategy Performance, you'll see the trades are being taken on the secondary series despite the primary series being much larger. With SetStopLoss, you don't have to tell it which series to set the stop loss for, it will know automatically because you're setting that in the order the stop loss is tied to.

                    Please let us know if we may be of further assistance to you.
                    Attached Files
                    Kate W.NinjaTrader Customer Service

                    Comment


                      #11
                      Hi Kate

                      Thank you for the script.

                      Now i just tried the following things just testing in month of july.

                      Can you explain bit about why there are the differences below.
                      For all examples I removed the stoploss - so it ran until end of day - (just for simplicity) - to better understand if the "performance" was actually as expected.
                      I used ES - with 2000 tick in analyzer in all. But i changed the strategy along the way like this:

                      1. So I used ES - with 2000 tick in analyzer, and in the script i just let it enter MES - with the settings you had.
                      This gave perfoamnce of 1,31

                      2. I then changed the added series to enter ES - (same as the main series) - still with 10 tick.
                      This gave 1,35

                      3. then i changed added series to ES - to run on 2000 tick -
                      and this gave 1,39

                      4. Then i changed to just trade directly on the main ES - (not the secondayr added ES) - and this gave the same 1,39. which i understand why.


                      5. Then i tested adding the Setstoploss you created - with same Enterlong on the main ES - wihtout no secondary) - and this gave 1,10 - which makes sense.

                      6. But when i run this on the secondary ES - and I also run this with tick 2000 - same as the main. Then it shows 1,12 perfoamnce.


                      I would assume that all had same perfoamnce. But - especially the differnce from 2 - 3 i dont understand. Sinse it is same ES - and because there is no Stoploss - but only stopping at same time - at end of day?

                      Then also i dont understand the difference from 5 to 6... again same ES, same ticks etc.

                      Thanks a lot for explaining.

                      Best regards
                      Karsten

                      Comment


                        #12
                        Hello KarstenKafl,

                        Thank you for your reply.

                        What is the primary series you are using on all of these tests? Is it the same? It's a little unclear if you were running the last test with 2000 tick on both the primary series and secondary series here.

                        Thanks in advance; I look forward to assisting you further.

                        Kate W.NinjaTrader Customer Service

                        Comment


                          #13
                          For primary series - i used ES - with 2000 tick in analyzer in al the examples.1 - 6

                          Comment


                            #14
                            Hello KarstenKafl,

                            Thank you for your reply.

                            I've tested your scenarios 5 and 6, and both gave identical results for me of 1.06 when tested from August 1 to today's date.

                            Are there specific dates you are using that this occurs on? Exactly what edits did you make to the script, just changing the Order to use 0 instead of 1 for the BarsInProgress?

                            Thanks in advance; I look forward to assisting you further.
                            Kate W.NinjaTrader Customer Service

                            Comment


                              #15
                              Hi Kate

                              I tried again runnning it from 1 july to 1. august.

                              I test it on main series = ES, 2000 tick.

                              And the added series is same =
                              AddDataSeries("ES 09-20", Data.BarsPeriodType.Tick, 2000, Data.MarketDataType.Last);

                              If i just tell it to enter long on the "main" series like this:
                              EnterLong(Convert.ToInt32(DefaultQuantity), "Long2");

                              then the performance is 1,13 - and it have 521 trades.

                              But if i change it to enter the secondary series (which is same - 2000 tick, ES)
                              Like this:
                              EnterLong(1, Convert.ToInt32(DefaultQuantity), "Long2");
                              Then the performance is 1,14 - and it have only 481 trades.

                              So again - im not sure why there is a difference?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by TraderBCL, Today, 04:38 AM
                              3 responses
                              23 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by WeyldFalcon, 08-07-2020, 06:13 AM
                              11 responses
                              1,423 views
                              0 likes
                              Last Post jculp
                              by jculp
                               
                              Started by RubenCazorla, Today, 09:07 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post RubenCazorla  
                              Started by BarzTrading, Today, 07:25 AM
                              2 responses
                              29 views
                              1 like
                              Last Post BarzTrading  
                              Started by devatechnologies, 04-14-2024, 02:58 PM
                              3 responses
                              21 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Working...
                              X