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

AFTERRender event

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

    AFTERRender event

    Hi all,

    I'm taking a screenshot after an order is proceed and calling ForceRefresh();
    Then I'm watching OnRender event. This is also been touched but unfortunetely my screenshot is still to early.
    Think I need a way to create my screenshot ATERRender event.
    Is there any posibility?

    Thanks in advance.

    #2
    Hi Airwave, thanks for posting.

    You could set a boolean variable to false before the order is submitted, wait for OnRender to pass once and set it to true in OnRender then once that becomes true take the screenshot. You could also take the screenshot on the next bar where the Order object is State.Accepted or Working then take the screenshot on the next bar. If none of these ideas resolve, I will need to see a reduced test script from you to see the issue.

    Kind regards,
    -ChrisL
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChrisL View Post
      You could set a boolean variable to false before the order is submitted, wait for OnRender to pass once and set it to true in OnRender then once that becomes true take the screenshot. You could also take the screenshot

      Hello,

      thats exactly how I do it.
      Seems to be as if the Variable in OnRender is set a bit to early. Thats why I asked for "After"OnRender.

      Or what do you mean with "wait for Render to pass once". Maybe I should wait for second OnRender run through and not already the my variable to true in the first run through?

      Thanks in advance.
      Last edited by Airwave; 07-27-2021, 09:35 AM.

      Comment


        #4
        Hi Airwave, thanks for your reply.

        You should monitor the order in OnOrderUpdate if you are not already. The order should be rendered to the chart once the order has reached State.Accepted or State.Working. If you are already doing this, please share a reduced code example so I can test on my end.

        Kind regards,
        -ChrisL
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Hi Chris,

          Thank you for your answer.
          I'm trying to change a bit of my code.

          Here I came to a new question:

          You wrote: "You should monitor the order in OnOrderUpdate if you are not already. "

          Can you tell me how I can identify and track the same order in OnOrderUpdate from each time OnOrderUpdate is called. Tryed the the OrderI, but this is changeing?

          Thanks in advance.

          Airwave

          Comment


            #6
            Hello Airwave,

            I have attached an example that takes a screenshot from OnRender after we signal that an order is accepted/working from OnOrderUpdate when it would be present on the chart. This is set up for an indicator but you may override OnOrderUpdate for strategy level order update events.

            OnOrderUpdate - https://ninjatrader.com/support/help...rderupdate.htm

            Please let us know if you have issues testing this script or taking this approach.
            Attached Files
            JimNinjaTrader Customer Service

            Comment


              #7
              Hu Jim,

              thank you. Problem was I used:
              protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string comment)
              {
              }

              With the account.OrderUpdate it's working perfectly.


              Unfortunetely following is always "null":
              // Find our Sim101 account
              lock (Account.All)
              account = Account.All.FirstOrDefault(a => a.Name == AccountName);

              I have the chance to select this manually in the properties but would like to fill this by default also with SIM101.

              Any suggestions?

              Thanks

              Comment


                #8
                Hi AirWave,

                The Account documentation page has an example on initializing the account as the Sim101:


                Or use the Account selector property to initialize the Account object in State.Configure:
                [TypeConverter(typeof(NinjaTrader.NinjaScript.Accou ntNameConverter))]
                public string AccountName { get; set; }

                Kind regards,
                -ChrisL
                Chris L.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_ChrisL View Post
                  Or use the Account selector property to initialize the Account object in State.Configure:
                  [TypeConverter(typeof(NinjaTrader.NinjaScript.Accou ntNameConverter))]
                  public string AccountName { get; set; }

                  Thats exactly I've added on top of the class
                  public class mystrategy: Strategy
                  {
                  [TypeConverter(typeof(NinjaTrader.NinjaScript.Accou ntNameConverter))]
                  public string AccountName { get; set; }
                  .
                  .
                  .
                  .

                  But in StateConfigure it's still always null:

                  if (State == State.Configure)
                  {

                  // Find our Sim101 account
                  lock (Account.All)
                  account = Account.All.FirstOrDefault(a => a.Name == AccountName);


                  Any suggestions? Thanks in advance.

                  Comment


                    #10
                    Hi Airwave, thanks for your reply.

                    That can be fixed by checking objects for null:

                    Code:
                    else if (State == State.Configure)
                    {
                    if(AccountName != null)
                    {
                    lock (Account.All)
                    myAccount = Account.All.FirstOrDefault(a => a.Name == AccountName);
                    }
                    
                    if (myAccount != null)
                    {
                    myAccount.ExecutionUpdate += OnExecutionUpdate;
                    }
                    }
                    else if (State == State.Terminated)
                    {
                    if (myAccount != null)
                    myAccount.ExecutionUpdate -= OnExecutionUpdate;
                    }
                    Chris L.NinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by NinjaTrader_ChrisL View Post
                      That can be fixed by checking objects for null:
                      Hi Chris,

                      sorry the question was a bit different. My issues answer was just was to define
                      AccountName = "Sim101";
                      in SetDefaults
                      :-)

                      Thanks

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by RookieTrader, Today, 09:37 AM
                      2 responses
                      10 views
                      0 likes
                      Last Post RookieTrader  
                      Started by alifarahani, Today, 09:40 AM
                      1 response
                      6 views
                      0 likes
                      Last Post NinjaTrader_Jesse  
                      Started by Gerik, Today, 09:40 AM
                      1 response
                      6 views
                      0 likes
                      Last Post NinjaTrader_Gaby  
                      Started by KennyK, 05-29-2017, 02:02 AM
                      3 responses
                      1,285 views
                      0 likes
                      Last Post NinjaTrader_Clayton  
                      Started by AttiM, 02-14-2024, 05:20 PM
                      11 responses
                      186 views
                      0 likes
                      Last Post NinjaTrader_ChelseaB  
                      Working...
                      X