Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stop Loss Issue

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

    Stop Loss Issue

    Hello,

    I have a problem with my stop loss: it gets triggered on the same bar as the entry. I set my stoploss at 2ATR below the price but I can't figure what the matter. Do you have an idea where does the problem come from?

    Here is the piece of code that causes me this issue:

    HTML Code:
    if (Close[0] > MAX(High,20)[1])
    {
    EnterLong(DefaultQuantity, "Positive Breakout");
    Variable0 = ATR(20)[0];
    Variable1=Position.AvgPrice-5*Variable0;
    Print("Variables for Long Position");
    Print(Variable0);
    Print(Position.AvgPrice);
    Print(Variable1);
    SetStopLoss("Positive Breakout", CalculationMode.Price, Variable1, false);
    Thank you

    Manuel

    #2
    Originally posted by Manuel17 View Post
    Hello,

    I have a problem with my stop loss: it gets triggered on the same bar as the entry. I set my stoploss at 2ATR below the price but I can't figure what the matter. Do you have an idea where does the problem come from?

    Here is the piece of code that causes me this issue:

    HTML Code:
    if (Close[0] > MAX(High,20)[1])
    {
    EnterLong(DefaultQuantity, "Positive Breakout");
    Variable0 = ATR(20)[0];
    Variable1=Position.AvgPrice-5*Variable0;
    Print("Variables for Long Position");
    Print(Variable0);
    Print(Position.AvgPrice);
    Print(Variable1);
    SetStopLoss("Positive Breakout", CalculationMode.Price, Variable1, false);
    Thank you

    Manuel
    Until your order is filled, Position.AvgPrice is zero, so your SetStopLoss() statement is trying to set the StopLoss to a negative value. Correct your logic to set, or reset your StopLoss after the order is filled. Try using OnExecution().

    Comment


      #3
      Hello Koganam,

      Thank you for your reply. I have tried with OnExecution but it did not work. So instead of using Position.AvgPrice I decided to use the close price and it works. I think that it respects the philosophy of the strategy. Thank you for your help!

      Manuel

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      648 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      369 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      108 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      572 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      573 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X