Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How can I get variable into my strategie from second strategie ?

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

    How can I get variable into my strategie from second strategie ?

    Hi,

    I have two strategies (strategie01 and strategie02).

    How can I read with strategie02 any variables from strategie01 ?

    e.g. strategie02

    if (myVariableFromStrategie01 == 1)
    { (do....
    }


    Torso

    #2
    Hello Torso,
    Thanks for writing in and I am happy to assist you.

    Unfortunately this is beyond what we could support but you can communicate between 2 strategies using advanced C# methods.

    However you can refer to this thread for reference http://www.ninjatrader.com/support/f...ad.php?t=10140

    I leave this thread open for any of our community member who can assist you in this regard.

    Please let me know if I can assist you any further.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Originally posted by Torso View Post
      Hi,

      I have two strategies (strategie01 and strategie02).

      How can I read with strategie02 any variables from strategie01 ?

      e.g. strategie02

      if (myVariableFromStrategie01 == 1)
      { (do....
      }


      Torso
      Expose the variable as public, by defining its properties. A public variable can be accessed by other classes/indicators/strategies, if necessary by using the fully qualified path name. Many times, even that is not necessary, and you can simply call the variable directly from the class.

      Comment


        #4
        Thanks Joydeep, thanks Koganam,

        I realize it's a hard nut to crack for me as a c# rookie. I tried to use the thread 4991, but I get a lot of mistakes.

        First question is, can I storing and retrieving a value between 2 strategies? In thread 4991 is an example between indicator and strategie. But I can't adjust it. Second, how can I print the BoolSerie?

        To understand it, I have two strategies written, I would be happy if someone shows the error. Or improves the code


        namespace NinjaTrader.Strategy
        {
        public class TestSetVariable : Strategy
        {
        #region Variables
        private BoolSeries tradeONOFF;
        #endregion

        protected override void Initialize()
        {
        SetStopLoss("", CalculationMode.Ticks, 10, false);
        SetProfitTarget("", CalculationMode.Ticks, 20);
        CalculateOnBarClose = true;
        tradeONOFF = new BoolSeries(this);
        }

        protected override void OnBarUpdate()
        {
        if (CrossAbove(EMA(10), EMA(20), 1) && Position.MarketPosition != MarketPosition.Flat)
        {
        EnterLong(DefaultQuantity, "");
        }

        if (Position.MarketPosition == MarketPosition.Flat)
        {
        tradeONOFF.Set(true);
        Print(/*HOW CAN I PRINT tradeONOFF ?????????????????????? */)
        }
        }

        #region Properties

        [Description("")]
        [GridCategory("Parameters")]
        public BoolSeries TradeONOFF
        {
        get { return tradeONOFF; }
        }
        #endregion
        }
        }




        namespace NinjaTrader.Strategy
        {
        public class TestUseVariable : Strategy
        {
        #region Variables
        #endregion

        protected override void Initialize()
        {
        CalculateOnBarClose = true;
        Add(TestSetVariable()); (/* ---------> get Error CS0118 */)

        }

        protected override void OnBarUpdate()
        {
        if (TestSetVariable().TradeONOFF[0])
        EnterShort();

        }

        #region Properties

        #endregion
        }
        }

        Comment


          #5
          Hello Torso,
          You cannot use the SampleBoolSeries as an example since it is an indicator and indicators are reference differently from strategies internally by NinjaTrader.

          I will still suggest you look at this thread for any hints http://www.ninjatrader.com/support/f...ad.php?t=10140

          Please let me know if I can assist you any further.
          JoydeepNinjaTrader Customer Service

          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