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

How To Prevent a StopLoss from Adjusting On Every OnBarUpdate

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

  • coopgrafik
    replied
    Chelsea,

    Thank you once again for your response but I'm on NT8 (lifetime) so this is why I'm getting the error. I'm not sure why you're making the assumption that I'm using the older software.

    So back to my issue. I simply want to to be able to move my stop without it being adjusted and reset after each OnBarUpdate.

    What I hear you telling me is that this will work in NT8. I just want to make sure we're onthe same page.

    /// OnOrderUpdate - open

    SetProfitTarget(@"scalp", CalculationMode.Ticks, 7);
    if (order.Name == "scalp" && order.OrderState == OrderState.Filled)
    {
    ExitLongStop(order.AvgFillPrice - 17 * TickSize, "scalp");
    }
    EnterLong(DefaultQuantity * 2, "scalp");

    /// OnOrderUpdate - close





    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello coopgrafik,

    ExitLongStop() is in the NinjaTrader 7 help guide.
    https://ninjatrader.com/support/help...itlongstop.htm

    ExitLongStopMarket() is a NinjaTrader 8 method and not for NinjaTrader 7.

    Further, you will need to use Position.AvgPrice.



    The entries have unique signal names and I would expect these both to be submitted if EntriesPerDirection is set to 2.


    The ExitLongStop() calls will be called after the entry is filled. This could be in OnOrderUpdate(), or OnExecution(), or in OnBarUpdate after the position is taken.

    Try submitting the exit orders in OnOrderUpdate().


    if (order.Name == "scalp" && order.OrderState == OrderState.Filled)
    {
    ExitLongStop(order.AvgFillPrice - 17 * TickSize, "scalp");
    }
    Last edited by NinjaTrader_ChelseaB; 08-04-2021, 07:32 AM.

    Leave a comment:


  • coopgrafik
    replied
    Hey Chelsea,

    When I added that line of code the complier threw out an error.

    "The name 'ExitLongStop' does not exist in the current context"

    Looking at the docs I see that ExitLongStop is not actually a method in the library. Did you mean ExitLongStopMarket?

    Also, I fiddled around with ExitLongStopMarket but it's not dropping a stop in the correct place. I'm calling Position.AveragePrice before the I'm even in the market as the next line of code is EnterLong.

    ExitLongStopMarket(0, true, 1, GetCurrentAsk() - 17 * TickSize, "exit", "scalp");

    Is this is a better version? I just want you to know that I'm trying this but it's still not working at all.

    In the code below I need to place a split order: two unique entries with two unique stops.

    Can you help me revise the 2 stops below to work so the algo brings me in but I still have the ability to manage the stops without then "snapping" back into place on every onBarUpdate?

    Thank you.

    Code:
     if ((Position.MarketPosition == MarketPosition.Flat)
    
    && (Conditions)
    
    {
    
    SetProfitTarget(@"scalp", CalculationMode.Ticks, 7);
    SetStopLoss(@"scalp", CalculationMode.Ticks, 17, false); // replace this
    // ExitLongStopMarket(0, true, 1, Position.AveragePrice - 17* TickSize, "exit", "scalp"); // this does not work
    EnterLong(DefaultQuantity * 2, @"scalp");
    
    SetProfitTarget(@"runner", CalculationMode.Ticks, 100);
    SetStopLoss(@"runner", CalculationMode.Ticks, 17, false); // this does not work
    // ExitLongStopMarket(0, true, 1, Position.AveragePrice - 17 * TickSize, "exit", "runner"); // this does not work
    EnterLong(DefaultQuantity, @"runner");
    
    
    }
    Last edited by coopgrafik; 08-03-2021, 10:05 PM.

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello coopgrafik,

    The overloads are listed in the help guide.
    ExitLongStop(double stopPrice)
    ExitLongStop(int quantity, double stopPrice)
    ExitLongStop(double stopPrice, string fromEntrySignal)
    ExitLongStop(double stopPrice, string signalName, string fromEntrySignal)
    ExitLongStop(int quantity, double stopPrice, string signalName, string fromEntrySignal)
    ExitLongStop(int barsInProgressIndex, bool liveUntilCancelled, int quantity, double stopPrice, string signalName, string fromEntrySignal)

    Use the overload with the liveUntilCancelled parameter. (This is demonstrated in the ProfitChaseStopTrailExitOrdersExample_NT7)

    For example:
    ExitLongStop(0, true, 1, Position.AveragePrice - MyStop * TickSize, "exit", "scalp");

    Leave a comment:


  • coopgrafik
    replied
    Thanks, Chelsea,

    However, I'm clicking around but the docs simply say:

    ExitLongStop(stopPrice);

    I just need a little more info than that. Of course, the docs state that this method accepts 4 arguments but there's just this one example. Also, does this method only calculate based on price versus ticks?

    In my code, MyStop equals 17 ticks. I'm not really sure how to convert to a price-based stop that sets up to 17 behind the price to a price-based formula. Something like??? (Position.AveragePrice - (MyStop * TickSize))

    Is there any way you can give me a leg up and covert the line below to the line of code I should use?

    SetStopLoss(@"scalp", CalculationMode.Ticks, MyStop, false);

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello coopgrafik,

    With set methods these are tied to OnBarUpdate.

    Instead, use exit orders with liveUntilCancelled as true. These will not update back to the original price when OnBarUpdate runs.


    Leave a comment:


  • How To Prevent a StopLoss from Adjusting On Every OnBarUpdate

    I'd like to mange my stop loss by hand. However, the strategy keeps snapping it back into it's original position on the close of every bar. Can you remind me the method used to prevent this from happening. Again, I love the way it's bring me into the trade but I want full control of my stop once I'm in the market. I believe there is some bool that can be set but I can't remember and the docs are always a bit of a mystery.

    Thank you!

    Code:
    if ((Position.MarketPosition == MarketPosition.Flat)
    && (Condition == true))
    
    {
    
    SetProfitTarget(@"scalp", CalculationMode.Ticks, 7);
    SetStopLoss(@"scalp", CalculationMode.Ticks, MyStop, false);
    EnterLong(DefaultQuantity * 2, @"scalp");
    
    SetProfitTarget(@"runner", CalculationMode.Ticks, 100);
    SetStopLoss(@"runner", CalculationMode.Ticks, MyStop, false);
    EnterLong(DefaultQuantity, @"runner");
    
    
    }

Latest Posts

Collapse

Topics Statistics Last Post
Started by Jon17, Today, 04:33 PM
0 responses
1 view
0 likes
Last Post Jon17
by Jon17
 
Started by Javierw.ok, Today, 04:12 PM
0 responses
6 views
0 likes
Last Post Javierw.ok  
Started by timmbbo, Today, 08:59 AM
2 responses
10 views
0 likes
Last Post bltdavid  
Started by alifarahani, Today, 09:40 AM
6 responses
41 views
0 likes
Last Post alifarahani  
Started by Waxavi, Today, 02:10 AM
1 response
20 views
0 likes
Last Post NinjaTrader_LuisH  
Working...
X