/// <summary> /// new data came from the connector / /// из коннектора пришли новые данные /// </summary> private void BotTabIndex_NewCandlesChangeEvent(List <Candle> candles) { for (int i = 0; i < Tabs.Count; i++) { List <Candle> myCandles = Tabs[i].Candles(true); if (myCandles == null || myCandles.Count < 10) { return; } } DateTime time = Tabs[0].Candles(true)[Tabs[0].Candles(true).Count - 1].TimeStart; for (int i = 0; i < Tabs.Count; i++) { List <Candle> myCandles = Tabs[i].Candles(true); if (myCandles[myCandles.Count - 1].TimeStart != time) { return; } } //loop to collect all the candles in one array // цикл для сбора всех свечей в один массив if (string.IsNullOrWhiteSpace(ConvertedFormula)) { return; } string nameArray = Calculate(ConvertedFormula); if (_valuesToFormula != null && !string.IsNullOrWhiteSpace(nameArray)) { ValueSave val = _valuesToFormula.Find(v => v.Name == nameArray); if (val != null) { Candles = val.ValueCandles; if (Candles.Count > 1 && Candles[Candles.Count - 1].TimeStart == Candles[Candles.Count - 2].TimeStart) { Candles.RemoveAt(Candles.Count - 1); } _chartMaster.SetCandles(Candles); if (SpreadChangeEvent != null) { SpreadChangeEvent(Candles); } } } }
/// <summary> /// count an array of candles and a number / /// посчитать массив свечей и цифру /// </summary> private string ConcateCandleAndDecimal(string valOne, string valTwo, string sign) { List <Candle> candlesOne = null; if (valOne[0] == 'A') { int iOne = Convert.ToInt32(valOne.Split('A')[1]); if (iOne >= Tabs.Count) { return(""); } candlesOne = Tabs[iOne].Candles(true); if (candlesOne == null) { return(valOne); } } if (candlesOne == null) { ValueSave value = _valuesToFormula.Find(v => v.Name == valOne); if (value == null) { return(""); } candlesOne = value.ValueCandles; } decimal valueTwo = Convert.ToDecimal(valTwo); string znak = ""; if (sign == "+") { znak = "plus"; } else if (sign == "-") { znak = "minus"; } else if (sign == "*") { znak = "multiply"; } else if (sign == "/") { znak = "devide"; } ValueSave exitVal = _valuesToFormula.Find(val => val.Name == "B" + valOne + znak + valTwo); if (exitVal == null) { exitVal = new ValueSave(); exitVal.Name = "B" + valOne + znak + valTwo; exitVal.ValueCandles = new List <Candle>(); _valuesToFormula.Add(exitVal); } List <Candle> exitCandles = exitVal.ValueCandles; int lastOper = -1; if (exitCandles.Count != 0 && candlesOne[candlesOne.Count - 1].TimeStart == exitCandles[exitCandles.Count - 1].TimeStart) { // need to update only the last candle // надо обновить только последнюю свечу lastOper = 1; exitCandles[exitCandles.Count - 1] = (GetCandle(exitCandles[exitCandles.Count - 1], candlesOne[candlesOne.Count - 1], valueTwo, sign)); } else if (exitCandles.Count != 0 && candlesOne[candlesOne.Count - 2].TimeStart == exitCandles[exitCandles.Count - 1].TimeStart) { lastOper = 2; // need to add one candle // нужно добавить одну свечу exitCandles.Add(GetCandle(null, candlesOne[candlesOne.Count - 1], valueTwo, sign)); } else { lastOper = 3; // need to update everything // обновить нужно всё int indexStartFirst = 0; for (int i1 = candlesOne.Count - 1; exitCandles.Count != 0 && i1 > -1; i1--) { if (candlesOne[i1].TimeStart <= exitCandles[exitCandles.Count - 1].TimeStart && indexStartFirst == 0) { indexStartFirst = i1 + 1; break; } } for (int i1 = indexStartFirst; i1 < candlesOne.Count; i1++) { exitCandles.Add(GetCandle(null, candlesOne[i1], valueTwo, sign)); } exitVal.ValueCandles = exitCandles; } for (int i = 0; i < exitVal.ValueCandles.Count; i++) { if (exitVal.ValueCandles[i] == null) { } } return(exitVal.Name); }
/// <summary> /// count arrays of candles / /// посчитать массивы свечей /// </summary> private string ConcateCandles(string valOne, string valTwo, string sign) { // take the first value // берём первое значение List <Candle> candlesOne = null; if (valOne[0] == 'A') { int iOne = Convert.ToInt32(valOne.Split('A')[1]); if (iOne >= Tabs.Count) { return(""); } candlesOne = Tabs[iOne].Candles(true); } if (candlesOne == null) { ValueSave value = _valuesToFormula.Find(v => v.Name == valOne); if (value == null) { return(""); } candlesOne = value.ValueCandles; } // take the second value // берём второе значение List <Candle> candlesTwo = null; if (valTwo[0] == 'A') { int iOne = Convert.ToInt32(valTwo.Split('A')[1]); if (iOne >= Tabs.Count) { return(""); } candlesTwo = Tabs[iOne].Candles(true); } if (candlesTwo == null) { ValueSave value = _valuesToFormula.Find(v => v.Name == valTwo); if (value == null) { return(""); } candlesTwo = value.ValueCandles; } // take outgoing value // берём исходящее значение string znak = ""; if (sign == "+") { znak = "plus"; } else if (sign == "-") { znak = "minus"; } else if (sign == "*") { znak = "multiply"; } else if (sign == "/") { znak = "devide"; } ValueSave exitVal = _valuesToFormula.Find(val => val.Name == "B" + valOne + znak + valTwo); if (exitVal == null) { exitVal = new ValueSave(); exitVal.Name = "B" + valOne + znak + valTwo; exitVal.ValueCandles = new List <Candle>(); _valuesToFormula.Add(exitVal); } List <Candle> exitCandles = exitVal.ValueCandles; if (exitCandles.Count != 0 && candlesOne[candlesOne.Count - 1].TimeStart == candlesTwo[candlesTwo.Count - 1].TimeStart && candlesOne[candlesOne.Count - 1].TimeStart == exitCandles[exitCandles.Count - 1].TimeStart) { // need to update only the last candle // надо обновить только последнюю свечу exitCandles[exitCandles.Count - 1] = (GetCandle(exitCandles[exitCandles.Count - 1], candlesOne[candlesOne.Count - 1], candlesTwo[candlesTwo.Count - 1], sign)); } else if (exitCandles.Count != 0 && candlesOne[candlesOne.Count - 1].TimeStart == candlesTwo[candlesTwo.Count - 1].TimeStart && candlesOne[candlesOne.Count - 2].TimeStart == exitCandles[exitCandles.Count - 1].TimeStart) { // need to add one candle // нужно добавить одну свечу exitCandles.Add(GetCandle(null, candlesOne[candlesOne.Count - 1], candlesTwo[candlesTwo.Count - 1], sign)); } else { // need to update everything // обновить нужно всё int indexStartFirst = 0; int indexStartSecond = 0; exitCandles = new List <Candle>(); for (int i = 1; i < candlesOne.Count; i++) { for (int i2 = 0; i2 < candlesTwo.Count; i2++) { if (candlesTwo[i2].TimeStart >= candlesOne[i].TimeStart) { indexStartFirst = i; indexStartSecond = i2; break; } } if (indexStartSecond != 0) { break; } } for (int i1 = indexStartFirst, i2 = indexStartSecond; i1 < candlesOne.Count && i2 < candlesTwo.Count; i2++, i1++) { if (candlesOne[i1] == null) { candlesOne.RemoveAt(i1); i2--; i1--; continue; } if (candlesTwo[i2] == null) { candlesTwo.RemoveAt(i2); i2--; i1--; continue; } Candle candleOne = candlesOne[i1]; Candle candleTwo = candlesTwo[i2]; try { if (candlesOne[i1].TimeStart == candlesTwo[i2].TimeStart) { exitCandles.Add(GetCandle(null, candlesOne[i1], candlesTwo[i2], sign)); } else if (candlesOne[i1].TimeStart > candlesTwo[i2].TimeStart) { i1--; } else if (candlesOne[i1].TimeStart < candlesTwo[i2].TimeStart) { i2--; } } catch (Exception e) { } } exitVal.ValueCandles = exitCandles; } return(exitVal.Name); }
/// <summary> /// count number and array / /// посчитать цифру и массив /// </summary> private string ConcateDecimalAndCandle(string valOne, string valTwo, string sign) { // take the first value // берём первое значение decimal valueOne = Convert.ToDecimal(valOne); // take the second value // берём второе значение List <Candle> candlesTwo = null; if (valTwo[0] == 'A') { int iOne = Convert.ToInt32(valTwo.Split('A')[1]); candlesTwo = Tabs[iOne].Candles(true); } if (candlesTwo == null) { ValueSave value = _valuesToFormula.Find(v => v.Name == valTwo); if (value == null) { return(""); } candlesTwo = value.ValueCandles; } // take outgoing value // берём исходящее значение string znak = ""; if (sign == "+") { znak = "plus"; } else if (sign == "-") { znak = "minus"; } else if (sign == "*") { znak = "multiply"; } else if (sign == "/") { znak = "devide"; } ValueSave exitVal = _valuesToFormula.Find(val => val.Name == "B" + valOne + znak + valTwo); if (exitVal == null) { exitVal = new ValueSave(); exitVal.Name = "B" + valOne + znak + valTwo; exitVal.ValueCandles = new List <Candle>(); _valuesToFormula.Add(exitVal); } List <Candle> exitCandles = exitVal.ValueCandles; if (exitCandles.Count != 0 && candlesTwo[candlesTwo.Count - 1].TimeStart == exitCandles[exitCandles.Count - 1].TimeStart) { // need to update only the last candle // надо обновить только последнюю свечу exitCandles[exitCandles.Count - 1] = (GetCandle(exitCandles[exitCandles.Count - 1], valueOne, candlesTwo[candlesTwo.Count - 1], sign)); } else if (exitCandles.Count != 0 && candlesTwo[candlesTwo.Count - 2].TimeStart == exitCandles[exitCandles.Count - 1].TimeStart) { // need to add one candle // нужно добавить одну свечу exitCandles.Add(GetCandle(null, valueOne, candlesTwo[candlesTwo.Count - 1], sign)); } else { // need to update everything // обновить нужно всё int indexStartSecond = 0; for (int i2 = candlesTwo.Count - 1; exitCandles.Count != 0 && i2 > -1; i2--) { if (candlesTwo[i2].TimeStart <= exitCandles[exitCandles.Count - 1].TimeStart && indexStartSecond == 0) { indexStartSecond = i2 + 1; break; } } for (int i2 = indexStartSecond; i2 < candlesTwo.Count; i2++) { exitCandles.Add(GetCandle(null, valueOne, candlesTwo[i2], sign)); } exitVal.ValueCandles = exitCandles; } return(exitVal.Name); }
/// <summary> /// посчитать массив свечей и цифру /// </summary> private string ConcateCandleAndDecimal(string valOne, string valTwo, string sign) { // берём первое значение List <Candle> candlesOne = null; if (valOne[0] == 'A') { int iOne = Convert.ToInt32(valOne.Split('A')[1]); candlesOne = Tabs[iOne].Candles(true); if (candlesOne == null) { return(valOne); } } if (candlesOne == null) { ValueSave value = _valuesToFormula.Find(v => v.Name == valOne); if (value == null) { return(""); } candlesOne = value.ValueCandles; } // берём второе значение decimal valueTwo = Convert.ToDecimal(valTwo); // берём исходящее значение string znak = ""; if (sign == "+") { znak = "plus"; } else if (sign == "-") { znak = "minus"; } else if (sign == "*") { znak = "multiply"; } else if (sign == "/") { znak = "devide"; } ValueSave exitVal = _valuesToFormula.Find(val => val.Name == "B" + valOne + znak + valTwo); if (exitVal == null) { exitVal = new ValueSave(); exitVal.Name = "B" + valOne + znak + valTwo; exitVal.ValueCandles = new List <Candle>(); _valuesToFormula.Add(exitVal); } List <Candle> exitCandles = exitVal.ValueCandles; if (exitCandles.Count != 0 && candlesOne[candlesOne.Count - 1].TimeStart == exitCandles[exitCandles.Count - 1].TimeStart) { // надо обновить только последнюю свечу exitCandles[exitCandles.Count - 1] = (GetCandle(exitCandles[exitCandles.Count - 1], candlesOne[candlesOne.Count - 1], valueTwo, sign)); } else if (exitCandles.Count != 0 && candlesOne[candlesOne.Count - 2].TimeStart == exitCandles[exitCandles.Count - 1].TimeStart) { // нужно добавить одну свечу exitCandles.Add(GetCandle(null, candlesOne[candlesOne.Count - 1], valueTwo, sign)); } else { // обновить нужно всё int indexStartFirst = 0; for (int i1 = candlesOne.Count - 1; exitCandles.Count != 0 && i1 > -1; i1--) { if (candlesOne[i1].TimeStart <= exitCandles[exitCandles.Count - 1].TimeStart && indexStartFirst == 0) { indexStartFirst = i1 + 1; break; } } for (int i1 = indexStartFirst; i1 < candlesOne.Count; i1++) { exitCandles.Add(GetCandle(null, candlesOne[i1], valueTwo, sign)); } exitVal.ValueCandles = exitCandles; } return(exitVal.Name); }
/// <summary> /// new data came from the connector / /// из коннектора пришли новые данные /// </summary> private void BotTabIndex_NewCandlesChangeEvent(List <Candle> candles) { LastTimeCandleUpdate = DateTime.Now; for (int i = 0; i < Tabs.Count; i++) { List <Candle> myCandles = Tabs[i].Candles(true); if (myCandles == null || myCandles.Count < 10) { return; } } DateTime time = Tabs[0].Candles(true)[Tabs[0].Candles(true).Count - 1].TimeStart; for (int i = 0; i < Tabs.Count; i++) { List <Candle> myCandles = Tabs[i].Candles(true); if (myCandles[myCandles.Count - 1].TimeStart != time) { return; } } //loop to collect all the candles in one array // цикл для сбора всех свечей в один массив if (string.IsNullOrWhiteSpace(ConvertedFormula)) { return; } string nameArray = Calculate(ConvertedFormula); if (_valuesToFormula != null && !string.IsNullOrWhiteSpace(nameArray)) { ValueSave val = _valuesToFormula.Find(v => v.Name == nameArray); if (val != null) { Candles = val.ValueCandles; if (Candles.Count > 1 && Candles[Candles.Count - 1].TimeStart == Candles[Candles.Count - 2].TimeStart) { try { Candles.RemoveAt(Candles.Count - 1); } catch { // ignore } } if (_startProgram == StartProgram.IsOsTrader && Tabs.Count > 0) { var candlesToKeep = ((OsEngine.Market.Servers.AServer)Tabs[0].MyServer)._neadToSaveCandlesCountParam.Value; var needToRemove = ((OsEngine.Market.Servers.AServer)Tabs[0].MyServer)._needToRemoveCandlesFromMemory.Value; if (needToRemove && Candles[Candles.Count - 1].TimeStart.Minute % 15 == 0 && Candles[Candles.Count - 1].TimeStart.Second == 0 && Candles.Count > candlesToKeep) { Candles.RemoveRange(0, Candles.Count - 1 - candlesToKeep); } } _chartMaster.SetCandles(Candles); if (SpreadChangeEvent != null) { SpreadChangeEvent(Candles); } } } }