Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

if statement for plot

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

    if statement for plot

    Hi,

    I've an indicator with a Upper and Lower plot. Upper plots upper divergence and lower plots lower divergence. I want to create an if statement when upper or lower plots occur do something.

    What would the if statement be?

    if (UpperPlot occurs)
    EnterLong;

    if (LowerPlot occurs)
    EnterShort;

    Essentially, my point is that how to create an if statement when the upper or lower dot occurs? I'll be more than happy to share more of the code so you get a better understanding.

    Thanks

    #2
    Hello AgriTrdr,

    Thanks for your post.

    To clarify, are you referring to plots that are added to the script by calling the AddPlot() method?

    If so, you could create a condition that compares the plot to some value and then call your Enter method within that condition.

    For example, say you have a plot named "MyPlot":

    if (MyPlot[0] > Close[0])
    {
    //do something
    }


    See this help guide page for more information about AddPlot(): https://ninjatrader.com/support/help...ghtsub=addplot
    <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
      So I think we're saying the same thing, but to confirm here's a brief code:

      private double LowerDivergence;
      private double UpperDivergence;

      AddPlot(new Stroke(Brushes.Red, 2), PlotStyle.Block, "Upper");
      AddPlot(new Stroke(Brushes.SteelBlue, 2), PlotStyle.Block, "Lower");

      if ((Momentum1[0] > 0) && (up1 > uptimes2))
      {
      Lower[0] = LowerDivergence;
      }

      if ((Momentum1[0] < 0) && (dn1 > dntimes2))
      {
      Upper[0] = UpperDivergence;
      }

      region Properties
      [Browsable(false)]
      [XmlIgnore]
      public Series<double> Upper
      {
      get { return Values[0]; }
      }

      [Browsable(false)]
      [XmlIgnore]
      public Series<double> Lower
      {
      get { return Values[1]; }
      }
      #endregion

      From the code above, I would like to write the if statement if (LowerDivergence) occurs buy and if (UpperDivergence) occurs sell.

      Based on your example the if statement would be:

      if (Lower[0] > Close[0])
      // do something

      if (Upper[0] < Close[0])
      // do something​

      Thanks,
      Ujit


      Comment


        #4
        Hello Ujit,

        Thanks for the clarification.

        Yes, that would be the correct way to reference the Lower and Upper plots in your script.

        For example, the code you shared would specifically check if the current value of the Lower[0] plot is greater than the Close price. It would also check if the current value of the Upper[0] plot is less than the Close[0] price.
        <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


          #5
          Thank you!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Today, 05:17 AM
          0 responses
          53 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          130 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          70 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          44 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          49 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X