Hello AFL programmers:
Here is a code to plot an array that is recalculated every Day Time intervals (in this case VWAP) .
When I change intervals to intraday it Plots array changing every Day.
I would like to actually plot VWAP recalculating every X Days or every X Hours or Every X Minutes independent on timeframe used.
Example1: In timeframe 1 Hour would like to plot VWAP recalculating every 3 Days.
Example2: In timeframe 1 Min would like to plot VWAP recalculating every 30 Minutes.
With this code I can plot VWAP recalculating every Month, Day, Hour or Minute because a function is provided by Amibroker. I just assign variables: NewMonth or NewDay or NewHour or NewMin to "NewTimeUnitChanged".
Example Goal = How do I detect 3 Days changing and assign to "NewTimeUnitChanged".
Example Goal = How do I detect 30 Minutes changing and assign to "NewTimeUnitChanged".
My problem with this code is not about the VWAP array. The problem is more of how to recalculate VWAP every 3 Days or 30 Minutes, etc..
Any help will be appreciated.
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
Plot( C, "", colorDefault, styleCandle );
//==============================================================
// VWAP
//==============================================================
//Get diferent Time Units Changes
NewMonth = Month() != Ref(Month(), -1);
NewDay = Day() != Ref(Day(), -1);
NewHour = Hour() != Ref(Hour(), -1);
NewMin = Minute() != Ref(Minute(), -1);
NewTimeUnitChanged = NewDay;
//VWAP starts every interval of time in var = NewTimeUnitChanged
Bars_so_far_today = 1 + BarsSince( NewTimeUnitChanged);
TodayVolume = Sum(V,Bars_so_far_today);
VWAP = Sum (C * V, Bars_so_far_today ) / TodayVolume;
Plot (VWAP,"VWAP",colorYellow, styleThick);
// Mark when Time Unit changed
Value1=0;
Value1 = ValueWhen(NewTimeUnitChanged, C);
Value1 = IIf(Value1!=0,Value1,Ref(Value1,-1));
Plot (Value1,"",colorWhite, styleline);