Exemplo n.º 1
0
Arquivo: ATR.cs Projeto: ifzz/QuantSys
        public override double HandleNextTick(Tick t)
        {
            double ATR = double.NaN;

            if (prevTick != null)
            {
                double m1 = t.BidHigh - t.BidLow;
                double m2 = Math.Abs(t.BidHigh - prevTick.BidClose);
                double m3 = Math.Abs(t.BidLow - prevTick.BidClose);
                double TR = Math.Max(m1, Math.Max(m2, m3));
                TrueRange.Enqueue(TR);
            }
            else
            {
                TrueRange.Enqueue(t.BidHigh - t.BidLow);
            }

            counter++;
            if (counter.Equals(Period))
            {
                ATR = TrueRange.ToArray().Average();
            }
            else if(counter > Period)
            {
                ATR = (this[0]*(Period - 1) + TrueRange.ToArray()[Period-1])/Period;
            }
            
            indicatorData.Enqueue(ATR);
            prevTick = t;
            return ATR;
        }
Exemplo n.º 2
0
        public override double HandleNextTick(Tick t)
        {
            SMAHi.HandleNextTick(t.BidHigh);
            SMALow.HandleNextTick(t.BidLow);

            return SMALow[0];
        }
Exemplo n.º 3
0
        public override double HandleNextTick(Tick t)
        {
            PFE.HandleNextTick(t);
            FI.HandleNextTick(t);
            RWI.HandleNextTick(t);
            AC.HandleNextTick(t);
            double value = 0;


            if (AC[0] > 0)
                value++;
            else if (AC[0] < 0)
                value--;
            
            if (PFE[0] > 0)
                value++;
            else if (PFE[0] < 0)
                value--;
            
            if (RWI.SubIndicators["RWHI"][0] > 1 && RWI.SubIndicators["RWHI"][0] > RWI.SubIndicators["RWLO"][0])
                value++;
            if (RWI.SubIndicators["RWLO"][0] > 1 && RWI.SubIndicators["RWLO"][0] > RWI.SubIndicators["RWHI"][0])
                value--;

            indicatorData.Enqueue(value);
            return value;
        }
Exemplo n.º 4
0
Arquivo: RSI.cs Projeto: ifzz/QuantSys
        public override double HandleNextTick(Tick currentTick)
        {
            double value = double.NaN;

            if (previousTick != null)
            {
                if (currentTick.BidClose < previousTick.BidClose)
                {
                    DOWN.Enqueue(previousTick.BidClose - currentTick.BidClose);
                    UP.Enqueue(0);
                }
                else if (currentTick.BidClose > previousTick.BidClose)
                {
                    DOWN.Enqueue(0);
                    UP.Enqueue(currentTick.BidClose - previousTick.BidClose);
                }
            }

            if (DOWN.Count.Equals(DOWN.Capacity))
            {
                AVGUP = UP.ToArray().Average();
                AVGDOWN = DOWN.ToArray().Average();
            }

            value = 100 - 100 / (1 + AVGUP / AVGDOWN);
            previousTick = currentTick;
            
            indicatorData.Enqueue(value);
            return value;
        }
Exemplo n.º 5
0
        public override double HandleNextTick(Tick t)
        {
            Tick hTick = null;

            if (HACandle.Count.Equals(0))
            {
                hTick = t;
            }

            if (prevTick != null)
            {
                double HABidClose = (t.BidOpen + t.BidHigh + t.BidLow + t.BidClose) / 4;
                double HAAskClose = (t.AskOpen + t.AskHigh + t.AskLow + t.AskClose) / 4;

                double HABidOpen = (prevTick.BidOpen + prevTick.BidClose) / 2;
                double HAAskOpen = (prevTick.AskOpen + prevTick.AskClose) / 2;

                double HABidHigh = Math.Max(t.BidHigh, Math.Max(HABidOpen, HABidClose));
                double HAAskHigh = Math.Max(t.AskHigh, Math.Max(HAAskOpen, HAAskClose));

                double HABidLow = Math.Min(t.BidLow, Math.Min(HABidOpen, HABidClose));
                double HAAskLow = Math.Min(t.AskLow, Math.Min(HAAskOpen, HAAskClose));

                hTick = new Tick(
                    t.CurrentBid, HABidOpen, HABidHigh, HABidLow, HABidClose,
                    t.CurrentAsk, HAAskOpen, HAAskHigh, HAAskLow, HAAskClose,
                    t.Volume, t.Time
                    );
            }

            HACandle.Enqueue(hTick);
            prevTick = hTick;

            return hTick.BidClose;
        }
Exemplo n.º 6
0
        public override void HandleNextTick(Tick t)
        {
            double emaVal = EMA.HandleNextTick(t);
            LRValues.Enqueue(emaVal);

            double[] Y = LRValues.ToArray();

            double stdErr = 0;

            if (Y.Count() == X.Length)
            {
                Vector x_data = new Vector(X);
                Vector y_data = new Vector(LRValues.ToArray());

                var poly = new PolynomialRegression(x_data, y_data, 2);
                for (int i = 0; i < Period; i++)
                {
                    double x = (i);
                    double y = poly.Fit(x);
                    stdErr += Math.Pow(LRValues.ToArray()[i] - y, 2);
                }

                stdErr = Math.Sqrt(stdErr);
            }

            HighData.Enqueue(EMA[0]+STDEV * stdErr);
            MiddleData.Enqueue(EMA[0]);
            LowData.Enqueue(EMA[0] - STDEV * stdErr);
             
        }
Exemplo n.º 7
0
 public override void HandleNextTick(Tick t)
 {
     MiddleData.Enqueue(MIDDLE.HandleNextTick(t));
     var stdev = MIDDLE.ToArray().StandardDeviation();
     HighData.Enqueue(MIDDLE[0] + stdev * 2);
     LowData.Enqueue(MIDDLE[0] - stdev * 2);    
 }
Exemplo n.º 8
0
        public override double HandleNextTick(Tick t)
        {
            BB.HandleNextTick(t);
            WILLR.HandleNextTick(t);
            UO.HandleNextTick(t);

            double value = 0;


            if (t.BidClose > BB.HI(0))
                value--;
            else if (t.BidClose < BB.LOW(0))
                value++;

            if (WILLR[0] > -20)
                value--;
            else if (WILLR[0] < -80)
                value++;

            if (UO[0] > 70)
                value--;
            else if (UO[0] < 30)
                value++;



            indicatorData.Enqueue(value);
            return value;
        }
Exemplo n.º 9
0
        public override double HandleNextTick(Tick t)
        {
            double value = double.NaN;
            double a1 = BP1.ToArray().Sum() / TR1.ToArray().Sum();
            double a2 = BP2.ToArray().Sum() / TR2.ToArray().Sum();
            double a3 = BP3.ToArray().Sum() / TR3.ToArray().Sum();

            if (BP3.Count == BP3.Capacity)
            {
                value = 100*((4*a1) + (2*a2) + a3)/(4 + 2 + 1);
            }

            if (prevTick != null)
            {
                double TR = Math.Max(t.BidHigh, prevTick.BidClose) - Math.Min(t.BidLow, prevTick.BidClose);
                double BP = t.BidClose - Math.Min(t.BidLow, prevTick.BidClose);

                BP1.Enqueue(BP);
                BP2.Enqueue(BP);
                BP3.Enqueue(BP);

                TR1.Enqueue(TR);
                TR2.Enqueue(TR);
                TR3.Enqueue(TR);
            }

            prevTick = t;
            indicatorData.Enqueue(value);
            return value;
        }
Exemplo n.º 10
0
 public MarketOrder(Tick t, Position.PositionSide side, double orderSize)
 {
     Symbol = t.Symbol;
     Side = side;
     Price = (side.Equals(Position.PositionSide.Long)) ? t.AskClose : t.BidClose;
     Size = orderSize;
     OrderDate = t.Time;
 }
Exemplo n.º 11
0
 public bool IncreasePosition(Tick t, double size)
 {
     if (ExistsPositionForSymbol(t.Symbol))
     {
         _positions[t.Symbol].IncreasePosition(t, size);
         return true;
     }
     return false;
 }
Exemplo n.º 12
0
        public override double HandleNextTick(Tick t)
        {
            returnsData.Enqueue((t.BidClose-prevTick)/prevTick);
            double value = returnsData.ToArray().StandardDeviation();
            indicatorData.Enqueue(value);

            prevTick = t.BidClose;
            return value;
        }
Exemplo n.º 13
0
        public double ClosePosition(Tick t, double price)
        {
            CloseDate = t.Time;

            if (Side.Equals(PositionSide.Long))
                return Size * (price - PositionPrice);
            else
                return Size * (PositionPrice - price);
        }
Exemplo n.º 14
0
Arquivo: AC.cs Projeto: ifzz/QuantSys
        public override double HandleNextTick(Tick t)
        {
            double value = double.NaN;
            double aonext = AO.HandleNextTick(t);
            double smanext = SMA.HandleNextTick(aonext);

            value = aonext - smanext;
            indicatorData.Enqueue(value);
            return value;
        }
Exemplo n.º 15
0
 public bool ReducePosition(Tick t, double size)
 {
     if (ExistsPositionForSymbol(t.Symbol))
     {
         double changeInBalance = _positions[t.Symbol].ReducePosition(t, size);
         AdjustPortfolioBalance(changeInBalance);
         return true;
     }
     return false;
 }
Exemplo n.º 16
0
        public UltimateOscillator(int p1 = 7, int p2 = 14, int p3 = 28):base(p3)
        {
            prevTick = null;
            BP1 = new MovingQueue<double>(p1);
            TR1 = new MovingQueue<double>(p1);
            BP2 = new MovingQueue<double>(p2);
            TR2 = new MovingQueue<double>(p2);
            BP3 = new MovingQueue<double>(p3);
            TR3 = new MovingQueue<double>(p3);

        }
Exemplo n.º 17
0
 //Balance is update when positions are closed
 public double ClosePosition(Tick t, double price)
 {
     if (ExistsPositionForSymbol(t.Symbol))
     {
         double changeInBalance = _positions[t.Symbol].ClosePosition(t, price);
         _positions.Remove(t.Symbol);
         AdjustPortfolioBalance(changeInBalance);
         return changeInBalance;
     }
     return 0;
 }
Exemplo n.º 18
0
        public override double HandleNextTick(Tick t)
        {
            double ema1 = EMA1.HandleNextTick(t);
            double ema2 = EMA2.HandleNextTick(ema1);
            double ema3 = EMA3.HandleNextTick(ema2);

            double value = 100 * (ema3 - EMA3[1]) / ema3;
            indicatorData.Enqueue(value);

            return value;
        }
Exemplo n.º 19
0
Arquivo: AO.cs Projeto: ifzz/QuantSys
        public override double HandleNextTick(Tick t)
        {
            double value = double.NaN;
            value = SMA1[0] - SMA2[0];
            indicatorData.Enqueue(value);

            double MEDIANPRICE = (t.BidHigh + t.BidLow)/2;
            SMA1.HandleNextTick(MEDIANPRICE);
            SMA2.HandleNextTick(MEDIANPRICE);

            return value;
        }
Exemplo n.º 20
0
        public override double HandleNextTick(Tick t)
        {
            double mfm = MoneyFlowMultiplier.HandleNextTick(t);
            double mfv = mfm*t.Volume;
            ADL += mfv;

            double a1 = ADL1.HandleNextTick(ADL);
            double a2 = ADL2.HandleNextTick(ADL);

            indicatorData.Enqueue(a1 - a2);
            return a1 - a2;
        }
Exemplo n.º 21
0
        public override double HandleNextTick(Tick t)
        {
            priceData.Enqueue(t.BidClose);

            double value = double.NaN;
            if (priceData.Count.Equals(priceData.Capacity))
            {
                value = HurstEstimation.CalculateHurstEstimate(priceData.ToArray());
            }
            indicatorData.Enqueue(value);
            return value;
        }
Exemplo n.º 22
0
        public override double HandleNextTick(Tick t)
        {
            double value = double.NaN;

            _highData.Enqueue(t.BidHigh);
            _lowData.Enqueue(t.BidLow);
            value = (_highData.ToArray().Max() - t.BidClose)/
                    (_highData.ToArray().Max() - _lowData.ToArray().Min())*-100;

            indicatorData.Enqueue(value);

            return value;
        }
Exemplo n.º 23
0
        public override double HandleNextTick(Tick t)
        {
            double value = Double.NaN;

            if (prevTick != null)
            {
                value = EMA.HandleNextTick(t.Volume*(t.BidClose - prevTick.BidClose));
            }

            prevTick = t;
            indicatorData.Enqueue(value);
            return value;
        }
Exemplo n.º 24
0
        public override double HandleNextTicks(Tick[] t)
        {
            foreach (Tick tick in t)
            {
                if (!subIndicators.ContainsKey(tick.Symbol.SymbolString))
                {
                    subIndicators.Add(tick.Symbol.SymbolString, new GenericContainer(Period));
                }


            }
            return 0;

        }
Exemplo n.º 25
0
Arquivo: CCI.cs Projeto: ifzz/QuantSys
        public override double HandleNextTick(Tick t)
        {
            double value = double.NaN;

            double typicalPrice = (t.BidClose + t.BidHigh + t.BidLow)/3;
            priceData.Enqueue(typicalPrice);
            SMA.HandleNextTick(typicalPrice);

            if(priceData.Capacity.Equals(priceData.Count))
                value = (1/constant)*(typicalPrice - SMA[0])/priceData.ToArray().StandardDeviation();

            indicatorData.Enqueue(value);
            return value;
        }
Exemplo n.º 26
0
Arquivo: RWI.cs Projeto: ifzz/QuantSys
        public override double HandleNextTick(Tick t)
        {
            double value = double.NaN;
            double RWIH = double.NaN;
            double RWIL = double.NaN;

            if (prevTick != null)
            {
                double m1 = t.BidHigh - t.BidLow;
                double m2 = Math.Abs(t.BidHigh - prevTick.BidClose);
                double m3 = Math.Abs(t.BidLow - prevTick.BidClose);
                double tr = Math.Max(m1, Math.Max(m2, m3));
                TR.Enqueue(tr);
            }
            else
            {
                TR.Enqueue(t.BidHigh - t.BidLow);
            }

            if (priceData.Count.Equals(priceData.Capacity))
            {
                List<double> maxRWIHI = new List<double>(Period - 1);
                List<double> maxRWILO = new List<double>(Period - 1);

                for (int k = 0; k < Period - 1; k++)
                {
                    double avgTR = 0;
                    for (int i = k; i < Period; i++) avgTR += TR.ToArray()[i];
                    avgTR /= (Period - k);

                    double rwiHI = 1/Math.Sqrt(Period-k)*(t.BidHigh - priceData.ToArray()[k].BidLow)/avgTR;
                    double rwiLO = 1/Math.Sqrt(Period-k)*(priceData.ToArray()[k].BidHigh - t.BidLow)/avgTR;

                    maxRWIHI.Add(rwiHI);
                    maxRWILO.Add(rwiLO);
                }
                RWIH = maxRWIHI.Max();
                RWIL = maxRWILO.Max();

            }
            ((GenericContainer)subIndicators["RWHI"]).HandleNextTick(RWIH);
            ((GenericContainer)subIndicators["RWLO"]).HandleNextTick(RWIL);

            prevTick = t;
            priceData.Enqueue(t);

            indicatorData.Enqueue(double.NaN);
            return double.NaN;
        }
Exemplo n.º 27
0
        public void ModifyStopOrder(Tick stop, double newPrice)
        {
            if (_outStandingStopOrders.ContainsKey(stop.Symbol))
            {
                _outStandingStopOrders[stop.Symbol].TriggerPrice = newPrice;
            }

            /*
            //Flags for visualization purposes
            _flags.Add(new HighstockFlag(
                   "MS",""+newPrice, stop.Time
                ));
             */
           
        }
Exemplo n.º 28
0
        public override void HandleNextTick(Tick t)
        {
            double emaVal = EMA.HandleNextTick(t);
            LRValues.Enqueue(emaVal);

            double[] Y = LRValues.ToArray();

            LinearRegression l = new LinearRegression();
            l.Model(Y);
            
            HighData.Enqueue(EMA[0]+STDEV * l.STDERR);
            MiddleData.Enqueue(EMA[0]);
            LowData.Enqueue(EMA[0] - STDEV * l.STDERR);
             
        }
Exemplo n.º 29
0
        public override double HandleNextTick(Tick t)
        {
            EMA1.HandleNextTick(t.BidClose);
            EMA2.HandleNextTick(t.BidClose);

            double MACD = EMA1[0] - EMA2[0];
            indicatorData.Enqueue(MACD);
            
            ((EMA)subIndicators["Signal"]).HandleNextTick(MACD);

            double MACDHist = MACD - subIndicators["Signal"][0];
            ((GenericContainer)subIndicators["Histogram"]).HandleNextTick(MACDHist);

            return MACD;
        }
Exemplo n.º 30
0
 public void RecalculateTrail(Tick t)
 {
     if (Side.Equals(Position.PositionSide.Long))
     {
         if (t.BidClose - TrailSize > TriggerPrice)
         {
             TriggerPrice = t.BidClose - TrailSize;
         }
     } else if(Side.Equals(Position.PositionSide.Short))
     {
         if (t.AskClose + TrailSize < TriggerPrice)
         {
             TriggerPrice = t.AskClose + TrailSize;
         }
     }
 }