Server Time vs. Local Time: This calculates the session from your broker's midnight (server time). If your broker operates on a standard New York close schedule (EET/EST structure), this aligns perfectly out of the box.
Tick Volume Integration: It uses tick_volume[] naturally. Because it resets strictly at the day flip, it prevents historical tick data from skewing the active session valuation.
Array Formatting: The prev_calculated logic handles tick-by-tick updates efficiently. During active market hours, the for loop only executes on the current index i, updating the running Welford totals in milliseconds.
Translating this to cTrader requires a fundamental architectural shift. Because cTrader’s Calculate(int index) method executes on every single tick for the active bar, using global variables for Welford’s running totals (like we did in MQL5) will double-count the current bar's volume thousands of times.
To make the calculation idempotent, this C# implementation stores the cumulative running totals inside IndicatorDataSeries. This ensures that tick-by-tick updates recalculate safely from the previous bar's finalized state without corrupting the math.
Idempotent Ticks: Because _sumVol[index] and _S[index] fetch their baseline from index - 1, the current bar can update 10,000 times during an active 1-minute candle without breaking the cumulative session variance.
Time Zones: The indicator is decorated with TimeZone = TimeZones.UTC. This ensures the .Date rollover behaves consistently across different brokers. If you prefer the bands to reset exactly at the 5:00 PM EST New York close rather than midnight UTC, you can switch the timezone property to TimeZones.EasternStandardTime.
To automate this in cTrader, you build a cBot that hooks into the custom SessionVWAP_SDBands indicator we just wrote.
Because you want to trade a structural rejection rather than a blind touch, the logic must execute inside the OnBar method. This guarantees the 1-minute or 5-minute candle has officially closed, confirming the liquidity sweep (the wick) before committing capital.
Here is the C# implementation for the automated fade.
Indicator Referencing: Because SessionVWAP_SDBands is a custom indicator, the cBot cannot natively see it. In cTrader Automate, you must right-click your cBot, select Manage References, navigate to the Indicators tab, and check the box next to your VWAP indicator before this will compile.
The "Index 1" Shift: The OnBar event fires the millisecond a new candle opens. Therefore, the setup is evaluated on Bars.Count - 2 (the candle that just closed). If you evaluate Bars.Count - 1, you are reading the open price of the brand-new, empty candle.
Dynamic Targeting: The ExecuteMarketOrder method in cAlgo requires Stop Loss and Take Profit to be passed as pip distances, not absolute price levels. The code dynamically calculates the pip distance from the entry (the close of the rejection candle) to the sweep wick (SL) and the VWAP line (TP).
Built-in R:R Filter: The logic includes a hard filter if (tpDistancePips > slDistancePips). If the 2.5 SD band is sitting too close to the VWAP, or if the rejection wick is unusually massive, the risk-to-reward ratio inverts. The bot will automatically pass on the trade rather than risking 15 pips to make 4.
The band version is how I'd approach a fade too, with the target at the line and nothing beyond it.
One practical issue on FX: a session VWAP built from tick volume behaves oddly in the first half hour, because the anchor has so few bars behind it that the bands are narrow and every normal swing looks like 2 SD. I don't take fades off the bands until roughly an hour after the anchor. Before that the VWAP is still finding its level and the "extremes" aren't extremes.
The other thing I'd check is the day type. If VWAP itself has sloped steadily for the first two hours, a stretch to 2 SD is often just the trend, and fading it is the classic way to lose three times in a row. I only fade when the line is flattish, which in my experience means lunch and the quieter afternoons more than the London open.