Mark candle if open is greater than high of two candles ago


Category:
0
0

Hi Pete ,
For Buy Signal
I am looking for a code which should compare any candle’s open with the high of the previous to previous  candle ( not the high of the two previous candles since there are instances where the open is lower than the previous candle’s high but higher than the previous to previous candle and if open is > high of previous to previous candle then buy signal with alert and arrow right after the candle open.

For Sell Signal

A code which should compare any candle’s open with the low of the previous to previous  candle and if open is < low of previous to previous candle then sell signal with alert and arrow right after the candle open.

I hope I am able to explain what I am thinking.
Thank you so much,
Shaishav

Marked as spam
Posted by (Questions: 49, Answers: 62)
Asked on November 20, 2019 8:39 pm
107 views
0
Private answer

I understand you want to compare the open of the current bar to the high of the bar two candles ago. I updated the title of the question because the phrase "previous to previous" was too difficult to understand clearly. Took me quite a bit of effort to understand it. I'm glad you took the time to explain it clearly in your question.

Here is the code to accomplish your request:

plot buySignal = open > high[2];
buySignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
buySignal.SetDefaultColor(Color.CYAN);
buySignal.SetLineWeight(3);
plot sellSignal = open < low[2];
sellSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
sellSignal.SetDefaultColor(Color.MAGENTA);

sellSignal.SetLineWeight(3);
Alert(buySignal, "Buy Signal", Alert.BAR, Sound.RING);
Alert(sellSignal, "Sell Signal", Alert.BAR, Sound.RING);

I have not tested this on a chart so let me know if anything is amiss.

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on November 21, 2019 1:59 pm
0
Hi Pete, Thank you so much. I checked starting yesterday 1800 PM candle, all signals fine except the one on 1800. It seems that it is due to a missing candle in between. I just made a paper trade on CL based on the signal, it has to hit 58.15 minimum by this hour end. Thank you.
( at November 21, 2019 4:19 pm)
0
Sorry Pete, I was wrong, I should check the previous candle in the case of 1800 PM since there is no candle starting 1700 PM. Nothing wrong in the code. You need to have a look at it since it really gives nice signal and trend.
( at November 21, 2019 7:48 pm)