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

unmanaged order

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

    unmanaged order

    Hello

    I changed all the order submission in my strategy to unmanaged order and I have the following problem:

    When I have an order and it is partially filled, example the one below where the order is for 5 contracts, first I buy 1 and then I buy 4, 2 Take Profit Orders and 2 Stop Loss Orders are generated, 1 for each filled order.

    Now when my system goes into Trail Stop mode, I need to cancel the Oco Created orders, but it only cancels the last one that has been filled.

    I need cancel all OCO orders in this case the 2 OCO Orders that were Created.


    Entry Order


    Datos de la Orden de Entrada LE orderId='06b7a0f03c3e4e0aa5b0b7eeefa7d38f' account='Playback101' name='LE' orderState=Accepted instrument='NQ 09-20' orderAction=Buy orderType='Stop Market' limitPrice=0 stopPrice=10381 quantity=5 tif=Gtc oco='unmanagedentryoco1033086642' filled=0 averageFillPrice=0 onBehalfOf='' id=37261 time='2020-07-02 09:15:01' gtd='2099-12-01' statementDate='2020-07-02'

    1 Filled
    Datos de La Orden Take Profit LE orderId='86bc94413acc450b95e26167f20f11e1' account='Playback101' name='longProfitTarget' orderState=Working instrument='NQ 09-20' orderAction=Sell orderType='Limit' limitPrice=10395 stopPrice=0 quantity=1 tif=Gtc oco='unmanageexitdoco1033108424' filled=0 averageFillPrice=0 onBehalfOf='' id=37262 time='2020-07-02 09:31:55' gtd='2099-12-01' statementDate='2020-07-02'
    Datos de La Orden Stop Loss LE orderId='78395b783d85449ebb4c76f4df29fa6e' account='Playback101' name='longStopLoss' orderState=Accepted instrument='NQ 09-20' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=10367 quantity=1 tif=Gtc oco='unmanageexitdoco1033108424' filled=0 averageFillPrice=0 onBehalfOf='' id=37263 time='2020-07-02 09:31:55' gtd='2099-12-01' statementDate='2020-07-02'

    2 Filled
    Datos de La Orden Take Profit LE orderId='d35c45ee282441cbafeae857e2d29d1c' account='Playback101' name='longProfitTarget' orderState=Working instrument='NQ 09-20' orderAction=Sell orderType='Limit' limitPrice=10395 stopPrice=0 quantity=4 tif=Gtc oco='unmanageexitdoco1033109023' filled=0 averageFillPrice=0 onBehalfOf='' id=37264 time='2020-07-02 09:31:55' gtd='2099-12-01' statementDate='2020-07-02'
    Datos de La Orden Stop Loss LE orderId='8f9f2a589b4141dd84208e89efba3055' account='Playback101' name='longStopLoss' orderState=Accepted instrument='NQ 09-20' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=10367 quantity=4 tif=Gtc oco='unmanageexitdoco1033109023' filled=0 averageFillPrice=0 onBehalfOf='' id=37265 time='2020-07-02 09:31:55' gtd='2099-12-01' statementDate='2020-07-02'
    Cancel Orden

    Cancela Orden LE Take Profit por Trail orderId='d35c45ee282441cbafeae857e2d29d1c' account='Playback101' name='longProfitTarget' orderState=Cancelled instrument='NQ 09-20' orderAction=Sell orderType='Limit' limitPrice=10395 stopPrice=0 quantity=4 tif=Gtc oco='unmanageexitdoco1033109023' filled=0 averageFillPrice=0 onBehalfOf='' id=37264 time='2020-07-02 09:32:24' gtd='2099-12-01' statementDate='2020-07-02'
    Cancela Orden LE Stop Loss por Trail orderId='d35c45ee282441cbafeae857e2d29d1c' account='Playback101' name='longProfitTarget' orderState=Cancelled instrument='NQ 09-20' orderAction=Sell orderType='Limit' limitPrice=10395 stopPrice=0 quantity=4 tif=Gtc oco='unmanageexitdoco1033109023' filled=0 averageFillPrice=0 onBehalfOf='' id=37264 time='2020-07-02 09:32:24' gtd='2099-12-01' statementDate='2020-07-02'

    Trail Stop
    Trail Stop LE orderId='d46a5d1a27ad4bbf98388c04027fd723' account='Playback101' name='TP Trail LE' orderState=Accepted instrument='NQ 09-20' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=10382.25 quantity=5 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=37266 time='2020-07-02 09:32:24' gtd='2099-12-01' statementDate='2020-07-02'




    Code:

    // Trail Stop Long
    if (Position.MarketPosition == MarketPosition.Long && activeTrail)
    {


    double riskPoint = Math.Abs(targetOrderLE.LimitPrice - Position.AveragePrice);
    {
    if (Close[0] >= (Position.AveragePrice + Math.Abs((riskPoint * ((puntoActivacionTrail)/100)))))
    {
    if (stopOrderLE != null && stopOrderLE.StopPrice < Position.AveragePrice)
    {
    CancelOrder(targetOrderLE);
    Print("Cancel Orden LE Take Profit por Trail " + testOrder);
    CancelOrder(stopOrderLE);
    Print("Cancel Orden LE Stop Loss por Trail " + testOrder);
    stopOrderLE = SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.StopMarket, Position.Quantity, 0, Math.Round((Position.AveragePrice + ((riskPoint) * ((ipat1)/100))),2) , "", "TP Trail LE");
    Print("Trail Stop LE " + testOrder);
    PlaySound(NinjaTrader.Core.Globals.InstallDir + @"\sounds\AutoTrail.wav");
    puntoActivacionTrail = puntoActivacionTrail + incrementoConsolePriceTrail;
    ipat1 = ipat1 + incrementoConsoleTrail;
    }
    // Incremento del Trail
    if (Close[0] >= Position.AveragePrice + ((riskPoint)*((puntoActivacionTrail)/100)))
    {
    if (stopOrderLE != null && stopOrderLE.StopPrice > Position.AveragePrice && Close[0] > stopOrderLE.StopPrice
    && (Math.Round((Position.AveragePrice + ((riskPoint) * ((ipat1)/100))),2)) > stopOrderLE.StopPrice)
    {
    ChangeOrder(stopOrderLE,stopOrderLE.Quantity,0,Mat h.Round((Position.AveragePrice + ((riskPoint) * ((ipat1)/100))),2));
    PlaySound(NinjaTrader.Core.Globals.InstallDir + @"\sounds\AutoTrail.wav");
    puntoActivacionTrail = puntoActivacionTrail + incrementoConsolePriceTrail;
    ipat1 = ipat1 + incrementoConsoleTrail;
    }
    }
    }
    };
    }


    #2
    Hello HGTrader,

    It looks like this question was also sent into the email support where we had replied to that by email.


    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by algospoke, Yesterday, 06:40 PM
    2 responses
    19 views
    0 likes
    Last Post algospoke  
    Started by ghoul, Today, 06:02 PM
    3 responses
    14 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by jeronymite, 04-12-2024, 04:26 PM
    3 responses
    45 views
    0 likes
    Last Post jeronymite  
    Started by Barry Milan, Yesterday, 10:35 PM
    7 responses
    20 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by AttiM, 02-14-2024, 05:20 PM
    10 responses
    181 views
    0 likes
    Last Post jeronymite  
    Working...
    X