Пример #1
0
        public static void TestHMA()
        {
            iFMA FMA = new iFMA(10);

            for (int i = 0; i < 10; i++)
            {
                FMA.ReceiveTick(i);
            }

            double v = FMA.Value();               // should be 9.5

            if (Math.Abs(9.5 - v) < 0.000001)
            {
                Framework.Logger(2, "FMA Returns correct value: 9.5");
            }
        }
        // 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);
        }
Пример #3
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);
        }