Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

while loop to modify position exits

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

    while loop to modify position exits

    I'm trying to code as part of my strategy a tentative trailing exit until my actual trailing exit indicator kicks in

    below is part of the code

    Code:
    int i = 2;
    while(Close[0] >= iterationlong && iterationlong < trailingstop)
    {
    	iterationlong = Open[0] + i * Math.Abs(Low[1] - Open[0]);
            i++;
    }
    After this part I then constructed if statements for the "iterationlong" variable.

    My biggest issue is that it seems like it may be in an endless loop or taking a long time to backtest since it needs to loop every single tick.

    If there's a better way to do this I'm all ears. Thanks!

    #2
    Open up the output window
    put a Print statement in your code after the {

    Print ( "Iterationlong=" + iterationlong + " i=" + i );

    Print out the other stuff too.

    You might want to limit your while loop to 1 iteration and then stop if it is that bad.

    Originally posted by Cataclyst View Post
    I'm trying to code as part of my strategy a tentative trailing exit until my actual trailing exit indicator kicks in

    below is part of the code

    Code:
    int i = 2;
    while(Close[0] >= iterationlong && iterationlong < trailingstop)
    {
        iterationlong = Open[0] + i * Math.Abs(Low[1] - Open[0]);
            i++;
    }
    After this part I then constructed if statements for the "iterationlong" variable.

    My biggest issue is that it seems like it may be in an endless loop or taking a long time to backtest since it needs to loop every single tick.

    If there's a better way to do this I'm all ears. Thanks!

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    36 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    23 views
    0 likes
    Last Post PaulMohn  
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    162 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    96 views
    1 like
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    152 views
    2 likes
    Last Post CaptainJack  
    Working...
    X