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

Draw.Region not working when I use additional DataSeries

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

    Draw.Region not working when I use additional DataSeries

    My indicator has two plots and a region being drawn. I also have a switch (bool) to indicate whether or not these values should be plotted according to a different time frame (data series). The idea is to plot a MA channel on the chart, optionally using values from a higher time frame.

    When I use the chart data series, the plots are correct and the region is drawn.

    When I use the secondary data series, the plots are correct, but the region is not drawn.

    Is there something wrong with the code below that prevents the region from being drawn?




    Code:

    Code:
    if (State == State.SetDefaults)
    {[INDENT]
    UseHigherTF = false;
    TF1 = 5;
    TF1Type = Data.BarsPeriodType.Minute;
    
    Period = 5;
    
    ChannelBrush = Brushes.Black;
    ChannelOpacity = 50;
    
    AddPlot(Brushes.Orange, "UpperLine");
    AddPlot(Brushes.Orange, "LowerLine");
    
    Plots[0].Width = 2;
    Plots[0].Brush = Brushes.Black;
    
    Plots[1].Width = 2;
    Plots[1].Brush = Brushes.Black;[/INDENT]
     
    
    
    }
    else if (State == State.Configure)
    {[INDENT]
    if(UseHigherTF == true) {[/INDENT][INDENT=2]AddDataSeries(TF1Type, TF1);[/INDENT][INDENT]}
    
    SetZOrder(-1);[/INDENT]
     
    
    
    }
    else if (State == State.DataLoaded)
    {[INDENT]
    if(UseHigherTF == true) {[/INDENT][INDENT=2]
    SMMA1 = smittySMMA(Highs[1], Period);
    SMMA2 = smittySMMA(Lows[1], Period);[/INDENT][INDENT]
    } else {[/INDENT][INDENT=2]
    SMMA1 = smittySMMA(Highs[0], Period);
    SMMA2 = smittySMMA(Lows[0], Period);[/INDENT][INDENT]
    }[/INDENT]
     
    
      }
    
    
    protected override void OnBarUpdate()
    {[INDENT]
    if(CurrentBars[0] < Period) { return; }
    
    if(UseHigherTF == true) {[/INDENT][INDENT=2]if(CurrentBars[1] < Period) { return; }[/INDENT][INDENT]}
    
    
    Values[0][0] = SMMA1[0];
    Values[1][0] = SMMA2[0];
    
    Draw.Region(this, "MA Channel", CurrentBar, 0, SMMA1, SMMA2, null, ChannelBrush, ChannelOpacity);[/INDENT]
     
    
    
    }
    Last edited by torch2k; 07-28-2021, 06:30 AM. Reason: clarity

    #2
    Hello torch2k,

    Drawing objects are attached to the primary series only. A secondary series would not have the same chart slots and would not allow this to draw.

    You could create a custom series, and then set the value of this to the higher time frame plot.

    Below is a link to an example with a similar idea.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      You could create a custom series, and then set the value of this to the higher time frame plot.
      Makes sense - thank you!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by giulyko00, Today, 12:03 PM
      0 responses
      2 views
      0 likes
      Last Post giulyko00  
      Started by AttiM, 02-14-2024, 05:20 PM
      12 responses
      213 views
      0 likes
      Last Post DrakeiJosh  
      Started by cre8able, 02-11-2023, 05:43 PM
      3 responses
      238 views
      0 likes
      Last Post rhubear
      by rhubear
       
      Started by frslvr, 04-11-2024, 07:26 AM
      8 responses
      117 views
      1 like
      Last Post NinjaTrader_BrandonH  
      Started by stafe, 04-15-2024, 08:34 PM
      10 responses
      47 views
      0 likes
      Last Post stafe
      by stafe
       
      Working...
      X