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

BuyToCover stop order ignored

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

    BuyToCover stop order ignored

    Hi All,

    I am having a problem with setting a stop loss which seems to be due to a gap down in price on the bar after my entry signal triggers. What seems to be happening is that on the close of bar X my short signal triggers so I enter my short. I then calculate my stoploss by adding a number of ticks above my AvgFillPrice. The problem is that on the bar after my entry signal, price has gapped down, so that when my stoploss is entered it is below the Close of the trigger bar. I need to run CalculateOnBarClose = true;

    Below is my stoploss code
    protectedoverridevoid OnExecution(IExecution execution)
    {
    if (order1 != null && order1 == execution.Order && Position.MarketPosition == MarketPosition.Short)
    {
    order1Target = ExitShortLimit(
    0, true, 1, order1.AvgFillPrice - profitTarget * TickSize, "order1Target", "order1");
    order1StopLoss = ExitShortStop(
    0, true, 1, order1.AvgFillPrice + stopLoss * TickSize, "order1StopLoss", "order1");
    }
    elseif (order2 != null && order2 == execution.Order && Position.MarketPosition == MarketPosition.Short)
    {
    Print(Time[
    0] + " " + Close[0]);
    order2StopLoss = ExitShortStop(
    0, true, 1, order2.AvgFillPrice + stopLoss * TickSize, "order2StopLoss", "order2");
    }
    }
    I have attached a screenshot to show the price action, aswell as my output window with TraceOrders=true;

    How can I get around this issue?
    Attached Files

    #2
    Hello DarkPool,
    As a workaround you can initially place the stop order like
    Code:
    order1StopLoss = ExitShortStop(0, true, 1, [B]Math.Max(Close[0[/B]], order1.AvgFillPrice + stopLoss * TickSize), "order1StopLoss", "order1");
    and subsequently change it to your original price (from OnBarUpdate or OnMarketData)
    Code:
    order1StopLoss = ExitShortStop(0, true, 1, order1.AvgFillPrice + stopLoss * TickSize, "order1StopLoss", "order1");
    Please let me know if I can assist you any further.
    JoydeepNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by AnnBarnes, Today, 12:17 PM
    1 response
    2 views
    0 likes
    Last Post NinjaTrader_Zachary  
    Started by Lopat, 03-05-2023, 01:19 PM
    4 responses
    167 views
    0 likes
    Last Post Sam2515
    by Sam2515
     
    Started by f.saeidi, Today, 12:14 PM
    0 responses
    3 views
    0 likes
    Last Post f.saeidi  
    Started by giulyko00, Today, 12:03 PM
    0 responses
    4 views
    0 likes
    Last Post giulyko00  
    Started by AttiM, 02-14-2024, 05:20 PM
    12 responses
    213 views
    0 likes
    Last Post DrakeiJosh  
    Working...
    X