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 Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        607 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        353 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        105 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        560 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        561 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X