Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Target Limit with Iorder...

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

    Target Limit with Iorder...

    I know there is a lot of code but I felt I had to include that to explain my problem. I will produce the code in 2 posts because of characters limit..

    I have three different orders because I want to scale in and out of the position. I manage my stop loss and trailing stop with SetStopLoss and SetTrailStop methods.

    Now I want to manage my Target Stop with IOrder objects. There is no other way !


    So as soon as I get a fill on a long or short trade I place my Take profit stop on the OnExecution method down below. The problem is that they don't get triggered !

    Do you see any bad coding there ?


    On OnBarUpdate method :
    if (BuyOrders > 0){
    entryBOrder1 = EnterLongLimit(Cnts_firstTarget,
    BuyOrders,"aL");
    entryBOrder2 = EnterLongLimit(secondTarget_Cnts,
    BuyOrders,"bL");
    entryBOrder3 = EnterLongLimit(thirdTarget_Cnts,
    BuyOrders,"cL");

    }
    if(SellOrders < 999999){
    entrySOrder1 = EnterShortLimit(Cnts_firstTarget,
    SellOrders,"aS");
    entrySOrder2 = EnterShortLimit(secondTarget_Cnts,
    SellOrders,"bS");
    entrySOrder3 = EnterShortLimit(thirdTarget_Cnts,
    SellOrders,"cS");
    }




    #2
    Second Post

    Second post :

    On OnExecution method :

    protectedoverridevoid OnExecution(IExecution execution)
    {
    if (entryBOrder1 != null && entryBOrder1.Token == execution.Order.Token)
    {
    if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
    {
    targetBOrder1 = ExitLongLimit(0, true, execution.Order.Filled, execution.Order.AvgFillPrice + (firstTarget_Ticks * TickSize), "MyLTarget1","aL");

    if (execution.Order.OrderState != OrderState.PartFilled)
    {
    entryBOrder1 =
    null;
    }
    }
    }

    if ((targetBOrder1 != null && targetBOrder1.Token == execution.Order.Token))
    {
    if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled)
    {
    targetBOrder1 =
    null;
    }
    }






    }


    Thank you

    Bernard

    Comment


      #3
      You will have to debug your IOrder. Print from the top of OnExecution to see which IOrder is coming in.

      Print(execution.ToString());

      Then work from there to determine which if-statement is not working.

      Also use TraceOrders = true to help in the tracking.
      Josh P.NinjaTrader Customer Service

      Comment


        #4
        Never reappeared

        If I look at the Output window it seems that the Target orders were placed at the time of the Fill but never reappeared again !

        But on the bar that the trade should have been triggered it showed my SetStop oder !!




        Bernard

        Comment


          #5
          Not following you. You should not mix Set() methods with IOrders. If you are managing your trades via IOrders you should manage it completely. If it does not reappear it could mean you are resetting your IOrder to null too early. It could also mean that the trade was finished and there is nothing to "reappear" for.
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            Yes Josh I am mixing SetStop and IOrder because I've been trying deseparately for three days now to make three easy things work :

            Enter a trade
            1) Initial Stop 6 ticks
            2)Target on first set 3 ticks, Target on second set 6 ticks, Target on third set 16 ticks.
            3) After 3 ticks reajust stop loss to EntryPrice - 3 ticks, After 6 ticks breakeven. That's it.

            I tried only IOrder , I tried only SetStopLoss SetTargetStop etc..


            I don't know what to do now

            Bernard

            Comment


              #7
              If you want so many targets you need to scale in 3 times.

              Use ExitLongStop for stops and ExitLongLimit for targets.

              See this reference for adjusting stops to breakeven: http://www.ninjatrader-support2.com/...ead.php?t=7499
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                Succeeded

                Thank you very much Josh and Bertrand.

                I have finally succeded and the backtest on the 50 ticks chart has worked as expected.






                Bernard

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                647 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