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 helpwanted, Today, 03:06 AM
      1 response
      12 views
      0 likes
      Last Post sarafuenonly123  
      Started by Brevo, Today, 01:45 AM
      0 responses
      9 views
      0 likes
      Last Post Brevo
      by Brevo
       
      Started by aussugardefender, Today, 01:07 AM
      0 responses
      5 views
      0 likes
      Last Post aussugardefender  
      Started by pvincent, 06-23-2022, 12:53 PM
      14 responses
      242 views
      0 likes
      Last Post Nyman
      by Nyman
       
      Started by TraderG23, 12-08-2023, 07:56 AM
      9 responses
      387 views
      1 like
      Last Post Gavini
      by Gavini
       
      Working...
      X