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

Keep DynamicSRLines Indicator running.

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

    Keep DynamicSRLines Indicator running.

    Hello all,

    I found this great DynamicSRLines indicator, it's using pivot points to draw SnR zones/lines. However, it doesn't work/loop continuously. It has MaxLookBackBars variable that also works as a stop. What I would like to achieve is that, use this MaxLookBackBars variable to draw SnR lines and then repeat the code, so that the indicator is going to draw a new SnR zone after getting the new MaxLookBackBars(50bars e.g).

    I would be very grateful if someone would help me or point me in the right direction.

    Code:
    protected override void OnBarUpdate()
    {
    
    if ( CurrentBar <= MaxLookBackBars )
    return;
    
    if ( LastBar != CurrentBar )
    {
    x = HighestBar(High, (PivotStrength*2)+1);
    Print("x on: " + x);
    if ( x == PivotStrength )
    {
    listEntry.Type = +1;
    listEntry.Price = High[x];
    listEntry.Bar = CurrentBar - x;
    pivot.Add(listEntry);
    
    if ( pivot.Count > MaxLookBackBars )
    {
    pivot.RemoveAt(0);
    }
    }
    x = LowestBar(Low, (PivotStrength*2)+1);
    if ( x == PivotStrength )
    {
    listEntry.Type = -1;
    listEntry.Price = Low[x];
    listEntry.Bar = CurrentBar - x;
    pivot.Add(listEntry);
    
    if ( pivot.Count > MaxLookBackBars )
    {
    pivot.RemoveAt(0);
    }
    }
    
    if ( CurrentBar >= Bars.Count-2 && CurrentBar > MaxLookBackBars )
    {
    p = Close[0]; p1 = 0; str = "";
    for ( level=1; level <= MaxLevels ; level++)
    {
    p = get_sr_level (p,+1);
    Draw.Rectangle(this, "resZone"+level, false, 0, p-((ZoneTickSize*TickSize)/2), MaxLookBackBars, p+((ZoneTickSize*TickSize)/2), ColorAbove, ColorAbove, 30 );
    Draw.Line (this, "resLine"+level, false, 0, p-((ZoneTickSize*TickSize)/2), MaxLookBackBars, p-((ZoneTickSize*TickSize)/2), ColorAbove, DashStyleHelper.Solid, 1);
    str = ( p == p1 ) ? str+" L"+level : "L"+level;
    Draw.Text (this, "resTag"+level, false , "\t "+str , -5 , p , 0, ColorAbove, boldFont, TextAlignment.Right, Brushes.Transparent , Brushes.Transparent , 0 );
    p1 = p; p += (PivotTickDiff*TickSize);
    }
    
    p = Close[0]; p1 = 0; str = "";
    for ( level = 1; level <= MaxLevels; level++)
    {
    p = get_sr_level (p, -1);
    Draw.Rectangle(this, "supZone"+level, false, 0, p-((ZoneTickSize*TickSize)/2), MaxLookBackBars, p+((ZoneTickSize*TickSize)/2), ColorBelow, ColorBelow, 30 );
    Draw.Line (this, "supLine"+level, false, 0, p-((ZoneTickSize*TickSize)/2), MaxLookBackBars, p-((ZoneTickSize*TickSize)/2), ColorBelow, DashStyleHelper.Solid, 1);
    str = ( p == p1 ) ? str+" L"+level : "L"+level;
    Draw.Text (this, "supTag"+level, false , "\t "+str , -5 , p , 0, ColorBelow, boldFont, TextAlignment.Right, Brushes.Transparent , Brushes.Transparent , 0 );
    p1 = p; p -= (PivotTickDiff*TickSize);
    }
    }
    }
    
    LastBar= CurrentBar;
    
    }
    
    double get_sr_level ( double refPrice, int pos)
    {
    int i=0, j=0;
    double levelPrice=0;
    
    if ( CurrentBar >= Bars.Count-2 && CurrentBar > MaxLookBackBars )
    {
    maxCountAbove=0; maxCountBelow=0; pxAbove=-1; pxBelow=-1;
    for ( i = pivot.Count-1; i >= 0; i--)
    {
    countAbove = 0; countBelow = 0;
    if ( pivot[i].Bar < CurrentBar-MaxLookBackBars ) break;
    for ( j=0; j < pivot.Count-1; j++)
    {
    if ( pivot[j].Bar > CurrentBar-MaxLookBackBars )
    {
    if ( pos > 0 && pivot[i].Price >= refPrice )
    {
    if( Math.Abs(pivot[i].Price-pivot[j].Price)/TickSize <= PivotTickDiff )
    {
    countAbove++;
    }
    if ( countAbove > maxCountAbove)
    {
    maxCountAbove = countAbove;
    levelPrice = pivot[i].Price;
    pxAbove = i;
    }
    }
    else
    if ( pos < 0 && pivot[i].Price <= refPrice )
    {
    if ( Math.Abs(pivot[i].Price-pivot[j].Price)/TickSize <= PivotTickDiff)
    {
    countBelow++;
    }
    if ( countBelow > maxCountBelow )
    {
    maxCountBelow = countBelow;
    levelPrice = pivot[i].Price;
    pxBelow = i;
    }
    }
    }
    }
    }
    
    if ( pos > 0 )
    {
    levelPrice = ( pxAbove >= 0 ) ? pivot[pxAbove].Price : High[HighestBar(High,MaxLookBackBars)];
    }
    if ( pos < 0 )
    {
    levelPrice = ( pxBelow >= 0 ) ? pivot[pxBelow].Price : Low[LowestBar(Low,MaxLookBackBars)];
    }
    
    }
    return Instrument.MasterInstrument.RoundToTickSize( levelPrice );
    
    }

    #2
    Hello ftraderXX,

    Thank you for your post.

    I'm not sure what you mean by "However, it doesn't work/loop continuously. It has MaxLookBackBars variable that also works as a stop."

    MaximumBarsLookBack would define how many bars ago you're able to retrieve the values for the indicator. This is generally set to MaximumBarsLookback.TwoHundredFiftySix; however, you can set this to MaximumBarsLookBack.Infiinite if you will need to retrieve indicator values further back.

    If this does not help, could you provide the entire .Zip file for the indicator in question so I may test and better understand what you mean?

    Thanks in advance; I look forward to assisting you further.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Hello Kate,

      Thanks for the prompt answer. Unfortunately, your answer didn't help me so far. Currently, the indicator works like this -> It reads 50 bars & then according to these 50 bars it draws SnR lines based on pivot points and then the indicator stops.

      I would like that the indicator reads in 50bars (MaxLookBackBars) and then draw SnR lines according to these first 50 bars. Then the indicator would read in another 50 bars and then draw new SnR lines according to the new 50 bars. And so on and on until I stop the indicator.

      Hopefully, it makes sense now. If not, then let me know I also attached the indicator .Zip file.

      regards
      Attached Files

      Comment


        #4
        Hello ftraderXX,

        Thank you for your reply.

        Looking at the indicator it's not designed to do that so that would require a pretty major overhaul of how it plots, considering as it is it basically plots backwards over the last 50 bars from the current bar, not starting at the current bar and moving forwards. We in the support department could not make those changes on your behalf, however, this is something you could either tackle yourself or enlist the assistance of a NinjaScript Consultant to help with.

        You'd have to decide how you'd want to plot this then - do you not want to plot for 50 bars and then on the 50th bar draw the new rectangle for just that period? Do you want to start plotting at the first bar of the 50 bars? These would be things to consider when overhauling how those plots occur.

        Please let us know if we may be of further assistance to you.
        Kate W.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        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
         
        Started by rocketman7, Today, 09:41 AM
        3 responses
        12 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X