Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

no orders sent from OnBarUpdate in ImmediatelySubmit

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

    no orders sent from OnBarUpdate in ImmediatelySubmit

    Hi, I did try to read as much as I could and also consult your excellent ChatGPT NT8 stack - yet struggling to understand why my manual-synchronization orders are not sent or appear in the Orders log at all.

    Motivation: All options to "sync" StartBehavior create these really wrong-priced "virtual entries".

    Implementation:
    In StateChange to Realtime the code detects when position is not flat, then raises a flag so that the first(?) OnBarUpdate (or next/whatever) send a "sync" order. I can print these "are called" but neither OnOrderUpdate or OnExecutionUpdate show these Accepted/Rejected etc.???

    Could you please help guide me?

    Extra question: can these be simulated in Playback mode?

    Thank you in advance!!!

    Code:
    protected override void OnBarUpdate()
            {    
                //if( CurrentBar < BarsRequiredToTrade )
                //    return;
    
                // Sync orders from Historical to Realtime to avoid wrong P/L reports and "virtual entries"
                if (needSync && !realTimeSynched)
                    SyncLivePosition();
    ....
    ​
    Code:
    private void SyncLivePosition()
            {
                if (Position.MarketPosition == MarketPosition.Long)
                {
                    Print(Time[0] + " Transition Historical position into Realtime: Re-entering Long position...");
                    EnterLong("Long");
                }
                else if (Position.MarketPosition == MarketPosition.Short)
                {
                    Print(Time[0] + " Transition Historical position into Realtime: Re-entering Short position...");
                    EnterShort("Short");
                }
                else
                {
                    Print(Time[0] + " No position to sync at Reatltime, staying flat.");
                }
                realTimeSynched = true;
                needSync = false;
                
                // try getting new position info???
                StrategyPositionInfo();
            }​

    #2
    Hello momchi,

    Thank you for your post.

    To understand why the script is behaving as it is, such as placing orders or not placing orders or drawing objects when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

    In the strategy add prints (outside of any conditions) that print the date time of the bar and all values compared in every condition that places an order.

    The prints should include the time of the bar and should print all values from all variables and all hard coded values in all conditions that must evaluate as true for this action to be triggered. It is very important to include a text label for each value and for each comparison operator in the print to understand what is being compared in the condition sets.

    The debugging print output should clearly show what the condition is, what time the conditions are being compared, all values being compared, and how they are being compared.

    Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

    Further, enable TraceOrders which will let us know if any orders are being ignored and not being submitted when the condition to place the orders is evaluating as true.

    After enabling TraceOrders remove the instance of the strategy from the Configured list in the Strategies window and add a new instance of the strategy from the Available list.

    I am happy to assist you with analyzing the output from the output window.

    Run or backtest the script and when the output from the output window appears save this by right-clicking the output window and selecting Save As... -> give the output file a name and save -> then attach the output text file to your reply.

    Below is a link to a support article that demonstrates using informative prints to understand behavior and includes a link to a video recorded using the Strategy Builder to add prints.

    https://support.ninjatrader.com/s/ar...nd-TraceOrders

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by abelsheila, 05-14-2025, 07:38 PM
    2 responses
    34 views
    0 likes
    Last Post hglover945  
    Started by nailz420, 05-14-2025, 09:14 AM
    1 response
    73 views
    0 likes
    Last Post NinjaTrader_ChristopherJ  
    Started by NinjaTrader_Brett, 05-12-2025, 03:19 PM
    0 responses
    353 views
    1 like
    Last Post NinjaTrader_Brett  
    Started by domjabs, 05-12-2025, 01:55 PM
    2 responses
    67 views
    0 likes
    Last Post domjabs
    by domjabs
     
    Started by Morning Cup Of Trades, 05-12-2025, 11:50 AM
    1 response
    87 views
    0 likes
    Last Post NinjaTrader_ChristopherJ  
    Working...
    X