Пример #1
0
        public static void TestBBands()
        {
            iBollingerBands BB;

            BB = new iBollingerBands(10, -1);
            BB = new iBollingerBands(20, -1);
            BB = new iBollingerBands(50, -1);

            BB = new iBollingerBands(21, -1);


            double[] val = { 6.92, 6.89, 6.82, 6.82, 6.83, 6.79, 6.75, 6.71, 6.71, 6.66, 6.59, 6.56, 6.59, 6.56, 6.61, 6.68, 6.65, 6.68, 6.54, 6.49, 6.42 };

            for (int i = 0; i < val.GetUpperBound(0) + 1; i++)
            {
                BB.ReceiveTick(val[i]);
            }

            double BP, MA, BM, pb, bw;

            BB.Value(out BP, out MA, out BM, out pb, out bw);

            if (Math.Abs(MA - 6.68) < 0.01)
            {
                Framework.Logger(2, "MA Returns correct value: " + MA);
            }

            if (Math.Abs(BP - 6.94) < 0.01)
            {
                Framework.Logger(2, "BP Returns correct value: " + BP);
            }

            if (Math.Abs(BM - 6.41) < 0.01)
            {
                Framework.Logger(2, "BM Returns correct value: " + BM);
            }
        }
Пример #2
0
        public string GetValues()
        {
            string Values;

            double BPlus, BSMA, BMinus, PctB, BW;
            double Deriv1, Deriv2;
            double MACDv, MACDs, MACDh;
            double STARCPlus, STARCSMA, STARCMinus;
            double STOv, STOs;

            double ATRv = ATR.Value();

            BB.Value(out BPlus, out BSMA, out BMinus, out PctB, out BW);
            double CCIv = CCI.Value();

            Derivatives.Value(out Deriv1, out Deriv2);
            double EMAv = EMA.Value();
            double FMAv = FMA.Value();
            double HMAv = HMA.Value();

            MACD.Value(out MACDv, out MACDs, out MACDh);
            double MOMv = Momemtum.Value();
            double RSIv = RSI.Value();
            double RKOv = Renko.Value();
            double SMAv = SMA.Value();

            STARCBands.Value(out STARCPlus, out STARCSMA, out STARCMinus);
            double STDv = STDDEV.Value();
            double SLPv = Slope.Value();
            double SRSv = StochRSI.Value();

            Stochastics.Value(out STOv, out STOs);
            double STv  = Stub.Value();
            double TRDv = Trend.Value();
            double TRv  = TrueRange.Value();
            double WMAv = WMA.Value();

            string ATRp = ATR.isPrimed().ToString();
            string BBp  = BB.isPrimed().ToString();
            string CCIp = CCI.isPrimed().ToString();
            string DERp = Derivatives.isPrimed().ToString();
            string EMAp = EMA.isPrimed().ToString();
            string FMAp = FMA.isPrimed().ToString();
            string HMAp = HMA.isPrimed().ToString();
            string MACp = MACD.isPrimed().ToString();
            string MOMp = Momemtum.isPrimed().ToString();
            string RSIp = RSI.isPrimed().ToString();
            string RKOp = Renko.isPrimed().ToString();
            string SMAp = SMA.isPrimed().ToString();
            string STCp = STARCBands.isPrimed().ToString();
            string STDp = STDDEV.isPrimed().ToString();
            string SLPp = Slope.isPrimed().ToString();
            string SRSp = StochRSI.isPrimed().ToString();
            string STOp = Stochastics.isPrimed().ToString();
            string STp  = Stub.isPrimed().ToString();
            string TRDp = Trend.isPrimed().ToString();
            string TRp  = TrueRange.isPrimed().ToString();
            string WMAp = WMA.isPrimed().ToString();

            Values =
                Candle.O + "," + Candle.H + "," + Candle.L + "," + Candle.C + "," +
                ATRp + "," + ATRv + "," +
                BBp + "," + BPlus + "," + BSMA + "," + BMinus + "," + PctB + "," + BW + "," +
                CCIp + "," + CCIv + "," +
                DERp + "," + Deriv1 + "," + Deriv2 + "," +
                EMAp + "," + EMAv + "," +
                FMAp + "," + FMAv + "," +
                HMAp + "," + HMAv + "," +
                MACp + "," + MACDv + "," + MACDs + "," + MACDh + "," +
                MOMp + "," + MOMv + "," +
                RSIp + "," + RSIv + "," +
                RKOp + "," + RKOv + "," +
                SMAp + "," + SMAv + "," +
                STCp + "," + STARCPlus + "," + STARCSMA + "," + STARCMinus + "," +
                STDp + "," + STDv + "," +
                SLPp + "," + SLPv + "," +
                SRSp + "," + SRSv + "," +
                STOp + "," + STOv + "," + STOs + "," +
                STp + "," + STv + "," +
                TRDp + "," + TRDv + "," +
                TRp + "," + TRv + "," +
                WMAp + "," + WMAv;

            return(Values);
        }
        // decide if we are entering or exiting a long or short trade
        // different criteria can be used for each condition
        private void DecisionFunction()
        {
            switch (Framework.Account.InTrade())
            {
            // if we are not in a trade, see to enter long or short
            case 0:
            {
                // seems like a repetitive check
                if (Framework.Account.InTrade() == 0)
                {
                    if (EntryCriteriaLong())
                    {
                        Framework.Account.EnterTrade(1);
                        Framework.Account.SetTrailingStop(0.0018);
                    }
                }

                // now is not a repetitive check since
                // EntryCriteriaLong might have entered a trade
                // so check again
                if (Framework.Account.InTrade() == 0)
                {
                    if (EntryCriteriaShort())
                    {
                        Framework.Account.EnterTrade(1);
                        Framework.Account.SetTrailingStop(0.0018);
                    }
                }

                break;
            }

            // if we are currently long, look for a long exit strategy
            case 1:
            {
                if (EntryCriteriaShort())
                {
                    Framework.Account.ExitTrade();
                    //Framework.Account.EnterTrade(-1);
                }
                break;
            }

            // if we are currently short, look for a short exit strategy
            case -1:
            {
                if (EntryCriteriaLong())
                {
                    Framework.Account.ExitTrade();
                    //Framework.Account.EnterTrade(1);
                }
                break;
            }
            }

            // extract values from indicators and account
            // and log them to a file (used to create a graph with a separate app)
            double logInTrade = Framework.Account.InTrade();
            double logMargin  = Framework.Account.GetAccount().C;
            double C          = cbx.GetCandle(0).C;
            double TP         = (cbx.GetCandle(0).C + cbx.GetCandle(0).H + cbx.GetCandle(0).L) / 3;
            double hma        = HMA.Value();
            double fma        = FMA.Value();
            double deriv1     = ((double)Deriv1.GetItem(0));
            double deriv2     = ((double)Deriv2.GetItem(0));
            double sma;
            double bband1;
            double bband2;
            double pb;
            double bw;
            double srsi = StochRSI.Value();
            double cci  = CCI.Value();

            BBands.Value(out bband1, out sma, out bband2, out pb, out bw);

            // write monitored valued to the numerical output file
            // Framework.WriteGraphLine("InTrade,Margin,C,TP,FMA,HMA,Deriv1,Deriv2,SMA,BBand1,BBand2,%b,Bandwidth,StochRSI,CCI");
            Framework.WriteGraphLine(logInTrade + "," + logMargin + "," + C + "," + TP + "," + fma + "," + hma + "," + deriv1 + "," + deriv2 + "," + sma + "," + bband1 + "," + bband2 + "," + pb + "," + bw + "," + srsi + "," + cci);
        }
Пример #4
0
        private void DecisionFunction()
        {
            BBands.Value(out BPlus, out SMA, out BMinus, out PctB, out BW);
            BWidth = BPlus - BMinus;
            SMASlope.ReceiveTick(SMA);

            HMAv = HMA.Value();

            // preprocessing

            StateMachine();

            switch (Framework.Account.InTrade())
            {
            case 0:
            {
                if (Framework.Account.InTrade() == 0)
                {
                    if (EntryCriteriaLong())
                    {
                        Framework.Account.EnterTrade(1);
                        Framework.Account.SetTrailingStop(TrailingStop);
                    }
                }

                if (Framework.Account.InTrade() == 0)
                {
                    if (EntryCriteriaShort())
                    {
                        Framework.Account.EnterTrade(-1);
                        Framework.Account.SetTrailingStop(TrailingStop);
                    }
                }
                break;
            }

            case 1:
            {
                if (ExitCriteriaLong())
                {
                    Framework.Account.ExitTrade();
                }
                break;
            }

            case -1:
            {
                if (ExitCriteriaShort())
                {
                    Framework.Account.ExitTrade();
                }
                break;
            }
            }

            double logInTrade = Framework.Account.InTrade();
            double logMargin  = Framework.Account.GetAccount().C;

            //Framework.WriteGraphLine("InTrade,Margin,B+,C,HMA,SMA,B-,State,BWidth,MinBWidth,EntryRecommend");
            Framework.WriteGraphLine(logInTrade + "," + logMargin + "," + BPlus + "," + Candle.C + "," + HMAv + "," + SMA + "," + BMinus + "," + State + "," + BWidth + "," + MinBWidth + "," + EntryRecommend);
        }