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

Plotting a 2nd time frame

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

    Plotting a 2nd time frame

    This simple task is getting the best of me.

    I am working on a strategy and I have added a second time frame using the same instrument as the primary data series.

    I just want to plot both charts, the primary and the second data series.

    This is my code by the second data series ALWAYS plots as 0.

    Code:
    public class TestPlotSeconDataSeries : Strategy
    
    {
    
    private Series<double> secondarySeries;
    
    
    
    
    
    
    protected override void OnStateChange()
    
    {
    
    if (State == State.SetDefaults)
    
    {
    
    Description = @"";
    
    Name = "TestPlotSeconDataSeries";
    
    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;
    
    
    
    
    
    AddPlot(new Stroke(Brushes.Red, 2), PlotStyle.Line, "Plot");
    
    
    
    
    
    
    
    }
    
    else if (State == State.Configure)
    
    {
    
    // Adding second date series
    
    //AddDataSeries(Data.BarsPeriodType.Tick, 1);
    
    AddDataSeries(Data.BarsPeriodType.Minute, 1);
    
    
    
    
    
    }
    
    
    
    else if (State == State.DataLoaded)
    
    {
    
    
    
    secondarySeries = new Series<double>(BarsArray[1]);
    
    }
    
    }
    
    
    
    
    protected override void OnBarUpdate()
    
    {
    
    if (CurrentBars[0] < 1 || CurrentBars[1] < 2)
    
            return;
    
    //Add your custom strategy logic here.
    
    if(BarsInProgress == 0)
    
    Value[0] = secondarySeries[0];
    
    }
    
    }

    #2
    I am assuming that one can plot both time frames on the same panel. The second timeframe your be plotted as a line instead of candlesticks.

    Comment


      #3
      Hello GARZONJ,

      In your logic you never set a value to the second series but that will also not help in plotting this value. Your plot is synced with the primary series and you are syncing the series with your secondary series, they will not have equal slots to use [0] BarsAgo on the primary. You could do the following to plot the secondary data, keep in mind there is not a way to add a secondary visual data set so you can only plot values at the frequency of your primary.

      Code:
       
       if(BarsInProgress == 0) {     Value[0] = Closes[1][0]; }
      The secondarySeries is not needed in this case, you already have the series of data represented as Closes[1].

      I look forward to being of further assistance.
      JesseNinjaTrader Customer Service

      Comment


        #4
        Jesse,

        I got it to work as you suggested. I am still curious about your statement, ."..keep in mind there is not a way to add a secondary visual data set so you can only plot values at the frequency of your primary".

        When adding a second data series using the Data Series configuration window, the chart is able to render both data series where one can see all the data points for the more detailed (lower timeframe) data series.

        There is no way to replicate this visual output through code?

        I am assuming that there might be a way, but my approach is defiantly not the way to go.

        Thanks

        Comment


          #5
          Hello GARZONJ.

          When adding a second data series using the Data Series configuration window, the chart is able to render both data series where one can see all the data points for the more detailed (lower timeframe) data series.
          There is no way to replicate this visual output through code?
          Correct, at this time there is no means to do this. Adding data through code only produces the data but does not configure charts or any other visuals. This is strictly for the purpose of accessing the data. While you can re-plot that data from your script you are limited to plotting at the frequency of the series which your script is applied to.

          I will add a feature request for a method similar to AddChartIndicator that could be used for the purpose of adding chart bars.


          I look forward to being of further assistance.



          JesseNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by alifarahani, Today, 09:40 AM
          6 responses
          31 views
          0 likes
          Last Post alifarahani  
          Started by Waxavi, Today, 02:10 AM
          1 response
          17 views
          0 likes
          Last Post NinjaTrader_LuisH  
          Started by Kaledus, Today, 01:29 PM
          5 responses
          14 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by Waxavi, Today, 02:00 AM
          1 response
          12 views
          0 likes
          Last Post NinjaTrader_LuisH  
          Started by gentlebenthebear, Today, 01:30 AM
          3 responses
          17 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X