Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Failing to actually manage the Managed approach

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

    Failing to actually manage the Managed approach

    Hello,

    Iam quite desperate. For days, I created like four completely different versions for managing one simple order and it just not even remotely works correctly

    Strategy selects some closed candle by some conditions. So far so good.

    Now we calculate Ticks and set LimitBuy, StopLoss and ProfitTarget. Still good.

    PHP Code:
    Order_Long_Limit_A1 = EnterLongLimit(0, true, 1, Ticks_Long_Limit_A1, "Buy_A1");
    Order_Long_Stop_A1   = ExitLongStop (0, true, 1, Ticks_Long_Stop_A1,   "Stop_A1",   "Buy_A1");
    Order_Long_Target_A1 = ExitLongLimit(0, true, 1, Ticks_Long_Target_A1, "Target_A1", "Buy_A1"); 
    

    Now I want to be able to monitor the LimitBuy order:

    If it reaches TargetProfit or StopLoss BEFORE it gets filled, I want to cancel/kill/destroy everything and start over. Not working at all.
    PHP Code:
    // REACHED TARGET OR STOP BEFORE FILLED LIMIT BUY
    if ( Order_Long_Limit_A1 != null && Order_Long_Stop_A1 != null && Order_Long_Target_A1 != null && Order_Long_Target_A1.OrderState != OrderState.Filled && Order_Long_Stop_A1.OrderState != OrderState.Filled) 
    {
        // HIGH of current bar is higher than TARGET PROFIT
        if ( High[0] >= Ticks_Long_Target_A1 ) 
        {   
            Reset_Long_A1();
        }
        
        // LOW of current bar is lower than STOP LOSS
        else if ( Low[0] <= Ticks_Long_Stop_A1 ) 
        {
            Reset_Long_A1();
        }
    } 
    
    If it do or do not get filled and not reached Target or Stop, I want to cancel it in some time. Thats the only thing that works.
    PHP Code:
    if (CurrentBar >= (Order_Bar_Number + 10) && Order_Long_Limit_A1 != null) 
    
    Beside that, Id like it to work when the order actually gets Filled and reaches either Target or StopLoss, which is currently does nothig as well.


    So lets recap:

    1) I need to submit Limit Buy, StopLoss and Target profit.
    2) I need it to cancel itself when not filled and reached either Stop or Target and clean everything else remaining, that can mess with new order.
    3) I need it to actually work correctly on StopLoss and target, when order IS filled.
    4) there is more buggy behaviourin the attached picture, I need to correct.

    So please, please, please is there some SIMPLE way to manage the order?? I couldnt get it work in 650 lines of code... I read the help from top to bottom and back again. Really not helped much :-/ I appreciate every hint of help. Code is attached as well.
    Attached Files

    #2
    Hello Avisak,

    Thank you for your post.

    On the screenshot, are these historical executions?

    If you open the Output Window (Tools > Output) and runt he strategy again, do you see any ignore message?

    Comment


      #3
      Hello Patrick, yes, these are historical executions.

      The output window is clean, no errors, beside standard:
      Code:
      **NT** Enabling NinjaScript strategy 'AvisFibot/e411a7d5ad804e0cbc4330d3ef8dc6b0' : On starting a real-time strategy - StrategySync=WaitUntilFlat SyncAccountPosition=False EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositions ExitOnClose=True/ triggering 30 before close Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=True CalculateOnBarClose=False MaxRestarts=4 in 5 minutes
      When I turn on TraceOrders, there is the following:

      Code:
      20.2.2015 8:35:00 Entered internal PlaceOrder() method at 20.2.2015 8:35:00: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=10973,0 StopPrice=0 SignalName='Buy_A1' FromEntrySignal=''
      20.2.2015 8:35:00 Entered internal PlaceOrder() method at 20.2.2015 8:35:00: BarsInProgress=0 Action=Sell OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=10970,5 SignalName='Stop_A1' FromEntrySignal='Buy_A1'
      20.2.2015 8:35:00 Ignored PlaceOrder() method: Action=Sell OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=10970,5 SignalName='Stop_A1' FromEntrySignal='Buy_A1' Reason='This was an exit order but no position exists to exit'
      20.2.2015 8:35:00 Entered internal PlaceOrder() method at 20.2.2015 8:35:00: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=1 LimitPrice=10974,0 StopPrice=0 SignalName='Target_A1' FromEntrySignal='Buy_A1'
      20.2.2015 8:35:00 Ignored PlaceOrder() method: Action=Sell OrderType=Limit Quantity=1 LimitPrice=10974,0 StopPrice=0 SignalName='Target_A1' FromEntrySignal='Buy_A1' Reason='This was an exit order but no position exists to exit'
      Any idea?


      On live data trading the order seems to be placed correctly.
      Attached Files
      Last edited by Avisak; 02-20-2015, 01:48 AM.

      Comment


        #4
        Hello Avisak,

        Your condition for going long -
        // GO LONG -------------------------------------------

        Is only going to be true to place the initial entry, however your exit orders are being placed at the same time but will get ignored cause there is no open position and the condition no longer becomes true from the Null check for the IOrder object.

        You need to adjust your condition tracking for the the GO LONG or move the Exit orders outside of that check and place them in OnExecution. Use OnExecution to detect when the Entry is filled and then place the working Stop and Profit orders.

        http://www.ninjatrader.com/support/f...ead.php?t=7499
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          That seems to help, thank you very much.

          It is now working at live trading, but not at back data. Not at all. Is there some fix, or the only way is to completely rewrite another strategy for backtesting?


          And the second issue is when I add second order (A1 and A2) like this:
          PHP Code:
          Order_Long_Limit_A1 = EnterLongLimit(0, true, 1, Ticks_Long_Limit_A1, "Buy_A1");
          Order_Long_Limit_A2 = EnterLongLimit(0, true, 1, Ticks_Long_Limit_A2, "Buy_A2"); 
          
          The second order gets ignored like this:
          Code:
          20.2.2015 21:26:00 Entered internal PlaceOrder() method at 20.2.2015 21:26:00: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=11146,0 StopPrice=0 SignalName='Buy_A1' FromEntrySignal=''
          20.2.2015 21:26:00 Entered internal PlaceOrder() method at 20.2.2015 21:26:00: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=11146,0 StopPrice=0 SignalName='Buy_A2' FromEntrySignal=''
          20.2.2015 21:26:00 Ignored PlaceOrder() method at 20.2.2015 21:26:00: Action=Buy OrderType=Limit Quantity=1 LimitPrice=11146,0 StopPrice=0 SignalName='Buy_A2' FromEntrySignal='' Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'
          Even though I have setted:
          PHP Code:
          protected override void Initialize()
          {
               CalculateOnBarClose = false;
               TraceOrders = true;
               EntryHandling = EntryHandling.AllEntries;
               EntriesPerDirection = 999;            
          } 
          
          EntryHandling = EntryHandling.UniqueEntries; did not helped either Any ideas? Looking forward to your reply

          Comment


            #6
            Aviask,

            Do those values get set in the strategy properties section when running the backtest?
            Cal H.NinjaTrader Customer Service

            Comment


              #7
              Iam quite sure they are, since the only values I have in my properties section are the ones Im managing from Strategies window as well and for all of them I have setted default values.

              Comment


                #8
                Avisak,

                At this time, I would like to setup a remote session with you for Tuesday.

                Please send me a note to platformsupport [at] ninjatrader [dot] com

                Put Attn Cal in the subject and reference this thread in the body
                Cal H.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                649 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                370 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                109 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                574 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                576 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X