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

Using variables

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

    Using variables

    I am trying to check the days between two events.
    If I buy, I set a variable with ToDay(Time[0]).
    My problem appears when I try to use this variabe in the next context.
    Please find below an extract of my code:

    Code:
    [FONT=Courier New][SIZE=2][COLOR=black]// Condition set 1[/COLOR][/SIZE][/FONT]
    [COLOR=black][FONT=Courier New][SIZE=2]if[/SIZE][/FONT][FONT=Courier New][SIZE=2] (Low[[/SIZE][/FONT][FONT=Courier New][SIZE=2]0[/SIZE][/FONT][FONT=Courier New][SIZE=2]] < MIN(Low, [/SIZE][/FONT][FONT=Courier New][SIZE=2]20[/SIZE][/FONT][FONT=Courier New][SIZE=2])[[/SIZE][/FONT][FONT=Courier New][SIZE=2]1[/SIZE][/FONT][FONT=Courier New][SIZE=2]][/SIZE][/FONT][/COLOR]
     
    [SIZE=2][FONT=Courier New][COLOR=black]{[/COLOR][/FONT][/SIZE]
    [COLOR=royalblue][FONT=Courier New][SIZE=2]int[/SIZE][/FONT][FONT=Courier New][SIZE=2] Inday = ToDay(Time[[/SIZE][/FONT][FONT=Courier New][SIZE=2]0[/SIZE][/FONT][FONT=Courier New][SIZE=2]]);[/SIZE][/FONT][/COLOR]
    [COLOR=black][SIZE=2][FONT=Courier New]EnterLongStop([/FONT][/SIZE][FONT=Courier New][SIZE=2]);[/SIZE][/FONT][/COLOR]
    [SIZE=2][FONT=Courier New][COLOR=black]}[/COLOR][/FONT][/SIZE]
     
    [FONT=Courier New][SIZE=2][COLOR=black]// Condition set 2[/COLOR][/SIZE][/FONT]
     
    [FONT=Courier New][SIZE=2][COLOR=black]if (Position.GetProfitLoss(Open[0], PerformanceUnit.Percent) > 0[/COLOR][/SIZE][/FONT]
    [SIZE=2][FONT=Courier New][COLOR=black]&& [COLOR=royalblue]ToDay(Time [0])> Inday[/COLOR])[/COLOR][/FONT][/SIZE]
    [SIZE=2][FONT=Courier New][COLOR=black]{[/COLOR][/FONT][/SIZE]
    [SIZE=2][FONT=Courier New][COLOR=black]ExitLong("", "");[/COLOR][/FONT][/SIZE]
    [SIZE=2][FONT=Courier New][COLOR=black]} [/COLOR][/FONT][/SIZE]
    How can I use the variable "Inday", set in the first condition, also in the second condition?
    Thanks a lot!
    Last edited by eswap0; 06-07-2008, 01:28 PM.

    #2
    Initialize the variable outside of the if statement in the Variables section. Then you should be able to access it throughout your code.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by Josh View Post
      Initialize the variable outside of the if statement in the Variables section. Then you should be able to access it throughout your code.
      Thank you very much: it worked!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by gravdigaz6, Today, 11:40 PM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by MarianApalaghiei, Today, 10:49 PM
      3 responses
      10 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by XXtrader, Today, 11:30 PM
      0 responses
      4 views
      0 likes
      Last Post XXtrader  
      Started by love2code2trade, Yesterday, 01:45 PM
      4 responses
      28 views
      0 likes
      Last Post love2code2trade  
      Started by funk10101, Today, 09:43 PM
      0 responses
      9 views
      0 likes
      Last Post funk10101  
      Working...
      X