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 sjsj2732, 03-23-2026, 04:31 AM
      0 responses
      42 views
      0 likes
      Last Post sjsj2732  
      Started by NullPointStrategies, 03-13-2026, 05:17 AM
      0 responses
      294 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      290 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      135 views
      1 like
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      98 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Working...
      X