public Operation GetOperationDetail(double[] arrayPriceOpen, double[] arrayPriceClose, double[] arrayPriceLow, double[] arrayPriceHigh, double[] arrayVolume) { try { int atr1 = 0; int atr2 = 0; double[] atr3 = new double[arrayPriceClose.Length]; TicTacTec.TA.Library.Core.Atr(0, arrayPriceClose.Length - 1, arrayPriceHigh, arrayPriceLow, arrayPriceClose, 14, out atr1, out atr2, atr3); double atrVal = atr3[atr2 - 1]; IndicatorMACD macd = new IndicatorMACD(); Operation operationMACD = macd.GetOperation(arrayPriceOpen, arrayPriceClose, arrayPriceLow, arrayPriceHigh, arrayVolume); IndicatorCCI cci = new IndicatorCCI(); Operation operationCCI = cci.GetOperation(arrayPriceOpen, arrayPriceClose, arrayPriceLow, arrayPriceHigh, arrayVolume); IndicatorRSI rsi = new IndicatorRSI(); Operation operationRSI = rsi.GetOperation(arrayPriceOpen, arrayPriceClose, arrayPriceLow, arrayPriceHigh, arrayVolume); //TicTacTec.TA.Library.Core.Atr(); MainClass.log("CCI: " + cci.result); MainClass.log("CCI Tendency: " + cci.getTendency()); MainClass.log("RSI: " + rsi.result); MainClass.log("RSI Tendency: " + rsi.getTendency()); MainClass.log("MACD: " + macd.result); if (MainClass.carolatr) { MainClass.log("ATR: " + atrVal); } if (cci.result > 0 && operationMACD == Operation.buy && rsi.result > 50 && cci.getTendency() == Tendency.high && rsi.getTendency() == Tendency.high && ((MainClass.carolatr && atrVal < MainClass.atrvalue) || !MainClass.carolatr)) //if (operationMACD == Operation.buy) { double[] arrayresultMA = new double[arrayPriceClose.Length]; int outBegidx, outNbElement; TicTacTec.TA.Library.Core.MovingAverage(0, arrayPriceClose.Length - 1, arrayPriceClose, 100, TicTacTec.TA.Library.Core.MAType.Ema, out outBegidx, out outNbElement, arrayresultMA); if (arrayPriceClose[arrayPriceClose.Length - 1] > arrayresultMA[outNbElement - 1]) { return(Operation.buy); } } if (cci.result < 0 && operationMACD == Operation.sell && rsi.result < 50 && cci.getTendency() == Tendency.low && rsi.getTendency() == Tendency.low && ((MainClass.carolatr && atrVal < MainClass.atrvalue) || !MainClass.carolatr)) //if (operationMACD == Operation.sell) { double[] arrayresultMA = new double[arrayPriceClose.Length]; int outBegidx, outNbElement; TicTacTec.TA.Library.Core.MovingAverage(0, arrayPriceClose.Length - 1, arrayPriceClose, 100, TicTacTec.TA.Library.Core.MAType.Ema, out outBegidx, out outNbElement, arrayresultMA); if (arrayPriceClose[arrayPriceClose.Length - 1] < arrayresultMA[outNbElement - 1]) { return(Operation.sell); } } return(Operation.nothing); } catch { return(Operation.nothing); } }
public Operation GetOperationDetail(double[] arrayPriceOpen, double[] arrayPriceClose, double[] arrayPriceLow, double[] arrayPriceHigh, double[] arrayVolume) { try { IndicatorMACD macd = new IndicatorMACD(); Operation operationMACD = macd.GetOperation(arrayPriceOpen, arrayPriceClose, arrayPriceLow, arrayPriceHigh, arrayVolume); IndicatorCCI cci = new IndicatorCCI(); Operation operationCCI = cci.GetOperation(arrayPriceOpen, arrayPriceClose, arrayPriceLow, arrayPriceHigh, arrayVolume); IndicatorRSI rsi = new IndicatorRSI(); Operation operationRSI = rsi.GetOperation(arrayPriceOpen, arrayPriceClose, arrayPriceLow, arrayPriceHigh, arrayVolume); MainClass.log("CCI " + cci.result); MainClass.log("RSI " + rsi.result); if (cci.result > 0 && operationMACD == Operation.buy && rsi.result > 50 && cci.getTendency() == Tendency.high && rsi.getTendency() == Tendency.high) //if (operationMACD == Operation.buy) { double[] arrayresultMA = new double[arrayPriceClose.Length]; int outBegidx, outNbElement; TicTacTec.TA.Library.Core.MovingAverage(0, arrayPriceClose.Length - 1, arrayPriceClose, 100, TicTacTec.TA.Library.Core.MAType.Ema, out outBegidx, out outNbElement, arrayresultMA); if (arrayPriceClose[arrayPriceClose.Length - 1] > arrayresultMA[outNbElement - 1]) { return(Operation.buy); } } if (cci.result < 0 && operationMACD == Operation.sell && rsi.result < 50 && cci.getTendency() == Tendency.low && rsi.getTendency() == Tendency.low) //if (operationMACD == Operation.sell) { double[] arrayresultMA = new double[arrayPriceClose.Length]; int outBegidx, outNbElement; TicTacTec.TA.Library.Core.MovingAverage(0, arrayPriceClose.Length - 1, arrayPriceClose, 100, TicTacTec.TA.Library.Core.MAType.Ema, out outBegidx, out outNbElement, arrayresultMA); if (arrayPriceClose[arrayPriceClose.Length - 1] < arrayresultMA[outNbElement - 1]) { return(Operation.sell); } } return(Operation.nothing); } catch { return(Operation.nothing); } }
public static void run() { MainClass.arrayPriceClose = new double[sizeArrayCandles]; MainClass.arrayPriceHigh = new double[sizeArrayCandles]; MainClass.arrayPriceLow = new double[sizeArrayCandles]; MainClass.arrayPriceVolume = new double[sizeArrayCandles]; MainClass.arrayPriceOpen = new double[sizeArrayCandles]; MainClass.arrayDate = new DateTime[sizeArrayCandles]; List <BitMEX.Candle> lstCandle = MainClass.bitMEXApi.GetCandleHistory(symbol, sizeArrayCandles, size); int i = 0; foreach (var candle in lstCandle) { MainClass.arrayPriceClose[i] = (double)candle.close; MainClass.arrayPriceHigh[i] = (double)candle.high; MainClass.arrayPriceLow[i] = (double)candle.low; MainClass.arrayPriceVolume[i] = (double)candle.volume; MainClass.arrayPriceOpen[i] = (double)candle.open; MainClass.arrayDate[i] = (DateTime)candle.TimeStamp; i++; } Array.Reverse(MainClass.arrayPriceClose); Array.Reverse(MainClass.arrayPriceHigh); Array.Reverse(MainClass.arrayPriceLow); Array.Reverse(MainClass.arrayPriceVolume); Array.Reverse(MainClass.arrayPriceOpen); Array.Reverse(MainClass.arrayDate); for (i = 10; i < sizeArrayCandles; i++) { IndicatorSAR sar = new IndicatorSAR(); IndicatorCCI cci = new IndicatorCCI(); Operation result = sar.GetOperation(SubArray(MainClass.arrayPriceOpen, 0, i), SubArray(MainClass.arrayPriceClose, 0, i), SubArray(MainClass.arrayPriceLow, 0, i), SubArray(MainClass.arrayPriceHigh, 0, i), SubArray(MainClass.arrayPriceVolume, 0, i)); Operation resultCCI = cci.GetOperation(SubArray(MainClass.arrayPriceOpen, 0, i), SubArray(MainClass.arrayPriceClose, 0, i), SubArray(MainClass.arrayPriceLow, 0, i), SubArray(MainClass.arrayPriceHigh, 0, i), SubArray(MainClass.arrayPriceVolume, 0, i)); MainClass.log(MainClass.arrayDate[i].ToString() + " - " + MainClass.arrayPriceClose[i].ToString() + " - " + result.ToString()); MainClass.log("CCI - " + cci.result); if (result == Operation.buy) { //MainClass.log("Buy"); //MainClass.log("Open " + MainClass.arrayPriceOpen[i].ToString()); //MainClass.log("Close " + MainClass.arrayPriceClose[i].ToString()); //MainClass.log("Low " + MainClass.arrayPriceLow[i].ToString()); //MainClass.log("High " + MainClass.arrayPriceHigh[i].ToString()); //MainClass.log("Volume " + MainClass.arrayPriceVolume[i].ToString()); } else if (result == Operation.sell) { //MainClass.log("Sell"); //MainClass.log("Open " + MainClass.arrayPriceOpen[i].ToString()); //MainClass.log("Close " + MainClass.arrayPriceClose[i].ToString()); //MainClass.log("Low " + MainClass.arrayPriceLow[i].ToString()); //MainClass.log("High " + MainClass.arrayPriceHigh[i].ToString()); //MainClass.log("Volume " + MainClass.arrayPriceVolume[i].ToString()); } else if (result == Operation.nothing) { } } }