Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Virtual Strategy instance from Main Strategy

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

    Virtual Strategy instance from Main Strategy

    Hello guys,

    Some context what I'm trying to do before the question. I want to run virtual strategy (can be Sim account or not existed account created in memory) which will produce virtual SystemPerformance which I can use in main Strategy which is running normally. I understand that I'm asking something advanced and it is fine with me if it will be something un-documented and can stop working with future releases.


    My question what would be the right way to do that? And what the minimum required properties I have to assign. I'm attaching simple code to better illustrate what I would like to have:


    PHP Code:
    
    namespace NinjaTrader.NinjaScript.Strategies
    {
        public class MainStrategy : Strategy
        {
            private SampleMACrossOver virtualStrategy;        
    
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Name = "MainStrategy";
                    Calculate = Calculate.OnBarClose;
                }
                else if (State == State.Configure)
                {
                    virtualStrategy = new SampleMACrossOver();
                }
            }
    
            protected override void OnBarUpdate()
            {    
                virtualStrategy.Update(CurrentBar, BarsInProgress);
                Print(virtualStrategy.SystemPerformance.AllTrades.TradesCount);
            }
        }
    } 
    

    Looking forward for your advice.
    Last edited by login_dejavu; 12-30-2019, 06:22 AM.

    #2
    Hello login_dejavu,

    There would be nothing I could suggest for the code you have shown. The properties that are being set for the instance are not known from a NinjaScript perspective so it would not be possible to directly replicate how the platform constructs the strategy instance. We couldn't say for sure that it was setup and started correctly as there is no existing means to manage strategies from code. You could try experimenting with what you provided however I have no suggestions on how to go about doing that.

    From a strategy really all you could do would be to either place orders or not so to simulate orders to be used later with an actual strategy would likely require you to implement logic to calculate or simulate the trades yourself. One option may be to make a custom trade collection and populate it with custom built trade objects. This is not documented but is likely a better starting point than trying to construct a whole strategy instance by code: https://ninjatrader.com/support/foru...797#post838797
    Rather than placing trades you could use data and construct a performance set of that data, that may be one route toward extra calculations/strategies to be simulated in the current strategy.

    I look forward to being of further assistance.

    Comment


      #3
      Hello, Jesse, and thanks for you response,

      yes, this is more or less what I have (I mean TradeCollection), but I was thinking if I could encapsulate Strategy logic but at same time to re-use it in virtual parallel execution.

      Thanks anyway and have a nice day!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Today, 05:17 AM
      0 responses
      49 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      126 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      67 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      42 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      46 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X