So i have this study that alerts me when price is between two EMAs and it works great. But i would like to add another condition for the alert and need help with this.
I want the alert to trigger when price is between EMAs but only 5min before every new 30min "window" opens. So as an example, if price is between the EMAs at 9:26AM or 9:58AM i want the alert to trigger but if price is inside EMAs any other time within the current 30min candle/window, it shouldn´t trigger.
So between 9:25-9.30AM, 9:55-10:00AM, 10:25-10:30AM etc. throughout the day and i need it to work with extended hours included (pre + after)
This should be fairly simple to add as a condition so i hope someone can help me modify the code below. Thanks in advance.
I want the alert to trigger when price is between EMAs but only 5min before every new 30min "window" opens. So as an example, if price is between the EMAs at 9:26AM or 9:58AM i want the alert to trigger but if price is inside EMAs any other time within the current 30min candle/window, it shouldn´t trigger.
So between 9:25-9.30AM, 9:55-10:00AM, 10:25-10:30AM etc. throughout the day and i need it to work with extended hours included (pre + after)
This should be fairly simple to add as a condition so i hope someone can help me modify the code below. Thanks in advance.
Code:
def agg=aggregationPeriod.DAY;
plot fastline = ExpAverage(close,32);
plot slowline = ExpAverage(close,50);
def fastlined = ExpAverage(close(period=agg),32);
def slowlined = ExpAverage(close(period=agg),50);
def numDevDn = -2.0;
def numDevUp = 2.0;
def timeFrame = 3 ;
def cap = getAggregationPeriod();
def errorInAggregation =
timeFrame == 3 and cap >= AggregationPeriod.WEEK or
timeFrame == 3 and cap >= AggregationPeriod.MONTH;
assert(!errorInAggregation, "timeFrame should be not less than current chart aggregation period");
def yyyyMmDd = getYyyyMmDd();
def periodIndx;
#switch (timeFrame) {
#case DAY:
periodIndx = yyyyMmDd;
#}
#def isPeriodRolled = compoundValue(1, periodIndx != periodIndx[1], yes);
def volumeSum;
def volumeVwapSum;
def volumeVwap2Sum;
#if (isPeriodRolled) {
volumeSum = volume;
volumeVwapSum = volume * vwap;
volumeVwap2Sum = volume * Sqr(vwap);
def price = volumeVwapSum / volumeSum;
def deviation = Sqrt(Max(volumeVwap2Sum / volumeSum - Sqr(price), 0));
def upperprice= if fastline> slowline then fastline else slowline;
DEF lowerprice= if fastline<slowline then fastline else slowline;
def alertcond= close(pricetype=pricetype.LAST)>lowerprice and close(pricetype=pricetype.LAST)<upperprice;
alert(alertcond,"Price is inside EMAs", alert.BAR,sound.ring);
addlabel(alertcond,"Price is inside EMAs ",COLOR.YELLOW);