Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

how to receive the current(!) price from within OnExecution?

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

    how to receive the current(!) price from within OnExecution?

    Hi Ninjas,
    perhaps an easy question:
    I want to set a Stop Order (i.e. with ExitLongStop) within an OnExecution Event.
    This Stop Order should based on the current (the "active") price of the instrument - I am shure this could not the Close[0] of the current Bar - because the Current bar is still generated...
    How could I receive this price?

    Regards
    Trendseek
    Last edited by Trendseek; 10-06-2011, 11:55 AM.

    #2
    Hi Trendseek,

    The last traded price is Close[0] when CalculateOnBarClose = false.

    OnExecution is the event raised during a fill, but you can access bar objects or other variables within this handler provided they are declared in proper scope. Declare variables in the variables region to have them available anywhere in the script.

    You could also work with OnMarketData() to get the last price and assign a variable to it from there.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Hello Ryan,
      thanks for your rapid and helpfull reply!
      I will do a closer Look to that OnMarketData Stuff...

      [EDIT: Solve...] This works - BUT only with realTimeData!

      #region Variables
      private double _lastPrice;
      #endregion
      ...
      use the _lastPrice in other Events...
      ...

      protected override void OnMarketData(MarketDataEventArgs e)
      {
      if (e.MarketDataType == MarketDataType.Last) _lastPrice = e.Price;
      }


      _lastPrice is only visible in OnMarketData.
      Outside (i.e. OnBarUpdate) _lastPrice is always 0 on Historical Data - but works on RealTimeData

      Nice :-)

      Regards
      Trendseeker
      Last edited by Trendseek; 10-07-2011, 05:49 AM.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      649 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      370 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      109 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      574 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      576 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X