Error in study alert rec usage is not allowed

M

MJJ3

New member
Hi,
I'm trying to create an alert that triggers when price crosses below the vwap. I keep getting the following error.

"rec usage is not allowed in this context"

I know this is due to my referencing a prior value but I don't know how to get around it. The thinkscript I am using is as follows.
Code:
close crosses below GtDailyVWAP()
Where the function GtDailyVWAP is:
Code:
def yyyyMmDd = GetYYYYMMDD();
def isPeriodRolled = if yyyyMmDd != yyyyMmDd[1] then 1 else 0;

def volumeSum;
def volumeVwapSum;
def volumeSumPrev;
def volumeVwapSumPrev;

volumeSumPrev = volumeSum[1];
volumeVwapSumPrev = volumeVwapSum[1];

if (isPeriodRolled) {
    volumeSum = volume;
    volumeVwapSum = volume * vwap;
} else {
    volumeSum = volumeSumPrev + volume;
    volumeVwapSum = volumeVwapSumPrev + volume * vwap;
}
def price = volumeVwapSum / volumeSum;

plot VWAP = price;

VWAP.SetDefaultColor(GetColor(0));
 

Similar threads

Top