Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Is there a way to enumerate through running strats?

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

    Is there a way to enumerate through running strats?

    Hi,
    I have several strats that I will be running simultaneously. In certain cases I don't want a particular strat to trade if another strat is in a position. Is there a way to do the following pseudo code?

    Code:
         foreach(strategy s in AllRunningStrategies)
         {
             if(s.IsInAPosition == true)
                DontTrade();
         }
    Any help would be greatly appreciated (read as: Worth 2 Snickers bars!)
    Thanks ... Ed.

    #2
    Hello,

    Thank you for the question.

    In general NinjaScript has no supported methods to allow for two strategies to communicate, this is largely because each strategy is treated like a bubble and only can see the information from inside its own bubble. I would not suggest trying this approach where a strategy relies on another external strategy as there is no specific way to keep these two instances in sync. This is especially important when trading the same instrument on the same account. This type of logic can lead to un wanted positions or un intentional trades being placed.

    The supported approach would instead be to use a single strategy file and then use the SampleMultiInstrument sample as a guideline on how to form the structure of the file. This would allow a single strategy to trade multiple instruments or the same on different time frames. The strategy would also be aware of all positions it creates so there is no need for cross script communication. You could look at other unsupported ways of doing this as well like writing data to file and reading data to file but I would not suggest any of these approaches and instead recommend the SampleMultiInstrument method. Mainly I would not suggest any of these approaches as you can not be certain the file will be able to be accessed when it needs to due to the other script may be accessing that file.

    You may be able to use an Addon for your own type of monitoring system as well, you could look into the Addon sample that demonstrates subscribing to the account: http://ninjatrader.com/support/forum...ad.php?t=84087
    I couldn't really suggest any means to communicate that information to strategies but in the case you wanted to use an addon to control or submit orders, you could.


    Please let me know if I may be of further assistance.
    Last edited by NinjaTrader_Jesse; 06-20-2016, 07:34 AM.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Interesting. Thanks for the thoughtful response.
      I guess I'm gonna have to go back to the drawing board.
      No snickers bar for you!
      Thanks again ... Ed

      Comment


        #4
        Originally posted by edstaffin View Post
        Hi,
        I have several strats that I will be running simultaneously. In certain cases I don't want a particular strat to trade if another strat is in a position. Is there a way to do the following pseudo code?

        Code:
             foreach(strategy s in AllRunningStrategies)
             {
                 if(s.IsInAPosition == true)
                    DontTrade();
             }
        Any help would be greatly appreciated (read as: Worth 2 Snickers bars!)
        Thanks ... Ed.
        Code:
        			if (Account.Strategies.Count > 0)
        				foreach (StrategyBase strat in Account.Strategies)
        					{
        						Print("Strategy Name: " + strat.Name);
        						Print("Position: " + strat.Position.MarketPosition.ToString());
        						Print("Quantity: " + strat.Position.Quantity.ToString());
        						Print("Price: " + strat.Position.AveragePrice.ToString());
        					}
        You must give my Snickers bars to at least one of your kids, and tell him why he/she gets a Snickers bar or two.

        Comment


          #5
          A 1000 thanks. I don't have any kids, but perhaps I can donate the Snicker's bars to your favorite charity???

          Comment


            #6
            Your response suggests that it's a bad thing to have inter-strat communication. However, it also makes the assumption that I am going against multiple instruments. In my case I have multiple strats going against the same instrument. As long as I am going against the same instrument, it would seem to me that using the lovely code provided by Koganam would fit my bill. Basically, I have one strat to handle long and one to handle short. Both going against the same instrument. So when using Koganam's code I would only be checking strats with like instruments. Doing things this way keeps me from having to use the unmanaged approach (simpler is better!). Am I missing something?
            Ed

            Comment


              #7
              Originally posted by edstaffin View Post
              ... Doing things this way keeps me from having to use the unmanaged approach (simpler is better!). Am I missing something?
              Ed
              You are not missing anything. That is the exact reason and scenario for which I came up with the (albeit) unsupported code.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by cmtjoancolmenero, Yesterday, 03:58 PM
              11 responses
              39 views
              0 likes
              Last Post cmtjoancolmenero  
              Started by FrazMann, Today, 11:21 AM
              0 responses
              3 views
              0 likes
              Last Post FrazMann  
              Started by geddyisodin, Yesterday, 05:20 AM
              8 responses
              52 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by DayTradingDEMON, Today, 09:28 AM
              4 responses
              26 views
              0 likes
              Last Post DayTradingDEMON  
              Started by George21, Today, 10:07 AM
              1 response
              22 views
              0 likes
              Last Post NinjaTrader_ChristopherJ  
              Working...
              X