Ejemplo n.º 1
0
        public override void ApplyTo(StockSerie stockSerie)
        {
            float accelerationFactorStart = (float)this.parameters[0];
             float accelerationFactorStep = (float)this.parameters[1];
             float accelerationFactorMax = (float)this.parameters[2];

             FloatSerie sarSupport;
             FloatSerie sarResistance;

             stockSerie.CalculateSAR(accelerationFactorStep, accelerationFactorStart, accelerationFactorMax, out sarSupport,
            out sarResistance, (int)this.parameters[3]);

             this.Series[0] = sarSupport;
             this.Series[1] = sarResistance;

             // Detecting events
             this.CreateEventSeries(stockSerie.Count);
             float previousHigh = stockSerie.Values.First().HIGH, previousLow = stockSerie.Values.First().LOW;
             float previousHigh2 = stockSerie.Values.First().HIGH, previousLow2 = stockSerie.Values.First().LOW;
             bool waitingForEndTrend = false;
             for (int i = 5; i < stockSerie.Count; i++)
             {
            if (float.IsNaN(sarResistance[i]) && !float.IsNaN(sarResistance[i - 1]))
            {
               this.Events[0][i] = true; // SupportDetected

               if (waitingForEndTrend)
               {
                  this.Events[3][i] = true; // EndOfTrend
                  waitingForEndTrend = false;
               }

               if (sarSupport[i] > previousLow)
               {
                  this.Events[4][i] = true; // HigherLow

                  if (sarSupport[i] > previousHigh2)
                  {
                     this.Events[2][i] = true; // PB
                     waitingForEndTrend = true;
                  }
               }
               previousLow2 = previousLow;
               previousLow = sarSupport[i];
            }
            if (float.IsNaN(sarSupport[i]) && !float.IsNaN(sarSupport[i - 1]))
            {
               this.Events[1][i] = true; // ResistanceDetected

               if (waitingForEndTrend)
               {
                  this.Events[3][i] = true; // EndOfTrend
                  waitingForEndTrend = false;
               }

               if (sarResistance[i] < previousHigh)
               {
                  this.Events[5][i] = true; // LowerHigh
                  if (sarResistance[i] < previousLow2)
                  {
                     this.Events[2][i] = true; // PB
                     waitingForEndTrend = true;
                  }
               }
               previousHigh2 = previousHigh;
               previousHigh = sarResistance[i];
            }

            this.Events[6][i] = false;
            this.Events[7][i] = false;
            this.Events[8][i] = float.IsNaN(sarResistance[i]);
            this.Events[9][i] = float.IsNaN(sarSupport[i]);
             }
        }
        public override void ApplyTo(StockSerie stockSerie)
        {
            float accelerationFactorStep = (float)this.parameters[0];
             float accelerationFactorMax = (float)this.parameters[1];

             FloatSerie sarSupport1;
             FloatSerie sarResistance1;

             FloatSerie sarSupport2;
             FloatSerie sarResistance2;

             float ratio = (float)this.parameters[2];

             stockSerie.CalculateSAR(accelerationFactorStep, accelerationFactorStep, accelerationFactorMax, out sarSupport1, out sarResistance1, 1);
             stockSerie.CalculateSAR2(accelerationFactorStep / ratio, accelerationFactorStep / ratio, accelerationFactorMax / ratio, sarSupport1, sarResistance1, out sarSupport2, out sarResistance2);

             this.Series[0] = sarSupport1;
             this.Series[1] = sarResistance1;

             this.Series[2] = sarSupport2;
             this.Series[3] = sarResistance2;

             // Detecting events
             this.CreateEventSeries(stockSerie.Count);

             for (int i = 5; i < stockSerie.Count; i++)
             {
            this.Events[0][i] = float.IsNaN(sarResistance1[i - 1]) && !float.IsNaN(sarResistance1[i]);
            this.Events[1][i] = float.IsNaN(sarSupport1[i - 1]) && !float.IsNaN(sarSupport1[i]);

            this.Events[2][i] = float.IsNaN(sarResistance2[i - 1]) && !float.IsNaN(sarResistance2[i]);
            this.Events[3][i] = float.IsNaN(sarSupport2[i - 1]) && !float.IsNaN(sarSupport2[i]);
             }
        }