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 Hwop38, 05-04-2026, 07:02 PM
    0 responses
    164 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Started by CaptainJack, 04-24-2026, 11:07 PM
    0 responses
    317 views
    0 likes
    Last Post CaptainJack  
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    245 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    350 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    179 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Working...
    X