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

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 kevinenergy, 02-17-2023, 12:42 PM
      117 responses
      2,766 views
      1 like
      Last Post jculp
      by jculp
       
      Started by Mongo, Today, 11:05 AM
      5 responses
      15 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Deleted: SightCare Australia Reviews by SightCareAubetter
      Started by SightCareAubetter, Today, 12:55 PM
      Topic deleted by NinjaTrader_LuisH
      Started by traderqz, Today, 12:06 AM
      8 responses
      16 views
      0 likes
      Last Post traderqz  
      Started by SightCareAubetter, Today, 12:50 PM
      0 responses
      2 views
      0 likes
      Last Post SightCareAubetter  
      Working...
      X