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

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(CurrentBarBarsInProgress);
                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.
    JesseNinjaTrader Customer Service

    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 geddyisodin, Today, 05:20 AM
      1 response
      11 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by Max238, Today, 01:28 AM
      3 responses
      30 views
      0 likes
      Last Post Max238
      by Max238
       
      Started by timko, Today, 06:45 AM
      2 responses
      12 views
      0 likes
      Last Post NinjaTrader_ChristopherJ  
      Started by habeebft, Today, 07:27 AM
      0 responses
      4 views
      0 likes
      Last Post habeebft  
      Started by Tim-c, Today, 03:54 AM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Working...
      X