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 Waxavi, Today, 02:10 AM
      0 responses
      3 views
      0 likes
      Last Post Waxavi
      by Waxavi
       
      Started by TradeForge, Today, 02:09 AM
      0 responses
      9 views
      0 likes
      Last Post TradeForge  
      Started by Waxavi, Today, 02:00 AM
      0 responses
      2 views
      0 likes
      Last Post Waxavi
      by Waxavi
       
      Started by elirion, Today, 01:36 AM
      0 responses
      4 views
      0 likes
      Last Post elirion
      by elirion
       
      Started by gentlebenthebear, Today, 01:30 AM
      0 responses
      4 views
      0 likes
      Last Post gentlebenthebear  
      Working...
      X