Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to cancel the SetProfitTarget

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

    How to cancel the SetProfitTarget

    Hi

    On the "Backtest" menu, I set "Time in force" = Day (instead of GTC) and I set the Session from 12:00:00AM to 11:59:00PM.

    The following is my program that will execute the BuyStop order when the condition met. It would also cancell the order if the triggered buy stop order is not filled for the day. However, I find that the ProfitTarget & StopLoss order is not cancelled automatically when the buy stop order is cancelled due to the "Time in force" triggered.

    Shall I use OnOrderUpdate(IOrder order) to cancel it manually(I don't know how to do so) or there is a parameter to set. Pls advise!


    protected override void Initialize()
    {
    SetProfitTarget("Ent", CalculationMode.Ticks, 400);
    SetStopLoss("Ent", CalculationMode.Ticks, 400, false);
    CalculateOnBarClose = false;
    }

    protected override void OnBarUpdate()
    {
    if ("My specific condition here")
    {
    EnterLongStop(100000, High[0], "Ent");
    }
    }

    Regards,
    Toyogo

    #2
    Not sure I follow...

    The stop/target are only placed as you have a position open. So if you have an open position at session close, do you not want the stop/target to persist into the next session?
    RayNinjaTrader Customer Service

    Comment


      #3
      Hi,

      I want to end the stop/target at the end of the session. Anyway, after recompile the program, it has cancelled stop/target automatically if the buystop order cancelled.

      There is another question. How do I set the "Backtest" parameter such that there is only one buystop order (one trade) per session even if the same condition met multiple times. (or through programming)

      Regards,
      Toyogo

      Comment


        #4
        You would have to self program some flag that is set once the 1st order of a session has been submitted and then reset this when the property FirstBarOfSession is true.
        RayNinjaTrader Customer Service

        Comment


          #5
          Hi,
          Thanks. While trying to program a flag, I found that my buystop order was first accepted, then cancelled on the next bar (1min) without valid reason. (don't know what has triggered it). I've checked it is a valid order as prices of triggered bar is small then the stop price.

          I thought it may be due to SetProfit/Stop so I remarked it out. (see below). The print of OnOrderUpdate shows that the BuyStop order is accepted at 2.00pm but cancelled at 2.01pm. Pls help


          protected override void Initialize()
          {
          /// SetProfitTarget("Ent", CalculationMode.Ticks, 400);
          /// SetStopLoss("Ent", CalculationMode.Ticks, 400, false);

          CalculateOnBarClose = false;
          }

          protected override void OnBarUpdate()
          {
          if (certain condition)
          {
          /// will only reset to null at the FirstBarOfSession
          if (entryOrder == null)
          entryOrder = EnterLongStop(100000, Highvalue,"Ent");
          }
          }

          *****
          CurrBarTm :14/4/2008 2:00:00 PM
          PendingSubmit
          Ent
          1.97355
          0
          *****
          *****
          CurrBarTm :14/4/2008 2:00:00 PM
          Accepted
          Ent
          1.97355
          0
          *****
          *****
          CurrBarTm :14/4/2008 2:00:00 PM
          Working
          Ent
          1.97355
          0
          *****
          *****
          CurrBarTm :14/4/2008 2:01:00 PM
          PendingCancel
          Ent
          1.97355
          0
          *****
          *****
          CurrBarTm :14/4/2008 2:01:00 PM
          Cancelled
          Ent
          1.97355
          0
          *****


          Regards,
          Toyogo

          Comment


            #6
            Please make sure you understand how orders are managed in NinjaScript: http://www.ninjatrader-support.com/H...verview36.html

            Orders that automatically expire (cancel) at the end of a bar unless re-submitted

            Comment


              #7
              Hi Dierk and Ray,

              I would like to express my greatest thanks to both of you. Without very much programming knowledge (more than 10yrs ago), I managed to do the first customized strategy with your help.

              Moreover, your service and response is so fast and effective that no other vendors near it. I am sure Ninja Trader will become one of the top platform in the near future.

              I will definately support it and recommend to other traders....

              Regards,
              Toyogo

              Comment


                #8
                Thanks for the compliment!
                RayNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by RubenCazorla, 08-30-2022, 06:36 AM
                3 responses
                77 views
                0 likes
                Last Post PaulMohn  
                Started by f.saeidi, Yesterday, 12:14 PM
                9 responses
                23 views
                0 likes
                Last Post f.saeidi  
                Started by Tim-c, Today, 03:54 AM
                0 responses
                3 views
                0 likes
                Last Post Tim-c
                by Tim-c
                 
                Started by FrancisMorro, Today, 03:24 AM
                0 responses
                4 views
                0 likes
                Last Post FrancisMorro  
                Started by Segwin, 05-07-2018, 02:15 PM
                10 responses
                1,772 views
                0 likes
                Last Post Leafcutter  
                Working...
                X