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

Strategy Supertrend multi array

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

    Strategy Supertrend multi array

    good morning,
    I need to manage a Tf 5 min strategy conditional on Supertrend on Tf 1H (1 hour).
    Is there a Supertrend encoding from Array different from [0]?
    I tried to make a new indicator that uses the 1H bar as default but I find some discrepancies in the returned values.
    thank you so much for the answer

    #2
    Hello marubozu79,

    Thanks for your post.

    In your strategy that you apply to the 5 minute bars, you can add a 1 hour data series and then in the strategy assign the indicator to use the 1 hour bars.

    As you are creating a multi time frame strategy, you will want to ensure a good understanding of the concepts as explained in this link: https://ninjatrader.com/support/help...nstruments.htm In particular you would want to review "How Bar Data is Referenced" as this will help you to see what the higher time frame would be using.

    Here is an example of using the indicator assigned to the 1 hour bars:

    protected override void Initialize()
    {
    Add(PeriodType.Minute, 60);
    CalculateOnBarClose = true;
    }

    protected override void OnBarUpdate()
    {
    if (CurrentBars[0] < 20 || CurrentBars[1] < 1) return;

    if (BarsInProgress != 0) return;

    if (Closes[0][0] > TSSuperTrend(Closes[1], 14, MovingAverageType.EMA, 2.618, 7, SuperTrendMode.ATR).UpTrend[0])
    {
    // do something
    }
    }


    Paul H.NinjaTrader Customer Service

    Comment


      #3
      I read and reread the page at the link that it posted and I understood it perfectly.
      As for the indicator, I still can't set it on the array [1] in a working way.
      Is there a SuperTrend indicator that can work on arrays other than 0?
      thanks

      Comment


        #4
        Hello marubozu79,

        Thanks for your reply.

        In my example code I show how to use the Closes[1] which would be the close data series of the added 60 minute bars. The version of TsSuperTrend I used was what is available in the NT User apps section of the ecosystem: https://ninjatraderecosystem.com/use...ssupertrend-2/ Please note: The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          thanks again,
          the code of the strategy that you wrote above does not work however with the TSSupertrend indicator which is located at the link you shared.
          Can you prove that it actually works?
          thanks

          Comment


            #6
            Hello marubozu79,

            Thanks for your reply.

            When you write, "...the code of the strategy that you wrote above does not work..." I did not test the condition of if (Closes[0][0] > as that was being used as an example to show how you can use the other side of the example which was: TSSuperTrend(Closes[1], 14, MovingAverageType.EMA, 2.618, 7, SuperTrendMode.ATR).UpTrend[0]). So if you mean the condition does not work (does not become true) that could well be.

            If by does not work you mean there is a compile issue, please make sure you have added "using TSSuperTrend.Utility;" to the "using declarations" at the top of the code.
            example:

            using NinjaTrader.Gui.Chart;
            using NinjaTrader.Strategy;
            using TSSuperTrend.Utility;
            #endregion


            "Can you prove that it actually works?" Please see the attached screenshot. To "prove" that this works I have created a chart with a 10 minute data series and a 60 minute data series. I have applied two instances of the TsSupertrend indicator, one to each series to show what the UpTrend and downTrend values are when the indicator is applied to a series. (I changed the uptrend and downtrend lines to be a solid line rather than a dash for better visualization). In the print window is the output of a single print statement from the strategy where I added the 60 minute bars and applied it to the 10 minute series. The print statement provides the date/time of the 10 minute bars, the TsSupertrend UpTrend (green line) from the 1 hour bars and the TsSupertrend DownTrend (red line) from the 1 hours bars. As the hourly bars are in a downtrend (redline) only the DownTrend values would be of interest. Look at the output windows 8:10:00 AM print at the bottom. It is advising that the hourly downtrend line is 3117.936 (shows as 3117.94 on chart) and the 10 minute Downtrend value on the chart shows as 3092.56. Again these values were pulled from the strategy applied to the 10 minute bars.

            You can certainly replicate and test this yourself (just make sure you set the chart indicators to use the same values in the TsSupertrend indicator as used in the strategy). Here is the exact print statement I used:

            Print(Time[0]+"UpTrend Value: "+TSSuperTrend(Closes[1], 14, MovingAverageType.EMA, 2.618, 7, SuperTrendMode.ATR).UpTrend[0]
            + "DownTrend Value: "+TSSuperTrend(Closes[1], 14, MovingAverageType.EMA, 2.618, 7, SuperTrendMode.ATR).DownTrend[0]);


            Click image for larger version

Name:	marubozu79-1.PNG
Views:	472
Size:	159.9 KB
ID:	1079742
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              thanking you for your patience, I confirm that the double array doesn't work for me, so I am attaching the strategy that I am setting so that you can check if I'm doing something wrong.
              as you will see I recalled 4 different supertrends on the tf 60 min and on the tf 5 min but the result is that all 4 indicators are plotted on tf 5min.
              thank you for your patience
              Attached Files

              Comment


                #8
                Hello marubozu79,

                Thanks for your reply.

                What is the bar type and type frame of the chart you are applying the strategy to?

                Paul H.NinjaTrader Customer Service

                Comment


                  #9
                  hello Paul,
                  is on 5m TF ,
                  thanks

                  Comment


                    #10
                    Hello marubozu79,

                    Thanks for your reply.

                    I am near the end of my day here so I will reply tomorrow morning.
                    Paul H.NinjaTrader Customer Service

                    Comment


                      #11
                      Hello marubozu79,

                      Thanks for your patience.

                      Display: You would not be able to display an indicator from another time frame on the chart through your strategy script using Add(). You can ceratinly display the two TsSupertrends (10 period and 21 period) on the 5 minutes bars. The Hourly based ones would be overridden and would use again the chart bars so you would end up with two of the same. I recommend manually adding the indicators and adding the hourly bars (hidden) to the chart so that you can visualize all 4 that you wish to use. I've created a short specific video to walk through the steps: https://Paul-ninjaTrader.tinytake.co...NV8xMjA0Nzk2Mg (you do not need to change the plots, I only did that to help me visualize)

                      Indicator Values: The TsSupertrend indicator uses 2 plots, UpTrend and DownTrend. These plots will only contain legitimate values when the indicator assigns values to them. Visually, on any given bar you will have either an Uptrend plot or a downtrend plot (of the same indicator) When the plot is not assigned a value by the indicator, it will automatically be populated with the close value of the bar. I highly recommend that you print all values of every TsSupertrend plots and include the close value of the bar and this will confirm/prove this, especially if you use the display method above to show the actual plots on the chart. You may also want to review the Data series class information here regarding the check of .ContainsValue(): https://ninjatrader.com/support/help...ries_class.htm

                      MultiTimeFrame: This "&& (BarsSinceExit() == -1 || BarsSinceExit() > 10" will not work, please use the appropriate method signature for multi time frame in this page of the help guide: https://ninjatrader.com/support/help...ssinceexit.htm

                      Paul H.NinjaTrader Customer Service

                      Comment


                        #12
                        thanks again Paul,
                        your explanation of how to display both the supertrend 5m and the 1H on the same graph is clear and I can reproduce it completely.
                        It is not clear to me, or at least it does not work, the strategy posted yesterday, leaving out the ADD method, which however does not correctly recall the TSSupertrend 1H values on the 5m chart.
                        Is the problem clear?
                        thanks again

                        Comment


                          #13
                          Hello marubozu79,

                          Thanks for your reply.

                          I recommend that you add print statement to look at the values of both the 5m and 60 TsSupertrend values on a per bar basis. Make sure that the indicators on the chart have the same settings to avoid confusion (I did that to myself yesterday!). They will match when done correctly.


                          Paul H.NinjaTrader Customer Service

                          Comment


                            #14

                            hi,
                            with BarsSinceExit (0, "", 0) I solved,
                            thank you so much

                            Comment


                              #15
                              good evening
                              now the problem that remains is that by setting a pending order eg: EnterLongLimit (Highs [0] [1], "") I get that each tick is placed an order in "Working" state which then immediately goes into "Canceled" creating therefore thousands of orders in a few seconds and considerably slowing down the CPU.
                              Is there a way to avoid this limit order generation behavior at the same fixed value, in this case Highs [0] [1]?

                              thank you very much

                              Comment

                              Latest Posts

                              Collapse

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