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 Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    598 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    343 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    103 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    556 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    555 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X