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

OnExecution NT8

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

    OnExecution NT8

    Hello,

    I´m having issues again with onExecution. As I had in NT7 I plot the entryprice and calculated targets in the chart (instead of output window) to see if its OK. I have - referring to the NT-sample "OnOrderUpdate" in Onexecution:

    protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
    {
    if (entryOrderS1a != null && entryOrderS1a == execution.Order)
    {
    if (execution.Order.OrderState == OrderState.Filled)
    {avgFillSa=execution.Order.AverageFillPrice;
    target1short=avgFillSa-ts1*TickSize;
    target2short=avgFillSa-ts2*TickSize;}
    }

    but when entry is triggered the avgFillSa, target1short and target2short are always "0".

    Thank you!
    Tony

    #2
    Hello tonynt,

    Are you certain this logic is being called? I don't see that you are checking within this condition if you are actually reaching this point in the logic. Have you tried using a Print to make sure this variable is being set? I also cannot see how you are trying to display the data, that could also be part of the problem.

    I would suggest trying a print first and make sure this is being run:

    Code:
    {
    if (entryOrderS1a != null && entryOrderS1a == execution.Order)
    {
    if (execution.Order.OrderState == OrderState.Filled)
    {
    [B]    Print("Inside my condition");
     Print(execution.Order.ToString());[/B]
    avgFillSa=execution.Order.AverageFillPrice;
    target1short=avgFillSa-ts1*TickSize;
    target2short=avgFillSa-ts2*TickSize;}
    }
    After this is run, it should output the executions order as a print so we can see the values of that order. If this print does not happen, that would highlight the problem or that the logic was not executed.


    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hello Jesse,

      thank you for your reply. What I do not understand is how it can be that when entries are triggered that it is not shown from OnExecution.
      Just for additional info: I made a workaround by adding a fast dataseries and have in in onbarupdate now, this is also working, why isnt it in onexecution?

      Please see attached the output.txt.

      Thank you!
      Tony
      Attached Files

      Comment


        #4
        Hello Jesse,

        additional question please: I moved the window with the browser and out thread ot another screen and all NinjaTrader Chartwindows are gone and do only appear in the taskbar below and one needs to catch every chart seperately.
        Even when this is a windows question I hope you have a reply to this because when trading with NinjaTrader on computers with windows this might be a big problem when trading live.

        Thank you!
        Tony

        Comment


          #5
          Hello tonynt,

          It looks like with the print we can see the values are there, so the problem is likely somewhere else in your logic. The Execution was seen and printed out, there is also an average price:

          orderId='b050fcb29b23416d84c99ee2becaab11' account='Sim101' name='S1a' orderState=Filled instrument='MNQ 09-19' orderAction=SellShort orderType='Limit' limitPrice=7767.25 stopPrice=0 quantity=1 tif=Gtc oco='' filled=1 averageFillPrice=7767.25

          What I do not understand is how it can be that when entries are triggered that it is not shown from OnExecution.
          I am not sure what you mean by this, the entry was triggered and this code was OnExecution specific so that would confirm OnExecution worked. Did you use the print I provided or did you test something other than what I had suggested?
          Code:
           Print(execution.Order.ToString());



          I made a workaround by adding a fast dataseries and have in in onbarupdate now, this is also working, why isnt it in onexecution?
          This does not seem to relate to your last question. If you don't provide the new code, I would have no idea what you made to answer this. If you are going to ask a new question, please provide the full details for that question. Before moving on to other questions, we should stay on track and try to solve the first question you asked.


          I moved the window with the browser and out thread ot another screen and all NinjaTrader Chartwindows are gone and do only appear in the taskbar below and one needs to catch every chart seperately.
          I would not be certain what happened there. Potentially you used one of the windows actions to hide all windows? For this type of question, I would suggest reviewing some general window use tutorials or search for what you have described on google to find similar results. If you are referring to shaking a window, that is a default windows action to hide all windows besides what is being shook.

          Please let me know if I may be of further assistance.




          JesseNinjaTrader Customer Service

          Comment


            #6
            Hello Jesse,

            thank you for your reply. You see the code I have in onexecution. The only other code with the entryorders is

            entryOrderS1a=EnterShortLimit(....) // which is triggered correctly

            and in OnStateChange
            else if (State == State.Realtime)
            {

            if (entryOrderS1a != null)
            entryOrderS1a = GetRealtimeOrder(entryOrderS1a);
            if (entryOrderS1b != null)
            entryOrderS1b = GetRealtimeOrder(entryOrderS1b);
            if (entryOrderL1a != null)
            entryOrderL1a = GetRealtimeOrder(entryOrderL1a);
            if (entryOrderL1b != null)
            entryOrderL1b = GetRealtimeOrder(entryOrderL1b);
            } // that is from a sample and I have no idea what this is for.

            I did the print you provided.

            Beside this I only wanted to inform you that in another script I have
            avgFillSa=execution.Order.AverageFillPrice; target1short=avgFillSa-ts1*TickSize; target2short=avgFillSa-ts2*TickSize;
            in onbarupdate and I get the values correctly. But it should work in onexecution in this script as well.

            Thank you!
            Tony

            Comment


              #7
              Hello tonynt,

              I am having trouble following what you are asking here. The code you mentioned in OnExecution seems to be working based on the test I had you do. What are you asking about surrounding that code?

              but when entry is triggered the avgFillSa, target1short and target2short are always "0".
              You did not provide any information about where this is 0. Where are you outputting this value to know its 0?

              it is not 0 in OnExecution, your print has just confirmed that the AverageFillPrice is populated:

              averageFillPrice=7767.25



              Please see attached the output.txt.
              The print shows OnExecution is working and the order has an average fill price.

              It seems OnExecution is working as expected, so now I would need to know what part of your script is not working. How are you checking the values you are asking about, and from what part of the script? I would need to see a specific example of the code which you are asking about to be of further assistance.



              GetRealtimeOrder is an order concept, but this would not be related to your original question. You can read more on this topic and what this method is used for in the help guide.


              Beside this I only wanted to inform you that in another script I have...
              If the other script works, you could compare and see what is different in the code. You can also do a Save As and start from that point if you are not sure what the problem is.

              Please let me know if I may be of further assistance.
              JesseNinjaTrader Customer Service

              Comment


                #8
                Hello Jesse,

                thank you for your reply. I do with "Save As" and step by step modifying scripts.

                I try to answer your questions: you see my code in OnExecution(#2). But even when you write OnExecution is working those variables are 0 when entry is triggered.

                I see this because in my charts I have drawtext, this I use for years to code and debug, there I have what I want and not so much text as in output window, and I see it directly with the price and time and close to the bars

                string str1 = string.Empty;
                str1+="\r\navgFillSa: " + avgFillSa;
                str1+="\r\navgFillLa: " + avgFillLa;
                str1+="\r\ntarget1short= " + target1short;
                str1+="\r\ntarget2short= " + target2short;
                str1+="\r\ntarget1long= " + target1long;
                str1+="\r\ntarget2long= " + target2long;
                Draw.TextFixed(...)

                And as I wrote: same script ("Save As") but I moved the lines (post#2) from onexecution to onbarupdate and there it works. You have all informations from this. Why doesnt it assign the values to the variables in onexecution?

                Thank you!
                Tony

                Comment


                  #9
                  Hello tonynt,

                  I try to answer your questions: you see my code in OnExecution(#2). But even when you write OnExecution is working those variables are 0 when entry is triggered.
                  You provided a print showing the opposite of what you are saying.

                  averageFillPrice=7767.25

                  The print confirms the value is there. What makes you think the value is 0? Please provide an accurate example of the script including the Print confirming the value is 0.


                  I see this because in my charts I have drawtext, this I use for years to code and debug, there I have what I want and not so much text as in output window, and I see it directly with the price and time and close to the bars
                  I am not sure what you mean by this. You have included a lot of details here, but I cant make out what you are trying to explain with this statement. Are you seeing a Draw.text work and the print does not work? Can you simplify this further? For example "The draw text works, the print does not work".



                  And as I wrote: same script ("Save As") but I moved the lines (post#2) from onexecution to onbarupdate and there it works
                  It seems that you made a change and that is likely the problem. If you moved code which has a specific requirement in OnExecutionUpdate into an arbitrary location (OnBarUpdate) it may not work the same.

                  Please let me know if I may be of further assistance.


                  JesseNinjaTrader Customer Service

                  Comment


                    #10
                    Hello Jesse,

                    I dont know how to explain in words anymore. I attach a code with the code in OnExecution we posted above, its a code reduced to the minimum to show what I mean. In the output windows it shows the entryprice but this is not assigned to the variables as you can see in the drawing in the chart on lower left corner.

                    Thank you!
                    Tony
                    Attached Files

                    Comment


                      #11
                      Hello tonynt,

                      Thank you for providing that, I can clearly see the problem now.

                      You moved the print to OnBarUpdate, so it will be 0 for a period of time before an execution happens. You also introduced a problem in your logic which makes this always 0:

                      Code:
                      if (Position.MarketPosition != MarketPosition.Short)
                       {
                      
                           avgFillSa=0;
                           target1short=0;
                           target2short=0;
                      Each time you enter short, OnExecution is called and updates the variable, but you set it back to 0 before the print happens. Your script only enters short so it should never be anything other than 0.

                      If you are expecting to see this drawing or print, you would need to move it into OnExecution within the condition, or move it before the point in your logic where you set the variables to 0.

                      Please let me know if I may be of further assistance.
                      JesseNinjaTrader Customer Service

                      Comment


                        #12
                        Hello,

                        I gave it another try and the scripts do not work with playback. So I switch to demo, change to Default 24/7 because its weekend, run the scripts and all is perfect. My doubles show the assigned values from onexecution and are not 0. OK, so I go again to playback and the doubles are 0 and do not update from onexecution.
                        Now I see in logtab the following message that appears with every entry, but I have no idea what this means

                        Time Category Message
                        13.08.2023 12:56:12 DB Error on executing DB command: code = Constraint (19), message = System.Data.SQLite.SQLiteException (0x800027AF): constraint failed FOREIGN KEY constraint failed at System.Data.SQLite.SQLite3.Reset(SQLiteStatement stmt) at System.Data.SQLite.SQLite3.Step(SQLiteStatement stmt) at System.Data.SQLite.SQLiteDataReader.NextResult() at System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCo mmand cmd, CommandBehavior behave) at System.Data.SQLite.SQLiteCommand.ExecuteReader(Com mandBehavior behavior) at System.Data.SQLite.SQLiteCommand.ExecuteNonQuery(C ommandBehavior behavior) at NinjaTrader.NinjaScript.StrategyBase.DbAdd() at NinjaTrader.Cbi.DB.DBThread()


                        Thank you!
                        Tony

                        Comment


                          #13
                          Hello tonynt,

                          If you are seeing database errors that generally means you didn't apply the strategy after connecting to playback. You can't enable strategies that are already in the control center after connecting to playback, you need to apply a fresh instance of the strategy and select the playback account.
                          JesseNinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by gentlebenthebear, Today, 01:30 AM
                          1 response
                          8 views
                          0 likes
                          Last Post NinjaTrader_Jesse  
                          Started by Aviram Y, Today, 05:29 AM
                          1 response
                          7 views
                          0 likes
                          Last Post NinjaTrader_ChelseaB  
                          Started by cls71, Today, 04:45 AM
                          1 response
                          7 views
                          0 likes
                          Last Post NinjaTrader_ChelseaB  
                          Started by TradeForge, Today, 02:09 AM
                          1 response
                          22 views
                          0 likes
                          Last Post NinjaTrader_ChelseaB  
                          Started by elirion, Today, 01:36 AM
                          2 responses
                          14 views
                          0 likes
                          Last Post elirion
                          by elirion
                           
                          Working...
                          X