Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Right logic on Market Replay and wrong on Real Time

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

    Right logic on Market Replay and wrong on Real Time


    Hello

    I tested my BOT with Market Replay and it put correct quantity of SL and PT, BUT when I tried to run it on real data - it put wrong quantity SL and PT if have more one conditions on one candle...
    So I have the question: why code is working correctly on Market replay and working with errors on realtime?​

    Thanks.​

    #2
    Hello vitaly_p,

    Thank you for your post.

    You mentioned, "if have more one conditions on one candle" - is this a difference between market replay and real-time data? Were you seeing a different number of conditions being met in each environment?

    I suggest adding print statements to better understand your strategy's behavior. For more details on using prints for debugging:Otherwise, when it comes to conditions, are you wanting more than one condition to be evaluated on the same candle? If not, you can add additional logic to make sure a new bar is started before a condition may be checked again.

    Please let me know if I may be of further assistance.
    Emily C.NinjaTrader Customer Service

    Comment


      #3
      Thank you Emily for Answer.

      I wrote about debugging and problem with logic BOT here:
      Hello everybody I have Strategy with multi MA logic and SL and PT. SL and PT a can choose in the Settings but they have a static positions on the chart. I modified my strategy for SL and PT and now I can move SL and PT on the chart, so my SL and PT are free to move. I used OnOrderUpdate and OnExecutionUpdate. Now I have


      but I don't see answers on my questions which I wrote in last three posts... I waiting on answers 3 days..​

      Comment


        #4
        Hello vitaly_p,

        Thank you for your reply.

        I sincerely appreciate your patience and apologize for any inconvenience based on the delay in getting a response to you. Here is what I see from your posts in that thread:

        My BOT working with Historical trades and I see at start (with start condition "wait until flat") when BOT have virtual position and this position is closing and BOT going to Real Time - it open just one position on canle (like earlier). BUT ALL next trades after that working well.
        In current situation I don't have positions which need to move vrom virtual to realtime, therefore I don't understand why first trade ignore conditions.​​
        With the start behavior "Wait until flat" the strategy will calculate the virtual position of the strategy. In this case, it sounds like the strategy has an open position when it is first enabled, then the strategy will wait until that virtual position is flat before submitting any orders to the account the strategy is running on. You mention the first trade is ignoring conditions - what conditions are required for the first trade? Are you seeing that the strategy is in an open position at this time or is it flat? You may review the Strategies tab of the Control Center to see the strategy position, account position, and whether these positions are in sync (True/False). For more information on syncing account positions:


        I tried to run BOT with start parameter "Immediately enter", it open positions correctly, but if need to open on one candle 8 positions from 8 signals - it place SL and PT only for 6 positions.. After second crossover BOT working well and place correct quantity of SL and PT.
        (I know about transfer virtual position to Real Time and use State.RealTime for it)
        So, I have a problem only with first trade after start BOT.
        What is the BOT must be checking when virtual position going to real position? for start states "immediately enter" and for "wait until flat"?​​
        In this case, I suggest setting TraceOrders to True in State.SetDefaults. This will offer additional information in the NinjaScript Output window in addition to your prints to understand what orders are submitted or ignored and why. For more information regarding TraceOrders:



        You may also review the link I shared in response to your previous question that explains the differences between immediately submit and wait until flat. For more details on transition order references from historical to live, please see the Advanced Order Handling > Transition order references from historical to live here:


        I tested my BOT with Market Replay and it put correct quantity of SL and PT (without first trade) BUT when I tried to run it on real data - it put wrong quantity SL and PT if have more one conditions on one candle...
        So I have second question: why code is working correctly on Market replay and working with errors on real data?​
        For this question, please see my response above in post number 2 of this thread.

        I look forward to assisting you further.
        Emily C.NinjaTrader Customer Service

        Comment


          #5
          Thank you Emily for ALL answers!

          My BOT working with multi MA's and have a reversal logic. When I start it with parameter "wait until flat" - I see virtual position, but when BOT see first reverse crossover - it close virtual position and open real position. Sometimes it will be more one crossovers, therefore BOT open more one position and must be place SL and PT for each position separately. For each crossover BOT create own order with unique name. Earlier I used one universal condition in OnOrderUpdate and Tracing show that all orers are opening, but SL and PT placed only for last order. Chris sent me example with 2 different signals on one candle.I saw that he use different parts in OnOrderUpdate for each type of orders, therefore I changed my logic and created different conditions in OnOrderUpdate for each Name of orders (for each condition separately). And just one condition in OnExecutionUpdate (with checking of all possible orders) for creating SL and PT. I checked it on Market replay on Saturday and code was working well (I don't talk about first trade now) but when I run this code on realtime - I see my previous problem...

          I everytime use Prints and Tracing orders.

          Comment


            #6
            Hello vitaly_p,

            Thank you for your reply.

            Are you using the Managed Approach or Unmanaged Approach in your strategy? What order methods are you using for your entries with separate names and your Stop Loss and Profit Target orders?

            You mentioned, "And just one condition in OnExecutionUpdate (with checking of all possible orders) for creating SL and PT" which I suspect is the cause of what you are reporting. You will likely need to create separate Stop Loss and Profit Target orders that are tied to the signalName of your separate entry orders (using fromEntrySignal) to resolve this. The answer to my previous questions should help to clarify so I can offer some suggestions for you to further debug your script and resolve your inquiry.

            I look forward to your reply.
            Emily C.NinjaTrader Customer Service

            Comment


              #7
              Hello Emily
              I use orders ExitShortStopMarket, ExitShortLimit , ExitLongStopMarket, ExitLongLimit.
              I saw that one of my variables, which add number of signal to Order Name changing very fast (in th OnBarUpdate) and when order is Filled - this variable is dofferent that number of order, therefore I created new variable which gives number of signal into OnOrderUpdate (for each signag separetely) and pass this variable to OnexecutionUpgrade. And it helped me!
              Thank you very much for your answers and your comments. Your information gave me ideas what else I can try.

              Thank you! And Have a nice weekend!​

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by CortexZenUSA, Today, 12:53 AM
              0 responses
              1 view
              0 likes
              Last Post CortexZenUSA  
              Started by CortexZenUSA, Today, 12:46 AM
              0 responses
              1 view
              0 likes
              Last Post CortexZenUSA  
              Started by usazencortex, Today, 12:43 AM
              0 responses
              5 views
              0 likes
              Last Post usazencortex  
              Started by sidlercom80, 10-28-2023, 08:49 AM
              168 responses
              2,265 views
              0 likes
              Last Post sidlercom80  
              Started by Barry Milan, Yesterday, 10:35 PM
              3 responses
              11 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Working...
              X