public void RunStrategy(List <OHLCKandle> inputkandles, RobotInput robotInput, ref StrategyData strategyData, ref SimplePosition currentPosition)
        {
            PineScriptFunction fn = new PineScriptFunction();

            //convert to higher timeframe
            var largekandles = fn.converttohighertimeframe(inputkandles, KandleMultiplier);//3

            if (Smoothing.ToUpper() == "DEMA")
            {
                //higher timeframe candles with dema values
                largekandles = fn.dema(largekandles, 8);

                //lower timeframe candles with dema values
                inputkandles = fn.dema(inputkandles, 8);
            }
            else
            {
                //higher timeframe candles with smma values
                largekandles = fn.smma(largekandles, 8);

                //lower timeframe candles with smma values
                inputkandles = fn.smma(inputkandles, 8);
            }


            var closeseriesmma = inputkandles.Select(x => x.Close).ToList();


            //map higher timeframe values to lower timeframe values
            var altkandles = fn.superimposekandles(largekandles, inputkandles);

            var closeSeriesAlt = altkandles.Select(x => x.Close).ToList();

            var openSeriesAlt = altkandles.Select(x => x.Open).ToList();


            //trend and mood calculation-
            strategyData.trend = closeSeriesAlt.Last() > openSeriesAlt.Last() ? "BULLISH" : "BEARISH";

            strategyData.mood = closeseriesmma.Last() > openSeriesAlt.Last() ? "BULLISH" : "BEARISH";


            //buy sell signal
            var xlong = fn.crossover(closeSeriesAlt, openSeriesAlt);

            var xshort = fn.crossunder(closeSeriesAlt, openSeriesAlt);

            strategyData.isBuy = xlong.Last();

            strategyData.isSell = xshort.Last();


            //historical data
            strategyData.histdata = "";
            for (int i = 0; i < xlong.Count; i++)
            {
                if (xlong[i])
                {
                    strategyData.histdata += " B" + (xlong.Count - i - 1).ToString();
                }
                else if (xshort[i])
                {
                    strategyData.histdata += " S" + (xlong.Count - i - 1).ToString();
                }
                else
                {
                    // meh :\
                }
            }

            MakeBuySellDecision(ref strategyData, ref currentPosition, robotInput);

            if (strategyData.Output != StrategyOutput.None)
            {
                ResetCounters();

                strategyData.profitFactor = 1m;
            }
        }
Esempio n. 2
0
        public void RunStrategy(RobotInput robotInput, SimplePosition currentPosition, ref StrategyData strategyData)
        {
            List <OHLCKandle> inputkandles = strategyData.kandles.Select(x => new OHLCKandle
            {
                Close     = x.Close,
                CloseTime = x.CloseTime,
                High      = x.High,
                Low       = x.Low,
                Open      = x.Open,
                OpenTime  = x.OpenTime
            }).ToList();

            PineScriptFunction fn = new PineScriptFunction();

            //convert to higher timeframe
            var largekandles = fn.converttohighertimeframe(inputkandles, KandleMultiplier);//3

            //higher timeframe candles with smoothened values
            largekandles = GetSmoothData(largekandles, 8, Smoothing);

            //lower timeframe candles with smoothened values
            inputkandles = GetSmoothData(inputkandles, 8, Smoothing);

            var inputcloseseriesmoothed = inputkandles.Select(x => x.Close).ToList();

            //map higher timeframe values to lower timeframe values
            var altkandles = fn.superimposekandles(largekandles, inputkandles);

            var closeSeriesAlt = altkandles.Select(x => x.Close).ToList();

            var openSeriesAlt = altkandles.Select(x => x.Open).ToList();

            //end map higher timeframe values to lower timeframe values

            //trend and mood calculation-
            strategyData.trend = closeSeriesAlt.Last() > openSeriesAlt.Last() ? "BULLISH" : "BEARISH";

            strategyData.mood = inputcloseseriesmoothed.Last() > openSeriesAlt.Last() ? "BULLISH" : "BEARISH";

            //start buy sell signal
            var xlong = fn.crossover(closeSeriesAlt, openSeriesAlt);

            var xshort = fn.crossunder(closeSeriesAlt, openSeriesAlt);

            strategyData.isBuy = xlong.Last();

            strategyData.isSell = xshort.Last();
            //end buy sell signal

            UpdateBollingerData(ref strategyData);

            UpdateSignalData(ref strategyData, xlong, xshort);

            strategyDecision.Decide(ref strategyData, currentPosition, robotInput);

            if (strategyData.Decision != StrategyDecision.None)
            {
                strategyDecision.ResetCounters();

                strategyData.profitFactor = 1m;
            }
        }