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

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 fx.practic, 10-15-2013, 12:53 AM
        5 responses
        5,406 views
        0 likes
        Last Post Bidder
        by Bidder
         
        Started by Shai Samuel, 07-02-2022, 02:46 PM
        4 responses
        98 views
        0 likes
        Last Post Bidder
        by Bidder
         
        Started by DJ888, Yesterday, 10:57 PM
        0 responses
        8 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by MacDad, 02-25-2024, 11:48 PM
        7 responses
        160 views
        0 likes
        Last Post loganjarosz123  
        Started by Belfortbucks, Yesterday, 09:29 PM
        0 responses
        9 views
        0 likes
        Last Post Belfortbucks  
        Working...
        X