Change BG Color Above VWAP line


Category:
1
0

Hello Pete I am looking for a code that changes the background color of my watchlist when a green candle passes above the VWAP line on an Intraday Chart.

Attachments:
Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on May 11, 2017 9:56 pm
1392 views
1
Private answer

I applied this to a watchlist and it appears to run very slow. Took several minutes for the data to show up. So be patient and don’t expect this to be affective at lower time frames where immediate notification is crucial.

I’ll save space here by not including the source code. You can copy/paste that from the standard VWAP chart study that comes with the platform.

First step, you need to remove the following lines from the very bottom of the source code:

plot UpperBand = price + numDevUp * deviation;
plot LowerBand = price + numDevDn * deviation;

VWAP.setDefaultColor(getColor(0));
UpperBand.setDefaultColor(getColor(2));
LowerBand.setDefaultColor(getColor(4));

Then you will change plot VWAP = price; to read def VWAP = price;

In the final step, you will add these two lines to the bottom of the code:

plot signal = close > open and open < VWAP and close > VWAP;
AssignBackgroundColor(if signal then Color.GREEN else Color.BLACK);

I should mention that your specification leaves a lot left to interpretation. You only asked to change the background color when a green candle crossed the VWAP. You did not mention any other conditions although the screenshot you provided appears to imply there is more. To explain further, you only marked one candle on your screenshot but there are a total of three candles that meet your specification, as stated.

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on May 12, 2017 8:02 am
0

Im sorry if I was a little vague. I’m asking for the first green candle to pass the VWAP line either half or full body on the intraday chart.

( at May 12, 2017 9:23 am)
1
Private answer

Ok, then we have to add quite a bit of complexity to achieve this. And I will restate my prior warning that this code takes quite some time to execute in the watchlist. Your screenshot is showing a 1 min chart and it is very doubtful the watchlist with this code will able to respond quickly enough display the signal before the 1 min bar expires.

Taking from my previous example, you would remove the lines of code I previously provide and in their place you add the following:

def regularSessionHours = RegularTradingStart(GetYYYYMMDD()) <= GetTime();
def regularSessionStart = GetDay() <> GetDay()[1];
def crossOfVWAP = open < close and open < VWAP and close > VWAP;
def firstCrossOfVWAP = CompoundValue(1, if regularSessionStart and close < VWAP then 0 else if regularSessionHours and crossOfVWAP == 0 then firstCrossOfVWAP[1] else crossOfVWAP, 0);
plot signal = firstCrossOfVWAP and !firstCrossOfVWAP[1];
AssignBackgroundColor(if signal then Color.GREEN else Color.BLACK);

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on May 12, 2017 11:32 am