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

SetProfitTarget, NT logic?

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

    SetProfitTarget, NT logic?

    Team NT, hello again

    I still have some questions concering the logic of SetProfitTarget:

    My strategy logic is:

    1.
    SetStopLoss( CalculationMode.Percent, initialRiskPercent/
    100.0);

    2. EnterLongLimit()

    .., now the trade is "alive" and every now and then the stop loss is adjusted by calls to SetStopLoss(CalculationMode.Price,price);

    I have no SetProfitTarget called because I don't want OCO orders sitting there with the OCO logic handled locally.
    By having simple stop loss orders all these orders sit on the exchange and are (almost!) guarenteed to execute.


    3. No I decide to exit the position and I do so by calling
    SetProfitTarget(zh.Buy,CalculationMode.Price,GetCurrentAsk()-TickSize);


    The result is that the positions exits as exspected once the Profit target order is filled, but at the same time I get an error concering the stop loss order. It seems that NT re-transmitts the stop loss order and by the time it is retransmitted the profit target was filled and the stop loss order turns invalid.

    Please indicate me what happens there? Why does the NT logic retransmit the stop loss?

    Why this error
    Can't modify a filled order" (104) Affected Order: Sell 1 Stop @ 4689,5

    Best regards

    Andreas

    Here is the log (cleaned up)
    It begins 10.17 with a change ot the stop loss order by my strategy.
    All later changes of the stop loss do not originate from my code, but from NT logic.

    Please explain how to avoid such errors!





    10.24 Execution Execution='FDAX 06-09/0000e7d2.4a0bc210.01.01' Instrument='FDAX 06-09' Exchange=Eurex Price=4724,5 Quantity=1 Market position=Short Operation=Insert Order='227258006' Time='14/05/2009 10.24.09'

    10.24 Order Order='227258006' Name='Profit target' New State=Filled Instrument='FDAX 06-09' Action=Sell Limit price=4724,5 Stop price=0 Quantity=1 Type=Limit Filled=1 Fill price=4724,5

    10.24 Order Affected Order: Sell 0 Stop @ 4689,5

    10.24 Order Order='227258005' Name='Stop loss' New State=Rejected Instrument='FDAX 06-09' Action=Sell Limit price=0 Stop price=4689,5 Quantity=0 Type=Stop Filled=0 Fill price=0 Error=NoError Native error=''

    10.24 Order Order='227258006' Name='Profit target' New State=PendingCancel Instrument='FDAX 06-09' Action=Sell Limit price=4724,5 Stop price=0 Quantity=1

    10.24 Strategy Strategy 'AndreasLongEntry' submitted an order that generated the following error 'OrderRejected'. Strategy has sent cancel requests, attempted to close the position and terminated itself.

    10.24 Order Can't modify a filled order" (104) Affected Order: Sell 1 Stop @ 4689,5

    10.24 Order Order='227258005' Name='Stop loss' New State=Rejected Instrument='FDAX 06-09' Action=Sell Limit price=0 Stop price=4689,5 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=OrderRejected Native error='Can't modify a filled order" (104)'

    10.24 Order Order='227258005' Name='Stop loss' New State=Accepted Instrument='FDAX 06-09' Action=Sell Limit price=0 Stop price=4689,5 Quantity=1 Type=Stop Filled=0

    10.24 Order Order='227258005' Name='Stop loss' New State=PendingChange Instrument='FDAX 06-09' Action=Sell Limit price=0 Stop price=4689,5 Quantity=1 Type=Stop Filled=0

    10.24 Order Order='227258005' Name='Stop loss' New State=Working Instrument='FDAX 06-09' Action=Sell Limit price=0 Stop price=4689,5 Quantity=0 Type=Stop Filled=0

    10.24 Order Order='227258006' Name='Profit target' New State=Working Instrument='FDAX 06-09' Action=Sell Limit price=4724,5

    10.24 Order Order='227258006' Name='Profit target' New State=Accepted Instrument='FDAX 06-09' Action=Sell Limit price=4724,5

    10.24 Order Order='9023d6dd28bc4b1187a8194d83df3be5' Name='Profit target' New State=PendingSubmit Instrument='FDAX 06-09' Action=Sell Limit price=4724,5

    10.17 Order Order='227258005' Name='Stop loss' New State=Working Instrument='FDAX 06-09' Action=Sell Limit price=0 Stop price=4689,5




    #2
    Andreas,

    You are dealing with inflight executions and this can happen if you try to modify orders. What happens is you try to change an order, but by the time you "succeed" the order was already filled or the position was already closed. Only way to prevent is to just not submit amends. If you clearly knew you were sending in a profit target that was going to get filled, don't send in stop amends.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Ok,

      but I checked my code already and I am quite sure no order amend comes from my code.

      It seems that the NT internal logic sends the following amend:

      first order is profit target

      second is stop loss amend with unchanged stop price but Quantity = 0
      how come a Quantity of 0 ?

      third is a stop loss amend with unchanged stop price but Quantity = 1

      Are these orders initiated by the internal NT order logic?


      Best regards
      Andreas



      10.24 Order Order='227258005' Name='Stop loss' New State=PendingChange Instrument='FDAX 06-09' Action=Sell Limit price=0 Stop price=4689,5 Quantity=1 Type=Stop Filled=0

      10.24 Order Order='227258005' Name='Stop loss' New State=Working Instrument='FDAX 06-09' Action=Sell Limit price=0 Stop price=4689,5 Quantity=0 Type=Stop Filled=0

      10.24 Order Order='227258006' Name='Profit target' New State=Working Instrument='FDAX 06-09' Action=Sell Limit price=4724,5

      Comment


        #4
        You need to use TraceOrders = true to see when and where your amends are coming from. NinjaTrader does not take action unless instructed to.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          thank you,

          where do I set TraceOrder=true;?

          In the Initialize() ?

          Comment


            #6
            Yes, correct - http://www.ninjatrader-support.com/H...aceOrders.html

            BertrandNinjaTrader Customer Service

            Comment


              #7
              I will getback tomorrow, this afternoon today the market is crap and after an excellent morning there is no need to gamble around and I am tired also.

              Testing in this case can only be done with real orders!

              Comment


                #8
                All working fine

                the NT Order logic works perfectly.

                It was a problem in my code and I did not consider that entryOrder=EnterLongLimit() returns null if the maximum EntriesPerDirection value is reached.

                One must also consider that by nature of the broker api's execution of the orders is indipendent of the OnBarUpdate(), hence careful monitoring of OnExecution and OnOrderUpdate is required

                Unbelievable how many intrications came up in a supposedly simple code.

                Regards

                Andreas

                Comment


                  #9
                  Andreas, thanks for reporting back - great this is resolved for you!
                  BertrandNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by agclub, 04-21-2024, 08:57 PM
                  5 responses
                  32 views
                  0 likes
                  Last Post agclub
                  by agclub
                   
                  Started by ESHunter, Today, 08:06 PM
                  2 responses
                  14 views
                  0 likes
                  Last Post ESHunter  
                  Started by ETFVoyageur, 05-07-2024, 07:05 PM
                  19 responses
                  150 views
                  0 likes
                  Last Post ETFVoyageur  
                  Started by ETFVoyageur, Yesterday, 10:13 PM
                  3 responses
                  26 views
                  0 likes
                  Last Post ETFVoyageur  
                  Started by ETFVoyageur, Yesterday, 12:52 AM
                  3 responses
                  33 views
                  0 likes
                  Last Post ETFVoyageur  
                  Working...
                  X