Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

If statement as variable

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

    If statement as variable

    Hi there...

    I´m new to programming indicators in NT. Studied the tutorials but still have an open question.

    double longtrigger = Open[0]+(ATR(ATRPeriods)[1]*Trigger);
    double shorttrigger = Open[0]-(ATR(ATRPeriods)[1]*Trigger);

    This works fine and I can display the results on the chart. But how is it possible to define variables with if statements ?

    If(High[0] >= longtrigger[0] and Low[0] <= shorttrigger[0], -1, 0)

    Thank you...

    #2
    Shaihulud,

    Frist of all, you have defined longtrigger and shorttrigger as doubles as opposed to DataSeries, so you can't apply indexing to them. Second "and" should be &&. And third, I'm not sure what -1 and 0 are for. If they are the values assigned to a variable when the if statement is true, then you would have to assign them to a variable, similar to below.

    Code:
     
    if (High[0] >= longtrigger && Low[0] <= shortrigger) 
         MyVariable = -1;
    else
         MyVariable = 0;
    Hope this helps.

    VT
    Last edited by VTtrader; 12-05-2010, 01:09 PM.

    Comment


      #3
      Originally posted by shaihulud View Post
      Hi there...

      I´m new to programming indicators in NT. Studied the tutorials but still have an open question.

      double longtrigger = Open[0]+(ATR(ATRPeriods)[1]*Trigger);
      double shorttrigger = Open[0]-(ATR(ATRPeriods)[1]*Trigger);

      This works fine and I can display the results on the chart. But how is it possible to define variables with if statements ?

      If(High[0] >= longtrigger[0] and Low[0] <= shorttrigger[0], -1, 0)

      Thank you...
      shaihulud, you could do something like this:
      Code:
      double longtrigger = Open[0]+(ATR(ATRPeriods)[1]*Trigger);
      double shorttrigger = Open[0]-(ATR(ATRPeriods)[1]*Trigger);
      
      if (High[0] >= longtrigger && Low[0] <= shorttrigger)
          yourVariable = -1;
      else
          yourVariable = 0;
      AustinNinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      571 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      331 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      549 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      549 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X