Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Order auto close

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

    Order auto close

    Hello

    i have made a strategy and tested it on playback mode succesffully but when i use it on a eval account nothing happens or when and order is submitted it auto close instantly. I encountered the same issue in play back mode and bypassed it by setting isSimulatedStop=true in setstoploss function, but it doesn't workd in live/eval. So i decided to made a simple strategy :




    protected override void OnBarUpdate()
    {
    //Add your custom strategy logic here.

    if(Close[0]>Open[0] && Position.MarketPosition==MarketPosition.Flat){
    EnterLong(1,"Long");
    SetStopLoss("Long", CalculationMode.Price, Low[0]-20, true);
    }

    if(Close[0]<Open[0] && Position.MarketPosition==MarketPosition.Flat){
    EnterShort(1,"Short");
    SetStopLoss("Short", CalculationMode.Price, High[0]+20, true);
    }

    }​


    When i use it in sim/live with these properties :
    Maximum bars look back : Infinite
    Bars required to trade : 1
    Start behavior : Wait until flat

    Then nothing happen and sometimes an order is filled and autoclose..

    Thanks for your help

    #2
    Hi xMCoo, please first re-arrange your call to SetStopLoss to be ahead of the entry order:

    SetStopLoss("Long", CalculationMode.Price, Low[0]-20, true);
    EnterLong(1,"Long");


    SetStopLoss("Short", CalculationMode.Price, High[0]+20, true);
    EnterShort(1,"Short");

    What could happen is the SetStopLoss could be set from the previous entry which could be an invalid price level. ​

    Comment


      #3
      Hello ChristL, i ve juste tried, non order is filled

      Comment


        #4
        Hi, If you turn on Trace Orders do you see any ignored entries coming from your script when you run it?

        https://ninjatrader.com/support/help...aceorders2.htm

        Please also use a simple Print() within your code to see if your entry signal is being reached:

        Code:
        if(Close[0]<Open[0] && Position.MarketPosition==MarketPosition.Flat)
        {
            Print("Submitting short order"); //if you see this, you know the strategy is reaching its entry signals.
            SetStopLoss("Short", CalculationMode.Price, High[0]+20, true);
            EnterShort(1,"Short");
        
        }
        ​
        You may also try other strategies that are confirmed to work here:
        https://ninjatrader.com/support/foru...der#post806596

        Comment


          #5
          No print, no trace order in print output, only thing i see in log is :
          2023-04-14 21:58:54:993|3|4|Strategy 'xmCTest/262996463': An order placed at '11/04/2023 00:00:01' has been ignored since the order was submitted before the strategy property BarsRequiredToTrade had been met.
          2023-04-14 21:58:55:045|1|4|Enabling NinjaScript strategy 'xmCTest/262996463' : On starting a real-time strategy - StartBehavior=WaitUntilFlat Position=MNQ 06-23 1L EntryHandling=All 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

          Comment


            #6
            Hi, If you do not see a print here it means the entry signal is not being reached. You can confirm this again using prints to print out

            Print(Close[0]<Open[0]);
            Print(Position.MarketPosition==MarketPosition.Flat );

            Comment


              #7
              I think i have found why, it seems that when i enable the strategy passed bars are processed and a position is opened in the past so the position is not flat. When the stop is reached then a realtime order is filled.
              Last edited by xMCoo; 04-14-2023, 04:04 PM.

              Comment


                #8
                Hi, thanks for the follow up. The historical position should not be submitting a real time order. You can use the startup behavior WaitUntilFlat or ImmediatelySubmit, Synchronize account to have the strategy take on the historical position in real time.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by NullPointStrategies, Yesterday, 05:17 AM
                0 responses
                56 views
                0 likes
                Last Post NullPointStrategies  
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                132 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                73 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                45 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Started by TheRealMorford, 03-05-2026, 06:15 PM
                0 responses
                49 views
                0 likes
                Last Post TheRealMorford  
                Working...
                X