Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using Strategy Methods for Indicator

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

    Using Strategy Methods for Indicator

    Hello,

    is there any chance to use methods for strategies, like GetProfitLoss(), for indicator code?
    What I'm trying to-do, is to evaluate the open loss for the instrument and close all trades if its above an user-defined level. Any chance?
    Or would it be possible to run a strategy in parallel for an instrument and monitoring the trades, opened from the ChartTrader?

    Thanks ahead!

    #2
    Hello BearingHH,

    Thank you for your post.

    This would require unsupported code as the strategy methods are not intended to pull the orders and executions outside their own run and the indicators cannot pull the strategy methods.

    Below is an example of pulling the account positions with unsupported code:
    Code:
    foreach (Account acct in Cbi.Globals.Accounts)
    {
    if (acct.Positions != null)
    {
    PositionCollection positions = acct.Positions;
    foreach (Position pos in positions)
    {
    Print(pos.Account.Name + " " + pos.Instrument + " " + pos.MarketPosition + " " + pos.Quantity + " " + pos.AvgPrice);
    }
    }

    Comment


      #3
      Thank you very much - helped a lot and make my trades a lot safer, when the ATM stop fails!

      Do you know, why I get round about 250 OnBarUpdate()'s instantly when I reload the NinjaScript (F5)? Even the data from these 250 calls for GetProfitLoss() are totally weird.
      After them, everything works as expected. I could ignore the instant OnBarUpdates()'s, but would be nice to know, why I get them.

      Ohh, one minute later it comes to my mind, that these are all the prior bars on my chart from the data series. How could I check that the initial bar history is over from OnBarUpdate() and I work with the actual "real-time" bar?

      Thanks!
      Last edited by BearingHH; 02-12-2016, 07:45 AM.

      Comment


        #4
        Hello BearingHH,

        At the beginning of OnBarUpdate() place the following:
        Code:
        if (Historical) return;
        For information on Historical please visit the following link: http://ninjatrader.com/support/helpG...historical.htm

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        81 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        43 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        64 views
        2 likes
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        68 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        56 views
        0 likes
        Last Post CarlTrading  
        Working...
        X