Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

strategy analyzer doesnt follow rules

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

    strategy analyzer doesnt follow rules

    Hi in market replay strategy opens correctly, for example fast ema must be above slow ema for longs.
    in Strategy analyzer, i see that strategy violates this condition and opens long when fast is below slow ema.
    I implementeed 1 tick graniluity and placing orders at barsinprogress == 1 and my stategy uses multi timeframe

    AddDataSeries(Data.BarsPeriodType.Tick, 1)

    in my dataloaded
    else if (State == State.DataLoaded)
    {
    ClearOutputWindow(); //Clears Output window every time strategy is enabled
    fastEMA = EMA(FastEMAPeriod);
    slowEMA = EMA(SlowEMAPeriod);​
    }

    Do i need to implement something else in order that fast and slow ema conditions woulb be met in strategy analyzer?

    #2
    Hello tkaboris,

    Thanks for your post.

    Have you added debugging prints to your strategy to confirm exactly how the strategy conditions are evaluating and placing orders?

    In the strategy add prints (outside of any conditions) that print the values of every variable used in every condition that places an order along with the time of that bar.

    For example, if you are creating a crossover condition, one line above the condition print out the values being used in the crossover condition and any other values being used in your condition to place the order. Then, add a print inside the condition after calling your Entry order method to confirm that the entry order method was called.

    This will allow you to see exactly how the values in your condition are evaluating and confirm entry orders are submitting when the condition to place the order is true.

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

    Below is a link to a forum post that demonstrates how to use prints to understand behavior.
    https://ninjatrader.com/support/foru...121#post791121​​
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Hi yes i did and strategy behaves as suppose to in market replay, however in strategy analyzer condition not getting met.
      see screenshot

      Click image for larger version

Name:	image.png
Views:	135
Size:	75.5 KB
ID:	1265648

      Comment


        #4
        Hello tkaboris,

        Thanks for your notes.

        So I may investigate further, please send me a copy of your print output in the NinjaScript Output window so I may see how the condition values are evaluating when the order is placed at that time.

        When the print output from the Output window appears after running a backtest, save this by right-clicking the Output window and selecting Save As... > give the output file a name and save > then attach the output to your reply.

        And, share a screenshot of the order being placed on the chart and ensure the time on the chart is visible in the screenshot so that it can be compared to the time printed in the Output window from your strategy prints.
        • To send a screenshot with Windows 10 or newer I would recommend using the Windows Snipping Tool.
        • Alternatively to send a screenshot press Alt + PRINT SCREEN to take a screenshot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Lastly, save it as a jpeg file and send the file as an attachment.

        i look forward to assisting further.
        Last edited by NinjaTrader_BrandonH; 08-22-2023, 08:38 AM.
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment


          #5
          HI I get this output and its taking all the space and i cant get to the printss of the actual order.
          I attached a trace file maybe information is in there.

          Strangly, when i select 1 week time to test, strategy doesnt take that trade, if i select 30 days strategy takes that wrong trade. Screenshot is the first on in the post.

          Also , i don tknow why but in live trading(not market replay) on buy order with 5 contracts, orders get filled and closed but 1 contract sell leaves hanging.
          It doesnt happen in market replay.. What could it be?


          7/31/2023 3:59:59 PM Strategy 'Sparta Algo/-1': Entered internal SubmitOrderManaged() method at 7/31/2023 3:59:59 PM: BarsInProgress=1 Action=Sell OrderType=Limit Quantity=0 LimitPrice=5.00 StopPrice=0 SignalName='PTL' FromEntrySignal='Xiphos Long'
          7/31/2023 3:59:59 PM Strategy 'Sparta Algo/-1': Ignored SubmitOrderManaged() method at 7/31/2023 3:59:59 PM: BarsInProgress=1 Action=Sell OrderType=Limit Quantity=0 LimitPrice=5.00 StopPrice=0 SignalName='PTL' FromEntrySignal='Xiphos Long' Reason='This was an exit order but no position exists to exit'
          7/31/2023 3:59:59 PM Strategy 'Sparta Algo/-1': Entered internal SubmitOrderManaged() method at 7/31/2023 3:59:59 PM: BarsInProgress=1 Action=Sell OrderType=Limit Quantity=0 LimitPrice=5.00 StopPrice=0 SignalName='PTL' FromEntrySignal='Dory Long'
          7/31/2023 3:59:59 PM Strategy 'Sparta Algo/-1': Ignored SubmitOrderManaged() method at 7/31/2023 3:59:59 PM: BarsInProgress=1 Action=Sell OrderType=Limit Quantity=0 LimitPrice=5.00 StopPrice=0 SignalName='PTL' FromEntrySignal='Dory Long' Reason='This was an exit order but no position exists to exit'
          7/31/2023 3:59:59 PM Strategy 'Sparta Algo/-1': Entered internal SubmitOrderManaged() method at 7/31/2023 3:59:59 PM: BarsInProgress=1 Action=Sell OrderType=Limit Quantity=0 LimitPrice=5.00 StopPrice=0 SignalName='PTL' FromEntrySignal='Kopis Long'
          7/31/2023 3:59:59 PM Strategy 'Sparta Algo/-1': Ignored SubmitOrderManaged() method at 7/31/2023 3:59:59 PM: BarsInProgress=1 Action=Sell OrderType=Limit Quantity=0 LimitPrice=5.00 StopPrice=0 SignalName='PTL' FromEntrySignal='Kopis Long' Reason='This was an exit order but no position exists to exit'​
          Attached Files

          Comment


            #6
            Hello tkaboris,

            Thanks for your notes.

            7/31/2023 3:59:59 PM Strategy 'Sparta Algo/-1': Ignored SubmitOrderManaged() method at 7/31/2023 3:59:59 PM: BarsInProgress=1 Action=Sell OrderType=Limit Quantity=0 LimitPrice=5.00 StopPrice=0 SignalName='PTL' FromEntrySignal='Xiphos Long' Reason='This was an exit order but no position exists to exit'

            This message will appear when your strategy calls ExitLong() or ExitShort() but no position exists to exit. You can check the current strategy position by referencing the Position.MarketPosition enum. You might need to add checks for an actual position before calling ExitLong()/ExitShort().

            For example, checking if Position.MarketPosition == MarketPosition.Long in BarsInProgress 1 before calling your ExitLong() method.

            See the help guide documentation below for more information.

            Position.MarketPosition: https://ninjatrader.com/support/help...etposition.htm
            Working with Multi-Timeframe/Multi-Instrument NinjaScripts: https://ninjatrader.com/support/help...nstruments.htm

            ​If you need to compare prints but there are so many prints that the prints you want to compare do not show in the Output window, you could send the prints to a text file by using a StreamWriter and then compare the prints in the text file.

            See this reference sample demonstrating using a StreamWriter: https://ninjatrader.com/support/help...o_write_to.htm
            <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

            Comment


              #7
              ok, i only have ExitShortStopMarket and ExitShortLimit, not ExitShort(). Does it apply to those too?

              Comment


                #8
                Hello tkaboris,

                Thanks for your notes.

                Yes, this applies to any Exit orders, long or short.

                Before calling your Exit order methods, you should make sure you are checking if Position.MarketPosition == MarketPosition.Short in BarsInProgress 1 to make sure you are in a short position in BarsInProgress 1 before calling your Exit order method in the script.

                Otherwise, the Exit order could be called when you are not in a short position which would result in the error message.
                <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                Comment


                  #9
                  Thank you
                  I have the following code but it still left one hanging. maybe i forgot to refresh the code or something and wondering if there can be something else that causing one order left hanging..

                  if (UseFixedSLTP)
                  if(Position.MarketPosition == MarketPosition.Short && Position.AveragePrice + (TickSize * StopLossTicks) >= ask){
                  ExitShortStopMarket(1, true, Position.Quantity, Position.AveragePrice + (TickSize * StopLossTicks), "SLS", "Xiphos Short");

                  in the screenshot originally it took 5 contracts order and then it still picked one hanging contract.

                  Comment


                    #10
                    Hello tkaboris,

                    Thanks for your notes.

                    I clicked the screenshot link you shared but the link leads to a page saying that the screenshot was removed.

                    To ensure the modified script is being used, first, run a compile to make sure changes to the code are saved. After compiling, please remove the strategy instance from the chart and then re-add the strategy instance back to the chart window and test its behavior.

                    If you are backtesting the script, run a compile to make sure changes to the code are saved, then select a different strategy in the Strategy Analyzer properties and then select your strategy.

                    If the strategy is still behaving the same, after removing the strategy instance and re-adding it to the chart, please send me a reduced exported copy of the strategy and the exact steps and settings you are using to reproduce the behavior so that I may test it on my end.

                    Note that a reduced copy refers to a copy of the script that contains the minimum amount of code needed to reproduce the issue. All other code is commented out or removed. To create a copy of your script to modify, open a New > NinjaScript Editor, select your script, right-click in the Editor, select 'Save as', name the script, and click OK.

                    To export the strategy, go to Tools > Export > NinjaScript AddOn.​
                    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                    Comment


                      #11
                      hi again.
                      I have implemented fix like i mentioned in post 9 but it still leaves hanging order. Where else can i look?
                      Thank you

                      Comment


                        #12
                        Hello tkaboris,

                        Thanks for your notes.

                        Please send a screenshot and brief description demonstrating exactly what you mean by 'still leaves hanging order' so I may accurately assist.

                        Does the order marker appear orange in color on the Chart window indicating a stuck order?

                        Is your strategy placing an entry order with a quantity of 5 but the strategy is only exiting a quantity of 4, leaving 1 order running on the chart?

                        From my previous post: "If the strategy is still behaving the same, after removing the strategy instance and re-adding it to the chart, please send me a reduced exported copy of the strategy and the exact steps and settings you are using to reproduce the behavior so that I may test it on my end.

                        Note that a reduced copy refers to a copy of the script that contains the minimum amount of code needed to reproduce the issue. All other code is commented out or removed. To create a copy of your script to modify, open a New > NinjaScript Editor, select your script, right-click in the Editor, select 'Save as', name the script, and click OK.

                        To export the strategy, go to Tools > Export > NinjaScript AddOn.​"
                        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                        Comment


                          #13
                          hi this is a screenshot from yetserday and it only happens in real time live trading.


                          it took 5 contracts, close in take profit and left one order hanging and executed it

                          Comment


                            #14
                            Hello tkaboris,

                            Thanks for your notes.

                            Please write in to support[at]ninjatrader[dot]com and follow the instructions below to attach your log and trace files to your email so that I may investigate this matter further. In the Subject of the email include 'ATTN BrandonH' and in the body of the email include a link to this forum thread.

                            Also, please send me the Order ID number of the order in question and the time that this behavior occurred so I may look into this further.

                            Follow the steps below to manually attach your log and trace files to your response so I may investigate this matter further.
                            • Open your NinjaTrader folder under, "Documents" (sometimes called, "My Documents")
                            • Right click on the 'log' and 'trace' folders and select Send To> Compressed (zipped) Folder.
                            • Send the 2 compressed folders as attachments to this email.
                            • Once complete, you can delete these compressed folders.
                            I look forward to assisting further.​
                            <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                            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