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

Market replay becoming very slow

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

    Market replay becoming very slow

    Hi,

    I have an indicator that returns the values "Neutral ","Long", and "Short". Depending on these values I have a strategy that creates and discards ATM strategies. The code is given below. The problem is that the system is very very slow, I have a screencast link to that as well. Please help solve this issue.

    protected override void OnBarUpdate()
    {
    // Enters Long Position when the CDA AID is Long and when the existing position is Flat//

    if (CDA("Neutral", true, Color.Bisque, "Alert2.wav", 1, 14,0 , 2,0 , 14, 3, 0.7, 0.25, Color.Honeydew, "Alert1.wav", 1000000, 1).aid1[0].ToString() == "Long"
    && Position.MarketPosition == MarketPosition.Flat)
    {
    s = CDA("Neutral", true, Color.Bisque, "Alert2.wav", 1, 14,0 , 2,0 , 14, 3, 0.7, 0.25, Color.Honeydew, "Alert1.wav", 1000000, 1).Support[0];

    atmStrategyId = GetAtmStrategyUniqueId();
    orderId = GetAtmStrategyUniqueId();

    AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.Limit, s +(entryTicksOffset*TickSize) ,0,
    TimeInForce.Day,orderId, "MyTemplate",
    atmStrategyId);
    }
    // Enters Short Position when the CDA AID is Short and when the existing position is Flat//

    if (CDA("Neutral", true, Color.Bisque, "Alert2.wav", 1, 14,0 , 2,0 , 14, 3, 0.7, 0.25, Color.Honeydew, "Alert1.wav", 1000000, 1).aid1[0].ToString() == "Short"
    && Position.MarketPosition == MarketPosition.Flat)
    {
    r = CDA("Neutral", true, Color.Bisque, "Alert2.wav", 1, 14,0 , 2,0 , 14, 3, 0.7, 0.25, Color.Honeydew, "Alert1.wav", 1000000, 1).Resistance[0];

    atmStrategyId = GetAtmStrategyUniqueId();
    orderId = GetAtmStrategyUniqueId();

    AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.Limit, r -(entryTicksOffset*TickSize) ,0,
    TimeInForce.Day, orderId, "MyTemplate",
    atmStrategyId);

    }



    // Enters Long Position when the CDA AID is Long and when the existing position is Short//

    if (CDA("Neutral", true, Color.Bisque, "Alert2.wav", 1, 14,0 , 2,0 , 14, 3, 0.7, 0.25, Color.Honeydew, "Alert1.wav", 1000000, 1).aid1[0].ToString() == "Long"
    && Position.MarketPosition == MarketPosition.Short)
    {
    s = CDA("Neutral", true, Color.Bisque, "Alert2.wav", 1, 14,0 , 2,0 , 14, 3, 0.7, 0.25, Color.Honeydew, "Alert1.wav", 1000000, 1).Support[0];
    AtmStrategyClose(orderId);
    AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.Limit, s +(entryTicksOffset*TickSize) ,0,
    TimeInForce.Day, orderId, "MyTemplate",
    atmStrategyId);
    atmStrategyId = GetAtmStrategyUniqueId();
    orderId = GetAtmStrategyUniqueId();



    }

    // Enters Short Position when the CDA AID is Short and when the existing position is Long//

    if (CDA("Neutral", true, Color.Bisque, "Alert2.wav", 1, 14,0 , 2,0 , 14, 3, 0.7, 0.25, Color.Honeydew, "Alert1.wav", 1000000, 1).aid1[0].ToString() == "Short"
    && Position.MarketPosition == MarketPosition.Long)
    {
    r = CDA("Neutral", true, Color.Bisque, "Alert2.wav", 1, 14,0 , 2,0 , 14, 3, 0.7, 0.25, Color.Honeydew, "Alert1.wav", 1000000, 1).Resistance[0];
    AtmStrategyClose(orderId);
    AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.Limit, r -(entryTicksOffset*TickSize) ,0,
    TimeInForce.Day, orderId, "MyTemplate",
    atmStrategyId);
    atmStrategyId = GetAtmStrategyUniqueId();
    orderId = GetAtmStrategyUniqueId();

    }
    // Exits all positions//

    if (CDA("Neutral", true, Color.Bisque, "Alert2.wav", 1, 14,0 , 2,0 , 14, 3, 0.7, 0.25, Color.Honeydew, "Alert1.wav", 1000000, 1).aid1[0].ToString() == "Neutral"
    && Position.MarketPosition != MarketPosition.Flat)
    {
    AtmStrategyClose(orderId);
    }



    }

    Free online storage and sharing with Screencast.com. 2 GB of storage and 2 GB of bandwidth per month for free. We won't compress, alter or take ownership of your content.

    #2
    Hello VarunDivakar,

    Thank you for your post.

    What is slow in the video? Is it Market Replay that slows down or the strategy is not taking positions when it should and is taking them late?

    Can you describe what is occurring that you are not expecting?

    I look forward to your response.

    Comment


      #3
      Hi,

      The thing is I wrote an indicator that returns the values "long", " short" , and " neutral". For which the code is here below:
      if(Close[0] > pS && plotS == true && Close[0] >= pR)
      AID = "Long";

      if(Close[0] < pR && plotR == true && Close[0] <= pS)
      AID = "Short";

      if( Close[0]>= pS && Close[0] <=pR && plotS == true && plotR == true)
      AID = "Neutral";

      if( plotS != true && plotR != true)
      AID = "Neutral";

      if( AID == "Long")
      {
      CandleOutlineColor = Color.Black ;
      BarColor = Color.LightGreen;
      }


      else if(AID == "Short")
      {
      CandleOutlineColor = Color.Black;
      BarColor = Color.Red;

      }

      else
      {
      CandleOutlineColor = Color.Black;
      BarColor = Color.Gray;

      }





      }

      public string aid1
      {
      get
      {
      Update();
      return AID;
      }
      }


      I am trying to call this aid1 variable in another indicator. by using the follwoing code:


      if (CDAEx("Neutral", true, Color.Bisque, "Alert2.wav", 1, 14,0 , 2,0 , 14, 3, 0.7, 0.25, Color.Honeydew, "Alert1.wav", 1000000, 1).aid1[0].ToString() == "Long")
      BarColor = Color.Green;

      this part of the code is not executing(or rather the aid1 variable is not being fetched) and I think this is causing the slowdown.

      Can you tell me why the aid1 is not accessible to the other indicator.

      Comment


        #4
        Hello,

        Thank you for the question.

        It appears that the public property aid1 is of type string but you are trying to access it like a DataSeries with the [0] index.

        Have you tried not using an index to see if this solves the problem or:

        Code:
        if (CDAEx("Neutral", true, Color.Bisque, "Alert2.wav", 1, 14,0 , 2,0 , 14, 3, 0.7, 0.25, Color.Honeydew, "Alert1.wav", 1000000, 1).[B]aid1 [/B]== "Long")
        BarColor	= Color.Green;
        If you instead need historical or synced values like a Series, I would suggest using a StringSeries instead of a String. You can locate more information on these series here: http://ninjatrader.com/support/helpG...b=stringseries

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Still not working

          Hi Jesse,

          Thank you so much for your reply.
          I tried both the things you suggested but still it is not working.

          I cant figure out what is wrong. I am sending you everything including the properties of variables. may be i did something wrong there.

          #region Variables
          // Wizard generated variables
          private int periodATR = 1; // Default setting for PeriodATR
          private int stddevBB = 2; // Default setting for StddevBB
          private int periodBB = 14; // Default setting for PeriodBB
          private double ticksSR = .25; // Default setting for TicksSupport and Resistance
          private double pS = 0;// Default value for Support/ Represents the previous Support
          private double pR = 0;// Default value fro Resistance/ Represents the previous Resistance
          private bool plotS = false;
          private bool plotR = false;
          // CDMA user defined Variables
          int _VolumeMin = 1;
          int _VolumeMax = 1000000;
          double _T3_vFactor = 0.7;
          int _T3_tCount = 3;
          int _T3_period = 14;
          Color _UpColor = Color.Honeydew;
          Color _DownColor = Color.Bisque;
          bool _AlertOncePerBar = true;
          string _UpCrossSound = "Alert1.wav";
          string _DownCrossSound = "Alert2.wav";
          string AID ="Neutral";


          // User defined variables (add any user defined variables below)
          #endregion


          protected override void Initialize()
          {
          Add(new Plot(Color.DarkSeaGreen, PlotStyle.Hash, "Support"));
          Add(new Plot(Color.Black, PlotStyle.Hash, "Resistance"));
          Overlay = true;
          }

          protected override void OnBarUpdate()
          {
          // Use this method for calculating your indicator values. Assign a value to each
          // plot below by replacing 'Close[0]' with your own formula.
          //Plot0.Set(Close[0]);
          if ((ATR(CDMA(_AlertOncePerBar,GomCDCalculationModeTy pe.BidAsk,GomCDChartType.CumulativeChart,_DownColo r,_DownCrossSound,false,_T3_period,_T3_tCount,_T3_ vFactor,_UpColor,_UpCrossSound,_VolumeMax,_VolumeM in), periodATR)[0] > Bollinger(ATR(CDMA(_AlertOncePerBar,GomCDCalculati onModeType.BidAsk,GomCDChartType.CumulativeChart,_ DownColor,_DownCrossSound,false,_T3_period,_T3_tCo unt,_T3_vFactor,_UpColor,_UpCrossSound,_VolumeMax, _VolumeMin),periodATR), stddevBB, periodBB).Upper[0])
          &&(CDMA(_AlertOncePerBar,GomCDCalculationModeType. BidAsk,GomCDChartType.CumulativeChart,_DownColor,_ DownCrossSound,false,_T3_period,_T3_tCount,_T3_vFa ctor,_UpColor,_UpCrossSound,_VolumeMax,_VolumeMin) .DeltaClose[0] >CDMA(_AlertOncePerBar,GomCDCalculationModeType.Bi dAsk,GomCDChartType.CumulativeChart,_DownColor,_Do wnCrossSound,false,_T3_period,_T3_tCount,_T3_vFact or,_UpColor,_UpCrossSound,_VolumeMax,_VolumeMin).D eltaOpen[0] )
          )
          {
          pS = Low[1]-ticksSR ;
          plotS = true;

          }
          if(Close[0] > pS && plotS == true)
          Support.Set(pS);


          if ((ATR(CDMA(_AlertOncePerBar,GomCDCalculationModeTy pe.BidAsk,GomCDChartType.CumulativeChart,_DownColo r,_DownCrossSound,false,_T3_period,_T3_tCount,_T3_ vFactor,_UpColor,_UpCrossSound,_VolumeMax,_VolumeM in), periodATR)[0] > Bollinger(ATR(CDMA(_AlertOncePerBar,GomCDCalculati onModeType.BidAsk,GomCDChartType.CumulativeChart,_ DownColor,_DownCrossSound,false,_T3_period,_T3_tCo unt,_T3_vFactor,_UpColor,_UpCrossSound,_VolumeMax, _VolumeMin),periodATR), stddevBB, periodBB).Upper[0])
          &&(CDMA(_AlertOncePerBar,GomCDCalculationModeType. BidAsk,GomCDChartType.CumulativeChart,_DownColor,_ DownCrossSound,false,_T3_period,_T3_tCount,_T3_vFa ctor,_UpColor,_UpCrossSound,_VolumeMax,_VolumeMin) .DeltaClose[0]<CDMA(_AlertOncePerBar,GomCDCalculationModeType.Bi dAsk,GomCDChartType.CumulativeChart,_DownColor,_Do wnCrossSound,false,_T3_period,_T3_tCount,_T3_vFact or,_UpColor,_UpCrossSound,_VolumeMax,_VolumeMin).D eltaOpen[0])
          )

          {
          pR = High[1]+ticksSR ;
          plotR = true;

          }

          if(Close[0] < pR && plotR == true)
          Resistance.Set(pR);



          if(Close[0] > pS && plotS == true && Close[0] >= pR)
          AID = "Long";

          if(Close[0] < pR && plotR == true && Close[0] <= pS)
          AID = "Short";

          if( Close[0]>= pS && Close[0] <=pR && plotS == true && plotR == true)
          AID = "Neutral";

          if( plotS != true && plotR != true)
          AID = "Neutral";

          if( AID == "Long")
          {
          CandleOutlineColor = Color.Black ;
          BarColor = Color.LightGreen;
          }


          else if(AID == "Short")
          {
          CandleOutlineColor = Color.Black;
          BarColor = Color.Red;

          }

          else
          {
          CandleOutlineColor = Color.Black;
          BarColor = Color.Gray;

          }




          }
          public string aid1
          {
          get
          { return AID;
          }
          }

          #region Properties
          // CDSR Variables declaration//
          [Browsable(false)]
          [XmlIgnore()]
          public DataSeries Support
          {
          get { return Values[0]; }
          }

          [Browsable(false)]
          [XmlIgnore()]
          public DataSeries Resistance
          {
          get { return Values[1]; }
          }

          [GridCategory("Parameters")]
          public int PeriodATR
          {
          get { return periodATR; }
          set { periodATR = Math.Max(1, value); }
          }

          [GridCategory("Parameters")]
          public int StddevBB
          {
          get { return stddevBB; }
          set { stddevBB = Math.Max(1, value); }
          }

          [GridCategory("Parameters")]
          public int PeriodBB
          {
          get { return periodBB; }
          set { periodBB = Math.Max(1, value); }
          }


          [GridCategory("Parameters")]
          public double TicksSR
          {
          get { return ticksSR; }
          set { ticksSR = Math.Max(0, value); }
          }

          // CDMA Variable declaration//
          [Description("Inclusive")]
          [GridCategory("CDMA")]
          [Gui.Design.DisplayNameAttribute("Trade size min")]
          public int VolumeMin
          {
          get { return _VolumeMin; }
          set { _VolumeMin = Math.Max(1, value); }
          }
          [GridCategory("CDMA")]
          [Gui.Design.DisplayNameAttribute("Trade size max")]
          public int VolumeMax
          {
          get { return _VolumeMax; }
          set { _VolumeMax = Math.Max(1, value); }
          }

          [GridCategory("CDMA")]
          [Gui.Design.DisplayNameAttribute("T3:Period")]
          public int T3_period
          {
          get { return _T3_period; }
          set { _T3_period = Math.Max(1, value); }
          }
          [GridCategory("CDMA")]
          [Gui.Design.DisplayNameAttribute("T3:TCount")]
          public int T3_tCount
          {
          get { return _T3_tCount; }
          set { _T3_tCount = Math.Max(1, value); }
          }
          [GridCategory("CDMA")]
          [Gui.Design.DisplayNameAttribute("T3:VFactor")]
          public double T3_vFactor
          {
          get { return _T3_vFactor; }
          set { _T3_vFactor = Math.Max(0, value); }
          }

          [GridCategory("CDMA")]
          [Gui.Design.DisplayNameAttribute("Color for up")]
          public Color UpColor
          {
          get { return _UpColor; }
          set { _UpColor = value; }
          }
          [Browsable(false)]
          public string UpColorSerialize
          {
          get { return NinjaTrader.Gui.Design.SerializableColor.ToString( _UpColor); }
          set { _UpColor = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value); }
          }
          [GridCategory("CDMA")]
          [Gui.Design.DisplayNameAttribute("Color for down")]
          public Color DownColor
          {
          get { return _DownColor; }
          set { _DownColor = value; }
          }
          [Browsable(false)]
          public string DownColorSerialize
          {
          get { return NinjaTrader.Gui.Design.SerializableColor.ToString( _DownColor); }
          set { _DownColor = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value); }
          }
          [GridCategory("CDMA")]
          [Gui.Design.DisplayNameAttribute("Sound file for up cross")]
          [TypeConverter(typeof(SoundConverter))]
          public string UpCrossSound
          {
          get { return _UpCrossSound; }
          set { _UpCrossSound = value; }
          }
          [GridCategory("CDMA")]
          [Gui.Design.DisplayNameAttribute("Sound file for down cross")]
          [TypeConverter(typeof(SoundConverter))]
          public string DownCrossSound
          {
          get { return _DownCrossSound; }
          set { _DownCrossSound = value; }
          }
          [GridCategory("CDMA")]
          [Gui.Design.DisplayNameAttribute("Sound once per bar")]
          public bool AlertOncePerBar
          {
          get { return _AlertOncePerBar; }
          set { _AlertOncePerBar = value; }
          }
          [GridCategory("CDAEx")]
          [Gui.Design.DisplayNameAttribute("AID")]

          public string aid
          {
          get
          {
          Update();
          return AID;
          }
          set { AID = value; }
          }
          [GridCategory("CDAEx")]
          [Gui.Design.DisplayNameAttribute("Support")]

          public double support
          {
          get
          {
          Update();
          return pS ;
          }
          set { pS = value; }
          }
          [GridCategory("CDAEx")]
          [Gui.Design.DisplayNameAttribute("Resistance")]

          public double resistance
          {
          get
          {
          Update();
          return pR;
          }
          set { pR = value; }
          }


          #endregion
          }
          }

          Comment


            #6
            Hello,

            Thank you for the reply.

            Unfortunately I am unable to compile what was provided to see what may be happening.

            I will provide a basic outline on what would be needed to expose and set a string series from an indicator.

            Using the sample from this page: http://ninjatrader.com/support/helpG...b=stringseries

            we can create the following in an indicator:

            Code:
            private StringSeries myStringSeries;
            
            protected override void Initialize()
            {
            	 myStringSeries = new StringSeries(this);
            }
            
            protected override void OnBarUpdate()
            {
                myStringSeries.Set("Current Bar: " + CurrentBar.ToString());
            }
            
            [Browsable(false)]
            [XmlIgnore()]
            public StringSeries MyStrings
            {
            	get { return myStringSeries; }
            }
            This would be all that is required to expose the series, now in the strategy we could call this series using the following syntax:

            Code:
            NameOfTheIndicator().MyStrings[0]
            I have attached this example for you to test.

            I look forward to being of further assistance.
            Attached Files
            JesseNinjaTrader Customer Service

            Comment


              #7
              Thank you

              Hi,

              Thank you so much for the reply, it has worked.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by CortexZenUSA, Today, 12:53 AM
              0 responses
              1 view
              0 likes
              Last Post CortexZenUSA  
              Started by CortexZenUSA, Today, 12:46 AM
              0 responses
              1 view
              0 likes
              Last Post CortexZenUSA  
              Started by usazencortex, Today, 12:43 AM
              0 responses
              5 views
              0 likes
              Last Post usazencortex  
              Started by sidlercom80, 10-28-2023, 08:49 AM
              168 responses
              2,266 views
              0 likes
              Last Post sidlercom80  
              Started by Barry Milan, Yesterday, 10:35 PM
              3 responses
              13 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Working...
              X