Announcement

Collapse
No announcement yet.

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.

      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.



          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Yesterday, 05:17 AM
          0 responses
          66 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          141 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          76 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          47 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          51 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X