Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

MultiTimeFrame Indicator

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

    MultiTimeFrame Indicator

    Hi,

    How can I program my strategy to use data from an indicator based on a secondary higher time frame (i.e TSI(3,7) on a 7-RangeBars) as a filter to determine the entry setup for trades that will be taken on a 4 Range Bar?

    The pseudocode would be something like:

    "If the TSI(3,7) value[0] on the 7 RangeBar (secondary data series) is > 0 and <<other conditions>> on the 4 Range Bar (primary data series) are met, then an entry long setup is true."

    Thanks,

    RP

    #2
    RP, you would point to the appropriate BarsArray in the overload to calculate the indicator with this input series data then -

    Comment


      #3
      Thanks Bertrand.... Can I also plot the secondary indicator on the primary chart?

      Comment


        #4
        Yes, you can plot the indicator running on another series as well - however for NT 6.5 this is all limited to strategies, for NT7 this would be possible in indicators in NinjaScript as well.

        Comment


          #5
          Could you please tell me how can I plot the secondary indicator in NT7 from the strategy? Thanks

          Comment


            #6
            Sure, please take a look at the strategy Plot reference sample, it would for example plot the added series Highs on the chart, you could use any indicator here in exchange.

            When running a strategy on a chart you may find the need to plot values onto a chart. If these values are internal strategy calculations that are difficult to migrate to an indicator, you can use the following technique to achieve a plot. NinjaTrader 8 With NinjaTrader 8 we introduced strategy plots which provide the ability

            Comment


              #7
              What is wrong with the following code?

              I am running a 1min strategy.
              I simply want to enter long if the last primary 1min bar(High[0]) on current day crosses above the previous days high(Highs[1][0]).
              I want to set the Profit target on Entry as ATR(20) Daily bars (ATR(BarsArray[1],20)[0])

              I can plot the correct entry/exit/target levels via an Indicator but when I try to run this strategy it gives me garbage.

              Thanks for any assistance.


              public class EnterOnPrevDailyHigh : Strategy
              {

              protected override void Initialize()
              {
              Add(PeriodType.Day, 1);

              CalculateOnBarClose = true;
              }

              protected override void OnBarUpdate()
              {
              // Ensure at least 50 Days lookback
              if (CurrentBar < 72000) //50D*24Hrs*60min
              return;

              if (BarsInProgress != 0)
              return;

              double LongStopIn = Highs[1][0];
              double LongTarget = LongStopIn + (ATR(BarsArray[1],20)[0]);
              double LongStopLoss = LongStopIn - (ATR(BarsArray[1],20)[0]);

              if ((High[0] > LongStopIn) && (Position.MarketPosition == MarketPosition.Flat))
              {
              EnterLong(1000, "Enter Long");
              SetStopLoss(LongStopLoss);
              SetProfitTarget(LongTarget);
              }

              }

              Comment


                #8
                Great help as usual Bertrand... thanks!

                RP

                Comment


                  #9
                  abfc123,

                  I have responded to you in your other thread and we can handle it there.
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    Bertrand, is it possible that the StartegyPlot recognizes the plot panel automatically, to avoid overlapping? I know I can use a parameter to define the StrategyPlot panel, but I would prefer to have it automatic, as the indicators do... they always find the next available panel.

                    Comment


                      #11
                      This is unfortunately not possible RP, you would need to set them to the needed panel explicitly in your code.

                      Comment


                        #12
                        Thanks Bertrand....one more question, is it possible to use multiple instances of the StrategyPlot... for instance to plot an indicator, and to plot unrealized profits in a trade? If so, where should I manage the Add(StrategyPlot(n)) lines for each instance?

                        Comment


                          #13
                          Yes, you can use them multiple times, the indicators are just placeholders, you Add() them as usual in the Initialize() and then set values in the OnBarUpdate(), here's the sample expanded by plotting also a 20 bar EMA as third plot -

                          Code:
                          /* Add our blank placeholder indicators. The parameter we pass in is used to distinguish the two
                          			indicators from each other. */
                          			Add(StrategyPlot(0));
                          			Add(StrategyPlot(1));
                          			Add(StrategyPlot(2));
                          			
                          			// Set the color for the indicator plots
                          			StrategyPlot(0).Plots[0].Pen.Color = Color.Blue;
                          			StrategyPlot(1).Plots[0].Pen.Color = Color.YellowGreen;
                          			StrategyPlot(2).Plots[0].Pen.Color = Color.Red;
                          			
                          			// Set the panel which the plots will be placed on. 1 = price panel, 2 = panel under the price panel, etc.
                          			StrategyPlot(0).PanelUI = 1;
                          			StrategyPlot(1).PanelUI = 1;
                          			StrategyPlot(2).PanelUI = 1;
                          			
                          			// For more options please see the forum tip titled "Adding Indicators to Strategies"
                          			// [url]http://www.ninjatrader-support.com/vb/showthread.php?t=3228[/url]
                                  }
                          
                                  /// <summary>
                                  /// Called on each bar update event (incoming tick)
                                  /// </summary>
                                  protected override void OnBarUpdate()
                                  {
                          			/* Set the values of our indicators. One of them is set to the High of the primary bar series while the
                          			other is set to the High of the secondary bar series. This effectively creates a multi-time frame plot. */
                          			StrategyPlot(0).Value.Set(High[0]);
                          			StrategyPlot(1).Value.Set(Highs[1][0]);
                          			StrategyPlot(2).Value.Set(EMA(Close, 20)[0]);
                                  }

                          Comment


                            #14
                            Ok Great... thank you very much. RP

                            Comment


                              #15
                              Bertrand,


                              I was able to plot the indicator, but now there is an issue that I don't know how to solve. I have a User Defined Method called MyStratey Methods, where I have a method that plots unrealized profit/loss statistics, and it uses the StrategyPlot to do so. It uses StrategyPlot(0) to StrategyPlot(2) in orfder to plot Positive, Negative and 0 data. This method (PlotResults()) is called from the Initialize() section. I Add() the StrategyPlot(0,1,2) from within My Strategy Methods, because it is allways called from Initialize().

                              When I used the same StrategyPlot(0,1,2) for my indicator, it worked fine, but the PlotResults were lost. I figured I had to Add more StrategyPlots so I added StrategyPlot(3,4,5) in the Initilialize() section of the strategy, and call the PlotIndicator(TSI(BarsArray[1],tsiFastPeriod,tsiSlowPeriod), 4) from OnBarUpdate(). This way I can use the BarsArray pointer, and not get the error that Add() can only be used at Initialize() and BarsArraycannot be used at Initialize(). The problem with that approach is that I got three empty panels for the StrategyPlots 3 to 5.

                              I hope you got the point. If not, I can send you by mail, the actual codes.

                              Thank you.

                              Roberto

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              630 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              364 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              105 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              566 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              568 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X