Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ghost order gets opened and cancelled

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

    ghost order gets opened and cancelled

    HI i have strategy that uses limit orders for entry, with onbar close.
    It uses both historical and real time processing. I am not sure but when there is no signal prints indicate orders gets opened and closed i am not sure where its coming from. Is it from historical processing? if I include this then I dont get similar ghost orders in print statements.
    if (State != State.Realtime) //Only trades realtime. Ignores historical trades.
    {
    return;
    }​

    my entry and Print methods
    if(BullBearFlag)
    {
    if (State == State.Historical && CurrentBar == BarsArray[0].Count - 2)
    {
    if (entryOrderFS != null)
    {
    suppressOcoF = true;
    exitNameF = "exit to start flat";
    exitFlatF = placeHolderOrderF;
    ExitShort(0, 1, exitNameF, entryOrderFS.Name);
    }
    }
    else if(beforeTradeShortCheck && bearFlagEntry && Close[0] > bearFlagEntryLevel && entryOrderFS == null
    && profitTargetFS == null && stopLossFS == null && GetCurrentAsk() >= bearFlagEntryLevel && !exitOnCloseWaitF)
    {
    // EnterShort(0,PositionSize, "LB Short");
    suppressOcoF = false;
    entryOrderFS = placeHolderOrderF;
    EnterShortStopMarket(0,true, PositionSize, bearFlagEntryLevel,"Flag Short");
    bearFlagEntry = false;

    }
    if(entryOrderFS != null && IsFirstTickOfBar && stochPrim[0] < maxStochFlagShort && stochPrim[0] > minStochFlagShort && bearFlagEntry && Close[0] > bearFlagEntryLevel
    && riskBearFlag < riskFlag && GetCurrentAsk() >= bearFlagEntryLevel && trendDirection == -1 && isLowSequence)
    {
    EnterShortStopMarket(0,true, PositionSize, bearFlagEntryLevel,"Flag Short");
    Print("entryOrderFS Reentry"+entryOrderFS);
    }
    if(entryOrderFS != null )
    {

    Print("entryOrderFS check:" + entryOrderFS);
    }
    if(entryOrderFS != null && IsFirstTickOfBar && (stochPrim[0] >= maxStochFlagShort || riskBearFlag > riskFlag || !isLowSequence ))
    {
    CancelOrder(entryOrderFS);
    Print("Cancel Sell order" + Time[0]);
    }
    if (ordersCancelledFS)
    {
    Print("stop and/or target cancelled or rejected");

    // if the orders were cancelled due to the exit on close, do not submit an order to flatten
    if (!exitOnCloseWaitF && entryOrderFS != null && entryOrderFS.OrderState == OrderState.Filled)
    {
    Print("exiting and resetting");

    exitNameF = "exit for cancel";
    exitFlatF = placeHolderOrder;
    ExitShort(exitNameF, entryOrderFS.Name);
    }

    if (entryOrderFS == null || entryOrderFS.OrderState != OrderState.Filled)
    Print(" entry not filled or is null");

    ordersCancelledFS = false;
    return;
    }

    }​


    my prints
    Enabling NinjaScript strategy 'LineBreakerAlgoTest/312671954' : On starting a real-time strategy - StartBehavior=WaitUntilFlat EntryHandling=Unique entries EntriesPerDirection=1 StopTargetHandling=Per entry execution ErrorHandling=Stop strategy, cancel orders, close positions ExitOnSessionClose=True / triggering 30 seconds before close SetOrderQuantityBy=Strategy ConnectionLossHandling=Recalculate DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=False CancelExitsOnStrategyDisable=False Calculate=On bar close IsUnmanaged=False MaxRestarts=4 in 5 minutes
    entryOrderFS checkrderId='NT-00186-5147' account='Sim101' name='Flag Short' orderState=Cancelled instrument='NQ 12-24' orderAction=SellShort orderType='Stop Market' limitPrice=0 stopPrice=20189.25 quantity=3 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2024-09-24 12:18:30' gtd='2099-12-01' statementDate='2024-09-24'

    Cancel Sell order9/24/2024 2:46:00 PM
    entryOrderFS checkrderId='NT-00186-5147' account='Sim101' name='Flag Short' orderState=Cancelled instrument='NQ 12-24' orderAction=SellShort orderType='Stop Market' limitPrice=0 stopPrice=20189.25 quantity=3 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2024-09-24 12:18:30' gtd='2099-12-01' statementDate='2024-09-24'

    Cancel Sell order9/24/2024 2:46:30 PM
    entryOrderFS checkrderId='NT-00186-5147' account='Sim101' name='Flag Short' orderState=Cancelled instrument='NQ 12-24' orderAction=SellShort orderType='Stop Market' limitPrice=0 stopPrice=20189.25 quantity=3 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2024-09-24 12:18:30' gtd='2099-12-01' statementDate='2024-09-24'

    Cancel Sell order9/24/2024 2:47:00 PM
    entryOrderFS checkrderId='NT-00186-5147' account='Sim101' name='Flag Short' orderState=Cancelled instrument='NQ 12-24' orderAction=SellShort orderType='Stop Market' limitPrice=0 stopPrice=20189.25 quantity=3 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2024-09-24 12:18:30' gtd='2099-12-01' statementDate='2024-09-24'

    Cancel Sell order9/24/2024 2:47:30 PM

    #2
    Hello tkaboris,

    The prints you provided appear to be custom so if you want to know when that is happening you could add the State into the print so you know if its historical or realtime. We would not be able to tell what happened based only on the prints and that part of your code, you would need to modify the prints so relevant information is output so you can review that while running and debugging the script.

    Comment


      #3
      Why when i cancel order
      i still get another cancel order of the same order. I think if i cancel order there will not be another instance of the same order to cancel.. you can see it by orderid in the prints below



      Ask >= BearFlag:True
      **********************
      entryOrderFL CheckrderId='4c104f088036465bafdf219478e54c72' account='Playback101' name='Flag Long' orderState=Cancelled instrument='NQ 12-24' orderAction=Buy orderType='Stop Market' limitPrice=0 stopPrice=20082.5 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=211341 time='2024-09-23 10:06:01' gtd='2099-12-01' statementDate='2024-09-23'
      Cancel Buy order9/23/2024 10:06:30 AM
      **********************
      Time after:9/23/2024 10:07:00 AM
      beforeTradeLongCheckTrue
      beforeTradeShortCheckTrue
      bullFlagFalse
      bearFlagFalse
      bullFlagEntryFalse
      bearFlagEntryFalse
      bullFlagEntryLevel20082.5
      bearFlagEntryLevel20055
      bearFlagPreEntryFalse
      trendlineValueUp20055.5
      bullFlagPreEntryFalse
      trendlineValueDn20082
      isHighSequence:False
      isLowSequence:False
      trendDirection1
      longTradeTakenFalse
      riskBullFlag10.5
      riskBearFlag9.5
      atrInd[0]:12.7216109795514
      chopIndex[0]49.3340253762486
      atrWithinRangeTrue
      limitFlagEntriesTrue
      stochPrim[0]74.7174731961744
      atrWithinRangeTrue
      exitOnCloseWaitFFalse
      Bid <= BullFlag:False
      Ask >= BearFlag:True
      **********************
      entryOrderFL CheckrderId='4c104f088036465bafdf219478e54c72' account='Playback101' name='Flag Long' orderState=Cancelled instrument='NQ 12-24' orderAction=Buy orderType='Stop Market' limitPrice=0 stopPrice=20082.5 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=211341 time='2024-09-23 10:06:01' gtd='2099-12-01' statementDate='2024-09-23'
      Cancel Buy order9/23/2024 10:07:00 AM​

      Comment


        #4
        Hello tkaboris,

        These are questions we cannot answer from the given information. You would need to debug the strategy if it is not performing as expected.

        Debugging involves using prints and actually running the strategy so you can evaluate how the logic you made works when run. Your prints don't mean anything to me specifically because I do not know where the prints are in the code and also I cannot run the code to see how it executed, those will only be useful for your while debugging on your machine.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        52 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        130 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        70 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        44 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        48 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X