However, my strategy is executing this with a delay of 1 bar for some reason, leading to a wrong "decision" in the screenshot, as the price retracts below VWAP, triggering the Short position. In other words in the screenshot, the trade opened short when the signal should have triggered a long position.
The tricky part was that during that Green candle, I still had an open position that got stopped out with a profit. Could that be the reason no new trade was allowed to be entered after the bar closed?
As I am not a developer, I just collected code to do what I want and thought it worked well... However, in this specific case I found that it works with a delay which causes the strategy to take the position for the wrong direction.
/// <summary> /// check if entry is allowed for actual bar /// </summary> /// <returns>true if entry is allowed</returns> private Boolean IsValidTime() { bool onBarClose = (State == State.Historical || Calculate == Calculate.OnBarClose); bool enabled = enabled = (tzsMON_THU.InSession(Time[0], onBarClose) == 0); DateTime timeTZ = tzsMON_THU.ActualBarTZ; switch( timeTZ.DayOfWeek ) { case DayOfWeek.Saturday: break; case DayOfWeek.Sunday: break; case DayOfWeek.Friday: enabled = (tzsFRI.InSession(Time[0], onBarClose) == 0); break; default: break; } if (!enabled) Printf("Time filter timeTZ={0} {1}", timeTZ, timeTZ.DayOfWeek); return enabled; } protected override void OnBarUpdate() { if (BarsInProgress != 0) return; if (CurrentBars[0] < 1) return; try { CheckEntry(); } catch( Exception e) { Printf(e.Message); base.Print(e.StackTrace); throw e; } } private void CheckEntry() { if (!trades.Update()) { lastTrade = null; } // Set 1 if ( // entry diretion EntryDirection >= 0 // cross above VWAP &&((Close[0] > VWAP81[0]) && trades.BarsSinceEntryExecution > 10 // check bars since last entry { if( lastTrade == null ) { lastTrade = new StrategyTrade(this); trades.Add(lastTrade); } lastTrade.EnterLongLimit( Close[0] - TickSize * Long_Negative_Offset_Arithmetic ); }
Thanks for your help in advance!
Comment