Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

few issues with the Strategy

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

    few issues with the Strategy

    I've been trying to make this strategy work. I've taken inputs from my previous posts and still having challenges. I really appreciate if this can be reviewed for following issue -

    1) Entries are not triggered at the correct place. As show in the below screenshot, I was expecting the entry when the price of the next bar after the signal is above the signal barBut that is not. happening. I wasn't sure what I'm missing here

    https://ra3-gmail.tinytake.com/msc/N...NV8xODcxMjg1NA

    as you see, the trades are triggered in the next bar after the signal bar but not meeting the condition (only trigger when the price is above the signal bar in this particular example)

    Also, question: is signal bar candle is price[1] or price[0] ?

    2) I see the past trades shown on the chart as soon as I enable the strategy. However, they are not triggering in real-time. I do see the strategy in green in control center

    uploaded my strategy (removed other proprietary logic for confidentiality)

    Thanks for reviewing it and apart from this I appreciate if there are any improvements I can make to the order management logic here.
    Attached Files
    Last edited by ark321; 12-31-2021, 02:17 PM.

    #2
    Hello ark321,

    Thanks for your post.

    1) Entries are not triggered at the correct place. As show in the below screenshot, I was expecting the entry when the price of the next bar after the signal is above the signal bar But that is not. happening. I wasn't sure what I'm missing here
    OnBarUpdate logic is processed differently between historical processing (backtesting) and realtime processing. During historical processing, strategy logic is processed bar by bar following Calculate.OnBarClose behaviors because there is no intrabar movement in a backtest. During realtime processing, a strategy can then take advantage of Calculate.OnEachTick or Calculate.OnPriceChange for intrabar logic.

    This would mean that orders are submitted at the close of the bar and the order will be filled with data on the next bar.

    As far as the orders filling on the same bar, it looks like your logic allows this. Your screenshot shows "EnterLong 1" and "EnterLong 2" enter, and this would be the case if the block below was processed if your ExitQuantity variable is greater than 0.

    Code:
     {
    
        Entry1IsClosed = false;
        SetStopLoss(CalculationMode.Ticks, StopLoss);
        SetProfitTarget("EnterLong 1", CalculationMode.Ticks, ProfitTarget);
        EnterLong(Quantity - ExitQuantity, "EnterLong 1");
    
        if(ExitQuantity > 0)
        {
            EnterLong(ExitQuantity, "EnterLong 2");
            //SetProfitTarget("EnterLong 2", CalculationMode.Ticks, ProfitTarget2);
        }
    }

    2) I see the past trades shown on the chart as soon as I enable the strategy. However, they are not triggering in real-time. I do see the strategy in green in control center
    If the strategy is green, it is allowed to place realtime orders. The question then would be if your logic is allowing the order methods to be reached, or if the order methods are ignored due to internal rules.

    Please use debugging prints to confirm your logic is allowing the order methods to be reached (place a print beside the order methods.)

    If the print is seen, please test again with TraceOrders to see why the order submission was ignored.

    If the print is not seen, the logic controlling this order submission would need to be checked to see why it is not allowing the actions to be met.

    Playback can help to reproduce behaviors so debugging steps can be taken to analyze.

    Debugging Tips - https://ninjatrader.com/support/help...script_cod.htm

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

    Playback Connection - https://ninjatrader.com/support/help...connection.htm

    Managed Approach (Internal Rules) - https://ninjatrader.com/support/help...antedPositions

    Let us know if you have any questions regarding the debug output or TraceOrders feedback.


    Comment


      #3
      Regarding the (1), I've these checks High[0] > High[1] (for long) and Low[0] < Low[1] (for short), why didn't the trade trigger at the high of the signal bar (for long) or low of the signal bar (for short)?

      Comment


        #4
        Hello ark123,

        When we are processing Calculate.OnBarClose or processing historical data, the order will be triggered on the bar where the condition becomes true, and the order will be submitted then and filled with data after that "trigger bar"

        So with EnterLong/EnterShort we would see the condition become true and the order submitted, and on the chart, the order would be filled on the next bar. So we would see the execution marker appear on the bar after the order was submitted. This is sometimes referred to as the "trigger bar" and the "fill bar"

        If no order was submitted at all, confirming the order method is reached, and checking TraceOrders would be necessary to see why an order method was not reached or was ignored.

        If you have additional questions, please illustrate what you are seeing with screenshots and please share how you have set up debugging prints showing that the order submission methods are being reached. Please share any TraceOrders related questions you may have as well.

        Comment


          #5
          the strategy is set to Calculate.OnEachTick,

          And I've condition to execute only if High[0] > High[1] (for long) and Low[0] < Low[1] (for short). Why is this condition not honored ? What I was trying to do here is that the fill bar has to be above the signal bar (for long) or below the signal bar (for short). Is my logic incorrect here?

          Also, how do I make the historical processing and live processing to be same?

          Comment


            #6
            Hello ark123,

            Actions controlled by a condition will only be met if the condition evaluating it evaluates as true. If you are seeing actions met, it means the conditions did become true. You can print out the values used in the condition, along with the bar timestamp, outside of the condition, and it will tell you each value used in that condition, before it gets evaluated, so you can see exactly how the condition became true.

            If you see an unexpected action, use prints to check how the conditions controlling that action allowed that action to take place.

            If you do not see expected actions, use prints to make sure the orders/actions are met, and use TraceOrders to see if an order is getting ignored if you can confirm the order method is reached with a print.

            Your logic would process on the "signal bar" if you submit a market order on that bar, the execution marker would appear on the "fill bar." "Fill bar just means where the order filled, not where it was submitted.

            Backtesting and realtime testing are fundamentally different. We should not expect these results to be the same. However, to make a strategy that can be backtested and attain similar results to a realtime test, I suggest programming the strategy to use Calculate.OnBarClose, and use Order Fill resolution set to High with a 1 tick data series. Playback can also be considered as Playback mimics realtime data.

            Discrepancies between realtime and backtest - https://ninjatrader.com/support/help...ime_vs_bac.htm

            Understanding historical fill processing - https://ninjatrader.com/support/help...ical_fill_.htm

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Yesterday, 05:17 AM
            0 responses
            58 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            133 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
            50 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X