Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Access a strategy within a strategy

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

    Access a strategy within a strategy

    Hi guys,

    I am wondering if its possible to access a strategy within a strategy.

    If yes, how could I call a strategy (e.i. SampleMovingAverage.cs) from a new strategy?

    #2
    Hello sburtt,

    There would not be a supported way to call one strategy inside of another strategy as they are meant to be separate instances of each other. You would only be able to call an Indicators within a Strategy, or if there are values that you would like to access you may want to write them to a file and them read them into another strategy.

    Here is a sample that goes over how ot read/write to a text that you can implement the same logic into a strategy if you need some variables in another Strategy.


    Happy to be of further assistance.
    JCNinjaTrader Customer Service

    Comment


      #3
      JC I am trying to embed a feature that allows me to takes trades only if my equity curve is above it's 20 day moving average. Conceptually it's simple, I create a new DataSeries that will store values for cumulativeProfit = Performance.AllTrades.TradesPerformance.Currency.C umProfit, after that I set a bool that switches on/off my strategy in this way: trade condition = cumulativeProfit[0] > SMA(cumulativeProfit, equityCurvePeriod)[0] ? true : false;

      However I have a problem, how can I continue to store values of the equity curve even for trades I don't take? Do you have any suggestion?

      Comment


        #4
        Or maybe I could you the streamWriter and then run 2 strategies in parallel, one that takes all trades on a demo account and a live account that trades with a switch that is ruled by the txt file generated by the streamWriter on the demo account, but I would always be delayed on the last bar (as onbarupdate they execute simultaneously) is that correct?

        Comment


          #5
          Hello sburtt,

          Yes, you can use the StreamWrite to write the values to a text file and read them in from your other strategy maybe the best way to accomplish this.

          They will execute almost simultaneously yes, but there is going to be no guarantee which of the two strategies are going to be called first so you may want to use CalcualteOnBarClose (COBC) false in your live account strategy but separate out the logic that you only want to do once at the end of the bar.


          Let us know if that works for you.
          JCNinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_JC View Post
            Hello sburtt,

            Yes, you can use the StreamWrite to write the values to a text file and read them in from your other strategy maybe the best way to accomplish this.

            They will execute almost simultaneously yes, but there is going to be no guarantee which of the two strategies are going to be called first so you may want to use CalcualteOnBarClose (COBC) false in your live account strategy but separate out the logic that you only want to do once at the end of the bar.


            Let us know if that works for you.
            JC, I am trying this out now, I tried adding this to my strategy code, to see what happens
            if(Performance.AllTrades.Count > 0 && BarsSinceExit() < 1)
            {
            string outputFile = Performance.AllTrades.TradesPerformance.Currency.C umProfit.ToString();
            File.AppendAllText("c:\\Users\\Admin\\Desktop\\tes t.txt",outputFile);
            }
            I was expecting this to generate an txt file when running the strategy in backtest but it doesn't and it actually messes up my strategy results, I am putting this code just at the start of OnBarUpdate(), would you know what i am doing wrong?

            Comment


              #7
              Hello sburtt,

              Do you see any messages inside of the Log tab of the Control Center or if you open up the Tools -> Output Window?
              JCNinjaTrader Customer Service

              Comment


                #8
                Originally posted by NinjaTrader_JC View Post
                Hello sburtt,

                Do you see any messages inside of the Log tab of the Control Center or if you open up the Tools -> Output Window?
                JC, I will go through proper testing this week end and revert, thanks for support so far

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                666 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                377 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                110 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                575 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                580 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X