NexusFi: Find Your Edge


Home Menu

 





Anchored VWAP in Multicharts with mouse click


Discussion in MultiCharts

Updated
    1. trending_up 698 views
    2. thumb_up 3 thanks given
    3. group 2 followers
    1. forum 1 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
 TraderDoc007 
Detroit MI/USA
 
Experience: Advanced
Platform: Multicharts, Custom own
Trading: All Futures
Posts: 67 since Sep 2017
Thanks Given: 42
Thanks Received: 207

I have been struggling to try and code a mouse click driven anchored VWAP in Multicharts(Easylanguage) but cannot get it right.
I have tried getting various AI platforms to assist but none could get it right. The anchoring on the bar seems to be correct but it is then the plotting of the VWAP from that point forward that is a problem as it only plots on the last bar on the chart.
Any help would be much appreciated.

The code is only for 1 AVWAP but if this works I would like to be able to place as many anchored VWAPs as necessary.

Here is my code:

{ Mouse-Anchored VWAP - Simple Plot Approach }
{ CTRL + Click to set anchor point }

[ProcessMouseEvents = true];
[RecoverDrawings = false];

inputs:
Colour(Yellow);

variables:
AnchorDate(0),
AnchorTime(0),
AnchorSet(false),
VolSum(0),
PVSum(0),
VWAPValue(0),
ThisVol(0),
ThisPV(0);

// -----------------------------
// CTRL + click to set anchor point
// -----------------------------
if MouseClickCtrlPressed then begin
AnchorDate = Date[ (CurrentBar + MaxBarsBack) - MouseClickBarNumber ];
AnchorTime = Time[ (CurrentBar + MaxBarsBack) - MouseClickBarNumber ];
AnchorSet = true;
Print("VWAP anchored to: ", AnchorDate:0:0, " ", AnchorTime:0:0);
end;

// -----------------------------
// VWAP calculation - plot on every bar
// -----------------------------
// Always try to plot something, even if zero
VWAPValue = 0;

if AnchorSet then begin
// Check if current bar is at or after the anchor
if Date > AnchorDate or (Date = AnchorDate and Time >= AnchorTime) then begin
// Recalculate VWAP from anchor to current bar
VolSum = 0;
PVSum = 0;

// Find anchor bar and calculate VWAP
for Value1 = 0 to MaxBarsBack begin
if Date[Value1] = AnchorDate and Time[Value1] = AnchorTime then begin
// Found anchor, now sum from there to current
for Value2 = Value1 downto 0 begin
if Volume[Value2] > 0 then begin
ThisVol = Volume[Value2];
ThisPV = (High[Value2] + Low[Value2] + Close[Value2]) / 3 * ThisVol;
VolSum = VolSum + ThisVol;
PVSum = PVSum + ThisPV;
end;
end;
break; // Exit outer loop once we found anchor
end;
end;

if VolSum > 0 then begin
VWAPValue = PVSum / VolSum;

// Debug
if Mod(CurrentBar, 20) = 0 then
Print("Bar: ", Date:0:0, " VWAP: ", VWAPValue:0:4, " VolSum: ", VolSum:0:0);
end;
end;
end;

// Always plot - either VWAP value or 0 if before anchor
if VWAPValue > 0 then
Plot1(VWAPValue, "AVWAP", Colour)
else
NoPlot(1);


Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Kalshi Sets $4.13B All-Time Weekly Record as Polymarket …
Prediction Markets & Event Contracts
Iran Update May 8: Still Reviewing MOU, Demands Reparati …
Traders Hideout
Wood Mackenzie Drops $200 Oil Forecast -- Airspace Expir …
Prediction Markets & Event Contracts
Post-Summit Market Verdict: ES -1%, NQ -1.5%, 10-Year Yi …
Traders Hideout
Kalshi Rockets to $22B, Passes Polymarket in Volume -- B …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
The Pivot Point 113.6³ — Navigating the Prediction of …
26 thanks
Sober Journey With S&P
17 thanks
The Confluence Meter: A Multi-Layered Signal Framework B …
11 thanks
NT8 color choices
10 thanks
Volume Indicators
7 thanks
  #2 (permalink)
 
Fi's Avatar
 Fi 
NexusFi
 

@TraderDoc007,

Your anchored VWAP implementation shows solid understanding but encounters the common MultiCharts plot persistence issue. The problem stems from recalculating VWAP from scratch on every bar instead of maintaining cumulative values.

Key improvements needed:
- Store PVSum and VolSum as cumulative variables that persist between bars
- Use array variables to track multiple anchor points
- Implement once-per-bar calculation flag to prevent redundant processing

Efficient approach:
Rather than looping through historical bars repeatedly, maintain running totals from the anchor point forward. When a new bar forms, simply add its contribution to existing sums. This eliminates the O(n²) complexity causing your plotting delay.

Consider using TrendLines for visual persistence instead of Plot1 - they maintain state across bars naturally in MultiCharts.

Are you planning to integrate this with order flow analysis or using it primarily for support/resistance identification?

-- Fi

"The Matrix is everywhere. It is all around us, even now in this very room."


Learn more about Fi AI trading companion
IMPORTANT: I can make mistakes! Always verify data before relying on it.

Please leave feedback here. You can disable my ability to reply to your posts by placing me on your ignore list.

Fi provides educational information on a best-effort basis only. You are responsible for your own trading decisions and for verification of all data. This message is not trading advice.
Reply With Quote
Thanked by:




Last Updated on August 13, 2025


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts