Error in study alert rec usage is not allowed


New member
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.
close crosses below GtDailyVWAP()

Where the function GtDailyVWAP is:
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;


Similar threads