Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stop and Target orders created by Exit... not showing in Orders tab or chart trader.

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

    Stop and Target orders created by Exit... not showing in Orders tab or chart trader.

    Hi,
    On Ninjatrader 8.0, I have a custom strategy coded in Ninjascript, which originally worked fine with managed orders using the SetStopLoss and SetProfitTarget commands.
    For example:

    (done once from the "(State == State.Configure)" section of OnStateChange() )

    SetProfitTarget("ScalpLong",CalculationMode.Ticks, tgt1Ticks);
    SetProfitTarget("ScalpShort",CalculationMode.Ticks , tgt1Ticks);
    SetStopLoss("ScalpLong",CalculationMode.Ticks, stop1Ticks, false);
    SetStopLoss("ScalpShort",CalculationMode.Ticks, stop1Ticks, false);​


    However, there is now a requirement that the user is able to use chart trader to manually drag the stop and target while the system is running, to change the stop or target on the chart. If the user drags the stop or target when I'm using the Set... commands for stop/target placement, the stop or target can't be moved manually; they seem to snap back to their original place on the next incoming tick.

    There is a solution on the forum:


    The proposed solution is not to use Set... commands, but instead (for long) use ExitLongStopLimit() to place the stop order, and ExitLongLimit() for the target (and the Short versions of these commands for the equivalent short side).

    I have commented out the Set... commands in Configure, and am now instead using the ExitLong... and ExitShort... commands, triggered when the order is detected as being filled in OnOrderUpdate:

    protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError)
    {​
    ....
    if ((order.Name == "ScalpLong")&&(order.OrderState == OrderState.Filled)) {

    // stop:
    double stopPriceOOU = averageFillPrice - stop1Ticks*TickSize;
    stopOrder = ExitLongStopLimit(0, true, quantity, stopPriceOOU, stopPriceOOU, "ScalpStop", "ScalpLong");
    if (stopOrder == null) {
    Print("Warning: long stop order is null");
    };​
    // target:
    double targetPriceOOU = averageFillPrice + stop1Ticks*TickSize;​
    targetOrder = ExitLongLimit(0, true, quantity, targetPriceOOU, "ScalpTarget", "ScalpLong");
    if (targetOrder == null) {
    Print("Warning: long target order is null");
    };​
    } else if ((order.Name == "ScalpShort")&&(order.OrderState == OrderState.Filled)) {
    double stopPriceOOU = averageFillPrice + stop1Ticks*TickSize;
    ...etc...


    The problem is, if you have a chart window for this instrument (a futures market), where the chart is of that exact same instrument and contract month as the strategy is using,
    (the strategy was actually created by adding it directly to that chart)
    and you turn on chart trader for that chart, and you set the account on chart trader to the same simulation account name that the strategy is running,
    you can see the entry made on chart trader. Which also confirms that the correct simulation account is being used (it is the only strategy running), you can see the order entry. If the simulation account was wrong, you wouldn't see the horizontal entry order line (and price) visible on the chart with chart trader turned on.

    However, the problem is you don't see the stop or target orders on chart trader like you normally would.

    And there is another strange problem. When those orders are active, you also don't see them on the main Ninjatrader window, in the Orders tab. You only see the entry order in the orders list.

    As an experiment, I changed EntriesPerDirection from 1 to 3.
    EntriesPerDirection = 3;
    It did not fix the problem. I still do not see the orders in the chart trader, and do not see them in the Orders tab on the main window.

    Additional print statements indicate that the stop and target prices seemed to be calculated correctly and looked reasonable for the market.

    I have tried other forms of the Exit... orders, such as:

    // template: ExitLongStopLimit(double limitPrice, double stopPrice, string signalName, string fromEntrySignal)
    //ExitLongStopLimit(0, stopPriceOOU, "ScalpStop", "ScalpLong");
    //ExitLongStopLimit(0, stopPriceOOU, "ScalpLong");​


    same result, can't see anything from chart trader, and no pending orders on the orders tab.

    I do see the following message on the ninjascript output window (which is generated by the error checking code above):

    Warning: long stop order is null
    Warning: long target order is null​

    Is there a better way to get orders to show up and be movable on the chart trader?
    Are Exit... orders actually real orders sent to the exchange, or are they held on the local machine?
    I assume Chart trader doesn't see the orders because the order is null on return. I don't see any information or errors on the stop or target orders in the Ninjatrader Log tab, only the original entry order completing as it enters.

    Thanks.​

    #2
    Hello, thanks for writing in. As long as the Chart Trader account is selected and is the same account that is running in the strategy the orders submitted to the account will be displayed. If your accounts are set up correctly and you do not see the orders, the orders are null. We have an example here that works properly if you would like to reference this for an example:

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Today, 05:17 AM
    0 responses
    50 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    126 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    69 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    42 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    46 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X