Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Setting Stop at Each Percentage of Open Profit

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

    Setting Stop at Each Percentage of Open Profit

    Hi I am trying to just set a simple profit stop after I have 2% of open profit in a position. The following code works fine for when I have 1% open profit but if I change it to anything over 1% it doesn't work.


    if ((InLong == true)
    && (High[0] > (Position.AveragePrice * 1.01) ))
    {
    ExitLongStopMarket(Convert.ToInt32(DefaultQuantity ), (Position.AveragePrice * 1.0075) , @"1%ProfitProtect", "");
    }



    This doesn't work:


    if ((InLong == true)
    && (High[0] > (Position.AveragePrice * 1.02) ))
    {
    ExitLongStopMarket(Convert.ToInt32(DefaultQuantity ), (Position.AveragePrice * 1.0075) , @"2%ProfitProtect", "");
    }


    Thanks

    #2
    Hello prescottbph,

    Thank you for the post.

    I wanted to check, are you currently using Prints or any other type of way to see the value you are calculating?

    Nothing looks out of place in what you provided, however, the value you are calculating may be the problem. Have you tried using a Print like the following before the condition to see what values it is reporting?

    Code:
    Print("InLong: " + InLong + " High[0]: " + High[0] + " Position.AveragePrice * 1.02: " + (Position.AveragePrice * 1.02));
    
    if ((InLong == true) && (High[0] > (Position.AveragePrice * 1.01) ))
    This would likely be the easiest way to see what is happening here.



    I look forward to being of further assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    43 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    21 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    30 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    50 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    41 views
    0 likes
    Last Post CarlTrading  
    Working...
    X