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

SetStopLoss and SetProfitTarget

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

    SetStopLoss and SetProfitTarget

    When using EnterLong / EnterShort the market orders are often different from the previous price. Will this code guarantee that the stop loss and profit targets will always be 5 ticks from the entry price. Or am I over thinking this? Or is there a better way?
    PHP Code:
    TargetTicks       5;
    StopTicks         5;
    BreakevenTicks 3;

    private 
    override void OnBarUpdate()
    {
       
    EnterLong(1"MyEntry");

       
    TargetPrice           Position.AveragePrice + (TargetTicks TickSize);
       
    CurrentStopPrice      Position.AveragePrice - (StopTicks TickSize);
       
    BreakevenTriggerPrice Position.AveragePrice + (BreakevenTicks TickSize);
       
    BreakevenPrice        Instrument.MasterInstrument.RoundDownToTickSize(Position.AveragePrice);


       
    SetStopLoss("MyEntry"CalculationMode.Pricefalse);
       
    SetProfitTarget("MyEntry"CalculationMode.Pricefalse);

       
    StopMovedToBreakEven false;

    If there is a better way could you please point me in the right direction.
    Thanks.

    #2
    Hello TAJTrades,

    Thank you for the post.

    For a market order, this would only guarantee the price at the time when you submit the order but would not confirm its fill price.

    If you want to submit target orders based on the market orders fill price, you should instead use OnExecutionUpdate to track the entry fill. Upon filling you could check its average price to position your targets at that point.

    We have a sample that demonstrates this concept here:


    This does not specifically use SetStopLoss/SetProfitTarget but it could easily be modified to use those instead of the limit orders it has. The main point of this sample is to show how to track the entry order and get its execution.Order.AverageFillPrice. This can be used to position the targets at a specified amount of ticks from the actual fill price.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thank you. I totally missed that sample code. It is exactly what I was looking for.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by RideMe, 04-07-2024, 04:54 PM
      5 responses
      28 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by f.saeidi, Today, 08:13 AM
      1 response
      4 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by DavidHP, Today, 07:56 AM
      1 response
      6 views
      0 likes
      Last Post NinjaTrader_Erick  
      Started by kujista, Today, 06:23 AM
      3 responses
      9 views
      0 likes
      Last Post kujista
      by kujista
       
      Started by Mindset, Yesterday, 02:04 AM
      2 responses
      18 views
      0 likes
      Last Post NinjaTrader_RyanS  
      Working...
      X