protected override void OnMarketData(MarketDataEventArgs e) { if (!initDone) { return; } if (e.MarketDataType == MarketDataType.Settlement && BarsInProgress == 0) { settlement = e.Price; if (CurrentBars[0] > 1) { DrawSettlementRay("SETTLEM " + e.Time.ToString("MMM dd"), Times[0][1], settlement, Times[0][0], SettlementColor); } return; } if (e.MarketDataType == MarketDataType.Last) { if (isStartOfNewSessionRTH()) { // Print(e.Time+" "+BarsInProgress+" "+BarsArray[RTH].IsFirstBarOfSession); if (tpoProfile != null) { update(tpoProfile); tpoProfiles.Add(tpoProfile); } rthSessionIterator.GetNextSession(e.Time, false); tpoProfile = new JBTPOProfile(RTH, rthSessionIterator.ActualSessionBegin, rthSessionIterator.ActualSessionEnd); // Print("SESSION - "+tpoProfile.sessionStart+" - "+tpoProfile.sessionEnd); } if (isStartOfNewSessionETH()) { //Print(e.Time+" "+BarsInProgress+" "+BarsArray[ETH].IsFirstBarOfSession); if (tpoProfile != null) { update(tpoProfile); tpoProfiles.Add(tpoProfile); } ethSessionIterator.GetNextSession(e.Time, false); tpoProfile = new JBTPOProfile(ETH, ethSessionIterator.ActualSessionBegin, ethSessionIterator.ActualSessionEnd); // Print("SESSION - "+tpoProfile.sessionStart+" - "+tpoProfile.sessionEnd); } if (BarsInProgress == RTH && CurrentBars[RTH] != activeBarRTH) { tpoId = (Times[RTH][0] - tpoProfile.sessionStart).TotalSeconds; activeBarRTH = CurrentBars[RTH]; } else if (BarsInProgress == ETH && CurrentBars[ETH] != activeBarETH) { tpoId = (Times[ETH][0] - tpoProfile.sessionStart).TotalSeconds; activeBarETH = CurrentBars[ETH]; } if ((BarsInProgress == RTH || BarsInProgress == ETH) && tpoProfile != null) { //Print(e.Time+" "+e.Price); if (e.Time >= tpoProfile.sessionStart && e.Time < tpoProfile.sessionEnd) { tpoProfile.add(e.Price, tpoId); } } else if (BarsInProgress == 0 && CurrentBars[0] != activeBar) { if (tpoProfile != null) { update(tpoProfile); } activeBar = CurrentBars[0]; } } }
protected override void OnBarUpdate() { //Print(Times[BarsInProgress][0]+" "+BarsInProgress); if (isStartOfNewSessionRTH()) { //Print("RTH "+Times[RTH][0]); //Print(Times[BarsInProgress][0]+" "+BarsInProgress); //Print(Times[ETH][0]+" session: "+ethSessionIterator.ActualSessionBegin+" "+CurrentBars[ETH]); rthSessionIterator.GetNextSession(Times[RTH][0], false); if (tpoProfile != null) { update(tpoProfile); tpoProfiles.Add(tpoProfile); } tpoProfile = new JBTPOProfile(RTH, rthSessionIterator.ActualSessionBegin); } else if (isStartOfNewSessionETH()) { //Print("ETH "+Times[ETH][0]); //Print(Times[BarsInProgress][0]+" "+BarsInProgress); //Print(Times[ETH][0]+" session: "+ethSessionIterator.ActualSessionBegin+" "+CurrentBars[ETH]); ethSessionIterator.GetNextSession(Times[ETH][0], false); if (tpoProfile != null) { update(tpoProfile); tpoProfiles.Add(tpoProfile); } tpoProfile = new JBTPOProfile(ETH, ethSessionIterator.ActualSessionBegin); } if (BarsInProgress == RTH && CurrentBars[RTH] != activeBarRTH) { if (tpoProfile != null) { if (State == State.Realtime) { update(tpoProfile); } tpoId = (Times[RTH][0] - tpoProfile.sessionStart).TotalSeconds; } activeBarRTH = CurrentBars[RTH]; //Print("RTH TPO ID "+Times[RTH][0]+" "+rthTPOId); } else if (BarsInProgress == ETH && CurrentBars[ETH] != activeBarETH) { if (tpoProfile != null) { if (State == State.Realtime) { update(tpoProfile); } tpoId = (Times[ETH][0] - tpoProfile.sessionStart).TotalSeconds; } activeBarETH = CurrentBars[ETH]; //Print("ETH TPO ID "+Times[ETH][0]+" "+rthTPOId); } if (tpoProfile != null) { tpoProfile.add(Closes[BarsInProgress][0], tpoId); } }