public void SetTF(EnmTF tf) { TF = tf; if (TF == EnmTF.M1) { DateTF = CUtilTime.NormalizeSeconds(Date); } else if (TF == EnmTF.M5) { DateTF = CUtilTime.NormalizeToM5(Date); } else if (TF == EnmTF.M15) { DateTF = CUtilTime.NormalizeToM15(Date); } else if (TF == EnmTF.M30) { DateTF = CUtilTime.NormalizeToM30(Date); } else if (TF == EnmTF.H1) { DateTF = CUtilTime.NormalizeHour(Date); } else if (TF == EnmTF.D1) { DateTF = CUtilTime.NormalizeDay(Date); } else { DateTF = Date; } }
public void SetSessionBeginEnd(Dictionary <string, object> data) { DtSessionBegin = (DateTime)data["DtBegin"]; DtSessionEnd = (DateTime)data["DtEnd"]; //TODO get from DB (and set to it previously) //this is for work for demo and real FORTS //but values are not correct now DtEveSessionBegin = DtSessionBegin; if (_useRealServer) { DtDaySessionBegin = CUtilTime.NormalizeDay(DtSessionEnd).AddHours(9).AddMinutes(0); } else { DtDaySessionBegin = CUtilTime.NormalizeDay(DtSessionEnd).AddHours(7).AddMinutes(0); } DtEveSessionEnd = CUtilTime.NormalizeDay(DtEveSessionBegin).AddHours(23).AddMinutes(45); DtDaySessionEnd = DtSessionEnd; }
public bool IsNewData(CRawDeal rd) { DateTime rd_date = CUtilTime.NormalizeDay(rd.Moment.Date); if (!this.ContainsKey("M1")) { return(true); } if (!this["M1"].ContainsKey(rd_date)) { return(true); } if (this["M1"][rd_date].ListTimeFrameInfo.Count == 0) { return(true); } DateTime dt = this["M1"][rd_date].ListTimeFrameInfo.Last().Dt;//.AddMinutes(1); if (rd.Moment > dt) { return(true); } return(false); }
private bool RetrieveInstTF(string buttName, ref string isin, ref string tf, ref string stDt) { Regex reg = new Regex(@"([\w0-9\-\.]+)_([\w0-9]+)"); Match m = reg.Match(buttName); if (m.Groups.Count > 2) { isin = Convert.ToString(m.Groups[1]); tf = Convert.ToString(m.Groups[2]); DateTime dt = Plaza2Connector.ServerTime; stDt = CUtilTime.NormalizeDay(dt).ToString(); return(true); } return(false); }
private void AnalyzeDiskTFDays() { try { if (!m_dictTFArray.ContainsKey(EnmTF.H1.ToString())) { return; } foreach (KeyValuePair <DateTime, CTimeFrameArray> kvp in m_dictTFArray[EnmTF.H1.ToString()]) //all dates of low TF array { try { CTimeFrameArray M_low_TF_Array = kvp.Value; DateTime dt = CUtilTime.NormalizeDay(M_low_TF_Array.ListTimeFrameInfo[0].Dt.Date); if (m_dictTFArray.IsContainTimeFrameInfo(EnmTF.D1, dt)) { continue; } CTimeFrameInfo ntfi = m_dictTFArray.GetNewTimeFrameInfo(m_isin, EnmTF.D1, dt); Analyze_D1(dt); } catch (Exception e) { } } } catch (Exception e) { Error("AnalyzeDiskTFDays", e); } }
public CTimeFrameInfo GetTFIByDate(string stTF, DateTime dt) { //DateTime dt = CUtil.NormalizeDay(Plaza2Connector.ServerTime); return(m_dictTFArray[stTF][CUtilTime.NormalizeDay(dt)].ListTimeFrameInfo.GetTFIByDate(dt)); }
private void AnalyzeOnlineM1(CRawDeal rd, CRawDeal prevDeal) { DateTime dtTill = rd.Moment.AddSeconds(-rd.Moment.Second); dtTill = dtTill.AddMilliseconds(-dtTill.Millisecond); if (!m_dictTFArray.IsContainTimeFrameInfo(EnmTF.M1, dtTill)) { m_dictTFArray.AddNewTimeFrameInfo(m_isin, EnmTF.M1, dtTill, this); } CTimeFrameInfo tfi = m_dictTFArray.GetLastTimeFrameInfo(EnmTF.M1); DateTime currMoment = rd.Moment; CRawDeal currRd = rd; //changed 2016/08/01 //only if changed extremum do recalc bool bChangedExtr = false; if (rd.ReplID > tfi.LastReplId) { tfi.LastReplId = rd.ReplID; tfi.OpenedPos = rd.Pos; tfi.Volume += rd.Amount; tfi.numOfDeals++; if (currRd.Price > tfi.HighPrice) { bChangedExtr = true;; tfi.HighPrice = currRd.Price; } if (currRd.Price < tfi.LowPrice) { bChangedExtr = true; tfi.LowPrice = currRd.Price; } tfi.LastUpdate = rd.Moment; if (!tfi.bProcessedData) { tfi.OpenPrice = rd.Price; tfi.bProcessedData = true; } tfi.ClosePrice = rd.Price; DateTime dtcnd = CUtilTime.NormalizeDay(dtTill); CheckTFIConsistent(tfi); // sw5.Stop(); //Plaza2Connector.GUIBox.GUICandleBox.UpdateCandle(this.m_isin, EnmTF.M1.ToString(), dtcnd.ToString(), tfi); Plaza2Connector.GUIBox.GUICandleBox.QueueTFinfo(this.m_isin, EnmTF.M1.ToString(), dtcnd.ToString(), tfi); } // TrapError(m_dictTFArray["M1"][CUtil.NormalizeDay(tfi.Dt)]); CheckDataOnline(rd); if (Plaza2Connector.IsDealsOnline) { //changed 2016/08/01 //only if changed extremum do recalc if (bChangedExtr) { TriggerRecalcAllBotsUpdateTF(EnmTF.M1, tfi); } DateTime dtTmp = Plaza2Connector.ServerTime; DateTime dtFrom = new DateTime(0); DateTime dtTo = new DateTime(0); CTimeFrameInfo tfiPrev = m_dictTFArray.GetPrevLastTimeFrameInfo(EnmTF.M1); if (CUtilTF.WasClose_M1_TF(prevDeal.Moment, rd.Moment)) { Log("M1 was closed prevDeal.Moment=" + prevDeal.Moment + " rd.Moment=" + rd.Moment); if (Plaza2Connector.IsAnalyzerTFOnline) { TriggerRecalcAllBotsChangedTF(EnmTF.M1, tfiPrev); } } } AnalyzeOnlineTF(CUtilTF./*(IsClosed_M5_M15_M30_TF*/ WasClosed_M5_M15_M30_TF, m_M5_scale, EnmTF.M5, EnmTF.M1, prevDeal, rd); AnalyzeOnlineTF(CUtilTF./*IsClosed_M5_M15_M30_TF*/ WasClosed_M5_M15_M30_TF, m_M15_scale, EnmTF.M15, EnmTF.M5, prevDeal, rd); AnalyzeOnlineTF(CUtilTF./*IsClosed_M5_M15_M30_TF*/ WasClosed_M5_M15_M30_TF, m_M30_scale, EnmTF.M30, EnmTF.M15, prevDeal, rd); AnalyzeOnlineTF(CUtilTF./*IsClosed_H1*/ WasClosed_H1, m_M30_scale, EnmTF.H1, EnmTF.M30, prevDeal, rd); AnalyzeOnlineTF(CUtilTF./*IsClosed_D1*/ WasClosed_D1, m_M30_scale, EnmTF.D1, EnmTF.H1, prevDeal, rd); CTimeFrameInfo TFinfo_D1 = m_dictTFArray.GetLastTimeFrameInfo(EnmTF.D1); LowDayPrice = TFinfo_D1.LowPrice; HighDayPrice = TFinfo_D1.HighPrice; }
private void AnalyzeOnlineTF(ChangedTF changedTF, List <int> lstScale, EnmTF TF_high, EnmTF TF_low, CRawDeal prevDeal, CRawDeal currDeal) { DateTime dtPrev = prevDeal.Moment; DateTime dtCurr = currDeal.Moment; //Get last high TF CTimeFrameInfo TFinfo_low = m_dictTFArray.GetLastTimeFrameInfo(TF_low); /* if (!TFinfo_low.bNotProcessedData) * return; */ DateTime dtFrom = new DateTime(0); DateTime dtTo = new DateTime(0); bool b_wasChangedTF = changedTF(prevDeal.Moment, currDeal.Moment, lstScale, ref dtFrom, ref dtTo); if (!m_dictTFArray.IsContainTimeFrameInfo(TF_high, /*dtFrom*/ dtTo)) { m_dictTFArray.AddNewTimeFrameInfo(m_isin, TF_high, /*dtFrom*/ dtTo, this); } CTimeFrameInfo TFinfo_low_prev = m_dictTFArray.GetPrevLastTimeFrameInfo(TF_low); CTimeFrameInfo TFinfo_high_prev = m_dictTFArray.GetPrevLastTimeFrameInfo(TF_high); CTimeFrameInfo TFinfo_high = m_dictTFArray.GetLastTimeFrameInfo(TF_high); bool bChangedExtr = false; if (currDeal.ReplID > TFinfo_high.LastReplId) { TFinfo_high.numOfDeals++; TFinfo_high.Volume += currDeal.Amount; TFinfo_high.OpenedPos = currDeal.Pos; //changed 2016/08/01 //only if changed extremum do recalc if (TFinfo_high.HighPrice < TFinfo_low.HighPrice) { TFinfo_high.HighPrice = currDeal.Price; bChangedExtr = true; } if (TFinfo_high.LowPrice > TFinfo_low.LowPrice) { TFinfo_high.LowPrice = currDeal.Price; bChangedExtr = true; } TFinfo_high.LastReplId = currDeal.ReplID; TFinfo_high.LastUpdate = DateTime.Now; if (!TFinfo_high.bProcessedData) { TFinfo_high.OpenPrice = TFinfo_low.OpenPrice; TFinfo_high.bProcessedData = true; } //KAA 2015-12-23 //because low TF was already updated // if (!b_wasChangedTF) TFinfo_high.ClosePrice = TFinfo_low.ClosePrice; // else // TFinfo_high.ClosePrice = TFinfo_low_prev.ClosePrice; //TFinfo_low.ClosePrice; DateTime dtcnd = CUtilTime.NormalizeDay(dtFrom); // Plaza2Connector.GUIBox.GUICandleBox.UpdateCandle(this.m_isin, TF_high.ToString(), dtcnd.ToString(), TFinfo_high); Plaza2Connector.GUIBox.GUICandleBox.QueueTFinfo(this.m_isin, TF_high.ToString(), dtcnd.ToString(), TFinfo_high); //changed 2016/08/01 //only if changed extremum do recalc if (bChangedExtr) { TriggerRecalcAllBotsUpdateTF(TF_high, TFinfo_high); } if (b_wasChangedTF) { Log(TF_high.ToString() + " TFinfo_high.Dt=" + TFinfo_high.Dt.ToString() + " was closed prevDeal.Moment=" + prevDeal.Moment + " currDeal.Moment=" + currDeal.Moment + " TFinfo_high.ClosePrice=" + TFinfo_high.ClosePrice + " TFinfo_low_prev.ClosePrice=" + TFinfo_low_prev.ClosePrice + " TFinfo_low_prev.Dt =" + TFinfo_low_prev.Dt); if (Plaza2Connector.IsDealsOnline && Plaza2Connector.IsAnalyzerTFOnline) { TriggerRecalcAllBotsChangedTF(TF_high, TFinfo_high_prev); } } } else { } // TrapError(m_dictTFArray[TF_high.ToString()][CUtil.NormalizeDay(dtFrom)]); int tmp = 1; }
private void AnalyzeDiskTF(ChangedTF changedTF, List <int> lstScale, EnmTF TF_high, EnmTF TF_low) { try { foreach (KeyValuePair <DateTime, CTimeFrameArray> kvp in m_dictTFArray[TF_low.ToString()]) //all dates of low TF array { if (CUtilTime.OlderThanTwoWorkDays(kvp.Key)) { continue; } CTimeFrameArray M_low_TF_Array = kvp.Value; for (int i = 1; i < M_low_TF_Array.ListTimeFrameInfo.Count; i++) //each TF array { DateTime dtPrev = M_low_TF_Array.ListTimeFrameInfo[i - 1].Dt; DateTime dtCurr = M_low_TF_Array.ListTimeFrameInfo[i].Dt; DateTime dtFrom = new DateTime(0); DateTime dtTo = new DateTime(0); if (changedTF(dtPrev, dtCurr, lstScale, ref dtFrom, ref dtTo)) { //TO DO chek prev day etc if (m_dictTFArray.IsContainTimeFrameInfo(TF_high, dtFrom)) { continue; //if already exists in high TF array than nothing to do and continue } //exp logics CTimeFrameInfo ntfi = null; if (m_dictTFArray.GetLatestTFI(TF_high.ToString()) != null) { DateTime dtLast = (m_dictTFArray.GetLatestTFI(TF_high.ToString())).Dt; if (dtLast > dtFrom) { ntfi = m_dictTFArray.GetNewTFIPuttingtoWritePlace(m_isin, TF_high, dtFrom); //Error("Inserting data. TO DO check and remove"); } else { ntfi = m_dictTFArray.GetNewTimeFrameInfo(m_isin, TF_high, dtFrom); } } else { ntfi = m_dictTFArray.GetNewTimeFrameInfo(m_isin, TF_high, dtFrom); } int j = i - 1; //note: the last pos ntfi.OpenedPos = M_low_TF_Array.ListTimeFrameInfo[j].OpenedPos; ntfi.ClosePrice = M_low_TF_Array.ListTimeFrameInfo[j].ClosePrice; while (j >= 0 && M_low_TF_Array.ListTimeFrameInfo[j].Dt >= dtFrom) { CTimeFrameInfo currtfi = M_low_TF_Array.ListTimeFrameInfo[j]; ntfi.numOfDeals += currtfi.numOfDeals; ntfi.Volume += currtfi.Volume; if (ntfi.HighPrice < currtfi.HighPrice) { ntfi.HighPrice = currtfi.HighPrice; } if (ntfi.LowPrice > currtfi.LowPrice) { ntfi.LowPrice = currtfi.LowPrice; } ntfi.OpenPrice = M_low_TF_Array.ListTimeFrameInfo[j].OpenPrice; j--; //backward } DateTime dtcnd = CUtilTime.NormalizeDay(dtFrom); //no need ? check ! CheckTFIConsistent(ntfi); } } //TrapError(kvp.Value); } } catch (Exception e) { Error("AnalyzeDiskTF", e); } }