Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Mark the levels of my entries targets and stops

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

    Mark the levels of my entries targets and stops

    When I enter a trade, Id like for there to be a line drawn that show my stop, entry point, and target. Chart trader does this but then the lines disappear when the trade is closed.
    I need this because I save every trade as an image for review later.

    Possible?
    Thanks.

    #2
    Yes, it's possible. I'm doing something like that.

    You'll need to get the active account using something like
    foreach (Account a in Account.All) in State.Configure
    and then check AccountStatus.Enabled and ConnectionStatus.Connected.

    To differentiate between a Sim account and live account, you can check Core.Globals.TradingOptions.IsGlobalSimulationMode and Provider.

    Next, subscribe to OnPositionUpdate and OnExecutionUpdate like this: _account.PositionUpdate += OnPositionUpdate ;

    Do the calculations in OnExecutionUpdate(object sender, ExecutionEventArgs e)
    and OnPositionUpdate(object sender, PositionEventArgs e).

    Finally, plot the calculated values in OnBarUpdate().

    Comment


      #3
      Hello Grantx,

      tradesmart would be correct, we do have this documented and have a complete sample of these concepts located at the following link:



      You can subscribe to account events from an Indicator as an example, this would allow you to Draw based on data you have received from the account. This would also allow you to access existing order information from the account collections.

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

      Comment


        #4
        Originally posted by tradesmart View Post
        Yes, it's possible. I'm doing something like that.

        You'll need to get the active account using something like
        foreach (Account a in Account.All) in State.Configure
        and then check AccountStatus.Enabled and ConnectionStatus.Connected.

        To differentiate between a Sim account and live account, you can check Core.Globals.TradingOptions.IsGlobalSimulationMode and Provider.

        Next, subscribe to OnPositionUpdate and OnExecutionUpdate like this: _account.PositionUpdate += OnPositionUpdate ;

        Do the calculations in OnExecutionUpdate(object sender, ExecutionEventArgs e)
        and OnPositionUpdate(object sender, PositionEventArgs e).

        Finally, plot the calculated values in OnBarUpdate().
        Excellent thank you!

        Comment


          #5
          Hi Tradesmart, How do I initiate this event so that it only triggers when I have entered a trade? Do I place it in the state.configure?

          if (State == State.SetDefaults)
          {}
          else if (State == State.Configure)
          {}

          Thanks

          Comment


            #6
            You subscribe to account updates when State.Configure, thus:
            Code:
            if (_account != null)
            {
               _account.PositionUpdate += OnPositionUpdate      ;[COLOR=Green]// subscribe to position updates[/COLOR]
               _account.ExecutionUpdate += OnExecutionUpdate ;[COLOR=Green]// subscribe to execution updates[/COLOR]
            }
            and unsubscribe when State.Terminated:
            Code:
            else if (State == State.Terminated)
            {
               if (_account != null)[COLOR=Green] // unsubscribe[/COLOR]
               {
                   _account.PositionUpdate -= OnPositionUpdate;
                  _account.ExecutionUpdate -= OnExecutionUpdate;
               }
            }
            Assign your class scope vars to be plotted in OnExecutionUpdate() and/or OnPositionUpdate(), for example:
            Code:
            private void OnPositionUpdate(object sender, PositionEventArgs e)
            {
                   _d_positionavgprice     = e.AveragePrice ;
                   _d_initialstopprice = 
                         e.MarketPosition == MarketPosition.Long [COLOR=Green]// round stop price down (looser)[/COLOR]
                               ? Instrument.MasterInstrument.RoundDownToTickSize(_d_positionavgprice - StopTicks * _d_ticksize )
                         :  e.MarketPosition == MarketPosition.Short [COLOR=Green]// round stop price up (looser)[/COLOR]
                               ? Instrument.MasterInstrument.RoundToTickSize(_d_positionavgprice + StopTicks * _d_ticksize ) 
                          : 0d ;[COLOR=Green]// Flat[/COLOR]
            }
            Then, plot 'em in OnBarUpdate()
            Code:
            protected override void OnBarUpdate()
            {
               if (_d_positionavgprice > 0) AvgPrice[0] = _d_positionavgprice;
               if (_d_initialstopprice > 0) StopPrice[0] = _d_initialstopprice ;
            }

            Comment


              #7
              Im stuck here. So far I have managed to get VS hooked into Ninja.
              Successfully get it to stop in debug mode at OnExecutionUpdate().
              Now what object do I need to instantiate so that I can retrieve the stop and target? And how do I get it once? I dont want it to activate again, or draw more lines on my chart if the stop level moves with the ATM.

              I haven't programmed for a few years and this is my first attempt back

              Comment


                #8
                Originally posted by Grantx View Post
                ...in debug mode at OnExecutionUpdate().
                Now what object do I need to instantiate so that I can retrieve the stop and target? And how do I get it once? I dont want it to activate again, or draw more lines on my chart if the stop level moves with the ATM. I haven't programmed for a few years and this is my first attempt back
                Come on in, the water's fine.
                I'm not doing anything with ATM stops/targets, so I can't help you with that. However, if you want to use OnExecutionUpdate(), here's an example of some things available there:
                Code:
                private void OnExecutionUpdate(object sender, ExecutionEventArgs e) [COLOR=Green]// fires before OnPositionUpdate[/COLOR]
                {
                    _b_exit = e.Execution.IsExit ;[COLOR=Green]// executing an exit[/COLOR]
                    if (OutputOn)
                       Print(string.Format("{0} {1} execution: {2}\t{3}\t@\t{4} Position size was: {5}",
                         (_b_exit ? "\tExit" : "Enter").ToString(),
                         e.Execution.MarketPosition,
                         e.Quantity, 
                         e.Execution.Instrument.MasterInstrument.Name, 
                         Bars.Instrument.MasterInstrument.FormatPrice(e.Price),
                          _i_positionsize)
                       );
                }

                Comment


                  #9
                  Would something like this retrieve the stoporder price?


                  Order stopOrder;


                  private void OnExecutionUpdate(object sender, ExecutionEventArgs e)
                  {
                  Double _sp = stopOrder.StopPrice
                  }

                  Comment


                    #10
                    Originally posted by Grantx View Post
                    Would something like this retrieve the stoporder price?
                    Order stopOrder;
                    private void OnExecutionUpdate(object sender, ExecutionEventArgs e)
                    {
                    Double _sp = stopOrder.StopPrice
                    }
                    Probably not, since placing a stop order is not an execution.


                    Take a look at OnOrderUpdate(); as I often say, When in doubt, try it out.


                    Also, the type for a price should be double not Double, since c# is case-sensitive.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Rapine Heihei, Today, 08:19 PM
                    1 response
                    6 views
                    0 likes
                    Last Post NinjaTrader_Manfred  
                    Started by Rapine Heihei, Today, 08:25 PM
                    0 responses
                    5 views
                    0 likes
                    Last Post Rapine Heihei  
                    Started by f.saeidi, Today, 08:01 PM
                    1 response
                    4 views
                    0 likes
                    Last Post NinjaTrader_Manfred  
                    Started by Rapine Heihei, Today, 07:51 PM
                    0 responses
                    6 views
                    0 likes
                    Last Post Rapine Heihei  
                    Started by frslvr, 04-11-2024, 07:26 AM
                    5 responses
                    98 views
                    1 like
                    Last Post caryc123  
                    Working...
                    X