Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 geddyisodin, 04-25-2024, 05:20 AM
      8 responses
      61 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by jxs_xrj, 01-12-2020, 09:49 AM
      4 responses
      3,288 views
      1 like
      Last Post jgualdronc  
      Started by Option Whisperer, Today, 09:55 AM
      0 responses
      5 views
      0 likes
      Last Post Option Whisperer  
      Started by halgo_boulder, 04-20-2024, 08:44 AM
      2 responses
      22 views
      0 likes
      Last Post halgo_boulder  
      Started by mishhh, 05-25-2010, 08:54 AM
      19 responses
      6,189 views
      0 likes
      Last Post rene69851  
      Working...
      X