• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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 StevenNelson, 11-19-2019, 05:39 AM
    3 responses
    13 views
    0 likes
    Last Post brucerobinson  
    Started by guidoisot, Today, 03:01 AM
    0 responses
    2 views
    0 likes
    Last Post guidoisot  
    Started by rontronimous, Yesterday, 05:55 PM
    0 responses
    9 views
    0 likes
    Last Post rontronimous  
    Started by bcgeek, Yesterday, 03:43 PM
    2 responses
    8 views
    0 likes
    Last Post bcgeek
    by bcgeek
     
    Started by Mberg, Yesterday, 04:05 PM
    1 response
    16 views
    0 likes
    Last Post NinjaTrader_ChrisSch  
    Working...
    X