Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

NBarsUp NBarsDown using the same return variable ?

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

    NBarsUp NBarsDown using the same return variable ?

    Hi
    When one has the N Bars Up and N Bars Down indicators and wishes to incorporate them into a strategy, an ambiguity arises because both indicators return the value 1 using the same return variable, value = 1.

    HTML Code:
    protected override void OnBarUpdate()
    {​
    // Evaluates if we have 3 consecutive higher closes
    double value=NBarsUp(3,true,true,true)[0];
    
    if(value==1)
    Print("We have three consecutive higher closes");​
    
    // Evaluates if we have 3 consecutive lower closes
    double value=NBarsDown(3,true,true,true)[0];
    
    if(value==1)
    Print("We have three consecutive lower closes");​
    
    }
    To resolve this issue, it is straightforward to correct it by modifying the names of the plots as follows:
    Code:
    AddPlot(new Stroke(Brushes.Crimson, 2), PlotStyle.Bar, NinjaTrader.Custom.Resource.NBarsDownTrigger);
    AddPlot(new Stroke(Brushes.DarkCyan, 2), PlotStyle.Bar, NinjaTrader.Custom.Resource.NinjaScriptIndicatorDi ff);


    By
    Code:
    AddPlot(new Stroke(Brushes.DarkCyan, 2), PlotStyle.Bar, "NBarsDownPlot");
    AddPlot(new Stroke(Brushes.Crimson, 2), PlotStyle.Bar, "NBarsUpPlot");​

    In the script, i can then use them as follows:
    Code:
    NBarsDownPlot[0] = 1;
    NBarsUpPlot[1];​
    What I wanted to understand is the meaning of NinjaTrader.Custom.Resource.NinjaScriptIndicatorDi ff and NinjaTrader.Custom.Resource.NBarsDownTrigger.
    I noticed in the data box and both panels that there are two values:
    Trigger=1 or 0,
    Diff =1 or 0,
    which are returned by these two indicators.
    Where can I find these values, and how can I access them for use without modifying the code?
    Thank you for the time you've dedicated to helping us.​​
    Click image for larger version

Name:	trigger.png
Views:	195
Size:	17.0 KB
ID:	1267249

    #2
    Hello aezkof,

    Thanks for your post.

    These are custom NinjaTrader resources that are not documented or open source.

    That said, NinjaTrader.Custom.Resource.NBarsDownTrigger is simply the plot name of the NBarsDown indicator which is 'Trigger'. This could be seen by adding the NBarsDown indicator to a chart and noting the name of the plot (Trigger) in the Indicators window.

    NinjaTrader.Custom.Resource.NinjaScriptIndicatorDi ff is simply the plot name of the NBarsUp indicator which is 'Diff'. This could be seen by adding the NBarsUp indicator to a chart and noting the name of the plot (Diff) in the Indicators window.

    You could access these values by accessing the plots of the NBarsDown and NBarsUp indicators as seen in the help guide documentation below.

    NBarsDown: https://ninjatrader.com/support/help..._bars_down.htm
    NBarsUp: https://ninjatrader.com/support/help..._up.htm​
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Thank you for your response.
      You've provided me with half of the answer.
      However, if I use both indicators simultaneously, there's an issue because both return values with the variable "value" equal to 1.
      HTML Code:
      protected override void OnBarUpdate()
      {
      
      doublevalue=NBarsDown(3,true,true,true)[0]; // Evaluates if we have 3 consecutive lower closes​
      doublevalue=NBarsUp(3,true,true,true)[0];​// Evaluates if we have 3 consecutive higher closes​
      
      if(value==1) // NBarsDown OR NBarsUp ?
      Print("We have three consecutive ");
      }​
      My question
      Is there another solution besides changing the plot name or adding a condition?




      Thanks in advance.



      Comment


        #4
        Hello aekzof,

        You need to use seperate variables for those two lines of code, you are just seeing the second value because you redefined the variable.

        Code:
        double downValue =NBarsDown(3,true,true,true)[0]; // Evaluates if we have 3 consecutive lower closes​
        double upValue =NBarsUp(3,true,true,true)[0];​// Evaluates if we have 3 consecutive higher closes​
        
        Print("Down is " + downValue  + " Up value is " + upValue);​

        Comment


          #5
          Thank you very much

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Yesterday, 05:17 AM
          0 responses
          65 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          139 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          75 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          45 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          50 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X