Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Adding multiple data series in one strategy

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

    #16
    Hello stantenlee,

    The indicators are using the secondary series so you can use those with AddChartIndicator. You can otherwise continue to use them. You just need to remove the AddChartIndicator lines.

    Code:
    MACD1 = MACD([B]Closes[1],[/B] 20, 32, 8);
    MACD2 = MACD([B]Closes[2],[/B] 20, 32, 8);

    Comment


      #17
      So I just add manually the 1min series and MACD1min to the chart directly instead of using AddChartIndicator()???Does it what u mean?
      public class RINGOStrategy2 : Strategy
      {
      private MACD MACD1;

      private MACD MACD2;

      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Description = @"Enter the description for your new custom Strategy here.";
      Name = "RINGOStrategy2";
      Calculate = Calculate.OnBarClose;
      EntriesPerDirection = 1;
      EntryHandling = EntryHandling.AllEntries;
      IsExitOnSessionCloseStrategy = true;
      ExitOnSessionCloseSeconds = 30;
      IsFillLimitOnTouch = false;
      MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
      OrderFillResolution = OrderFillResolution.Standard;
      Slippage = 0;
      StartBehavior = StartBehavior.WaitUntilFlat;
      TimeInForce = TimeInForce.Gtc;
      TraceOrders = false;
      RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
      StopTargetHandling = StopTargetHandling.PerEntryExecution;
      BarsRequiredToTrade = 20;
      // Disable this property for performance gains in Strategy Analyzer optimizations
      // See the Help Guide for additional information
      IsInstantiatedOnEachOptimizationIteration = true;
      }
      else if (State == State.Configure)
      {
      AddDataSeries(Data.BarsPeriodType.Minute, 5);
      AddDataSeries(Data.BarsPeriodType.Minute, 1);




      }
      else if (State == State.DataLoaded)
      {
      MACD1 = MACD(Closes[1], 20, 32, 8);
      MACD1.Plots[0].Brush=Brushes.SeaGreen;
      MACD1.Panel=3;
      MACD2 = MACD(Closes[2], 20, 32, 8);
      MACD2.Plots[0].Brush=Brushes.Gold;
      MACD2.Panel=4;
      SetProfitTarget(@"RR", CalculationMode.Ticks, 15);
      SetStopLoss(@"RR", CalculationMode.Ticks, 15, false);

      }
      }

      protected override void OnBarUpdate()
      {
      if (BarsInProgress != 0)
      return;
      if (CurrentBar < BarsRequiredToTrade)
      return;

      // Set 1
      if ((MACD2.Diff[0] > 0)
      && (MACD1.Diff[0] < 0)
      && MACD1.Diff[3] > MACD1.Diff[2]
      && MACD1.Diff[2] > MACD1.Diff[1]
      && MACD1.Diff[4] > MACD1.Diff[3]
      && (Slope(MACD1.Diff, 1, 0) > 0))
      {
      EnterLong(Convert.ToInt32(DefaultQuantity), @"RR");
      }

      }
      }
      }

      Comment


        #18
        Hello stantenlee,

        When using AddDataSeries none of that will be visual on the chart, that includes the indicators. The chart only has to have a single series for the strategy, the point of using AddDataSeries it to have extra data available to the script which was not originally on the chart however the extra data is not something which is added visually to the chart.

        If you wanted to visualize different timeframes and indicators on those timeframes the best solution is to add both timeframes to the chart and manually apply those indicators so you can see them. The strategy is not dependent on the chart for secondary data so if it needs those extra data series or indicators from those series you do that all through code instead.

        Keep in mind that if you manually apply the indicators and then the strategy uses the indicators with different settings they may have different results and may be inaccurate.

        AddCharrtIndicator is normally the correct way to visualize indicators from a strategy, just not in a multi series strategy. The option you have to visualize data in the multi series strategy would be to use Plots and then plot the secondary data from the BarsInProgress 0 in the strategy. That would be at the primary bar frequency and you could plot whatever the last closed value of the secondary series was at that point, it will be less granular than applying the indicator to the actual bar series on a chart.



        Comment


          #19
          Originally posted by NinjaTrader_Jesse View Post
          Hello stantenlee,

          When using AddDataSeries none of that will be visual on the chart, that includes the indicators. The chart only has to have a single series for the strategy, the point of using AddDataSeries it to have extra data available to the script which was not originally on the chart however the extra data is not something which is added visually to the chart.

          If you wanted to visualize different timeframes and indicators on those timeframes the best solution is to add both timeframes to the chart and manually apply those indicators so you can see them. The strategy is not dependent on the chart for secondary data so if it needs those extra data series or indicators from those series you do that all through code instead.

          Keep in mind that if you manually apply the indicators and then the strategy uses the indicators with different settings they may have different results and may be inaccurate.

          AddCharrtIndicator is normally the correct way to visualize indicators from a strategy, just not in a multi series strategy. The option you have to visualize data in the multi series strategy would be to use Plots and then plot the secondary data from the BarsInProgress 0 in the strategy. That would be at the primary bar frequency and you could plot whatever the last closed value of the secondary series was at that point, it will be less granular than applying the indicator to the actual bar series on a chart.


          I got the error like file attached. it made the whole ninjatrader platform to close down for this error happening.
          Attached Files

          Comment


            #20
            Hello stantenlee,

            The error shown in the image means some object was null, from the image I cannot tell what may have caused that. If you were running a custom script and had seen this error you would need to refer back to the code to see what part is having problems. Commenting out the code you created is a good starting point at locating problematic code, when you see the script can stay enabled without error you can then start uncommenting logic and re testing to find the line causing the problem.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Today, 05:17 AM
            0 responses
            38 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            124 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            64 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            41 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