Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

if statement

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

    if statement

    I have a strategy which triggers a trade, but when I ask it to trigger the trade, I also ask it to toggle the value of a two variables, but it does not. My Code looks like this;

    if(My criteria)

    {
    EnterLongLimit(
    2,Bollinger(1,21).Lower[0],"Long Recover RTM108");
    SetProfitTarget(
    "Long Recover RTM108", CalculationMode.Price, MyEntryPrice);
    Long1 =
    1;
    Recover =
    1;
    }

    In the above, the entry is made and the target is set, but my variables do not change to "1". I have verified this with the print statement. The variables are of the int type and start out as 0 value. Is my syntax incorrect? Am I limited to the number of lines I can write between the { } ?

    Thanks,

    Safetrading

    #2
    Hello,

    From what I can see here the code looks fine. However my first guess would be that you are not defining the variables properly.

    You will want to ensure your variables are defined in the #Region Variables section above the OnBarUpdate() if you were to define them in the OnBarUpdate() they will be reset every new bar.

    If this doesn't resolve the issue please attach the complete .cs file (or simplified version). If it's not too complex I can take a quick look at it.

    Located in (MY)Documents\NinjaTrader 7\bin\Custom\Strategy
    LanceNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    105 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    53 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    35 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    38 views
    0 likes
    Last Post TheRealMorford  
    Started by Mindset, 02-28-2026, 06:16 AM
    0 responses
    74 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X