Announcement

Collapse
No announcement yet.

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 Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      561 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      325 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
      547 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      547 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X