I was wondering if it would be possible to get some advice in relation to an indicator I am writing please.
This is my first indicator so it is all a bit new.
I am building it up in stages with the first stage I want to do a check to see if the current price action is above the 50EMA on the 5 minute, 1 hour, 4 hours and 1 day chart of the currently selected currency. If it is above I want it to print some text. If they are all below I want it to print some different text.
I have use 'close' and 'iclose' to try to determine this but wasn't sure if I should be using 'MarketInfo' instead.
This is the code I have:
I am not quite sure what you are trying to do. You said "current price" but you use the close price and for a certain shift, which is not current price. For the close you use a certain shift 'i' but for the iclose you use 0. And for the MA's you always use the current price. So it is not consistent. If you simply want to know when the current price is above the MA's then you do not need to use iclose at all because the price will be the same no matter what the timeframe is. Simply use the Bid or MarketInfo Bid price and compare it to the MA values. And you do not need a cycle like you have since only the current prices need considered.
Ok that is clear thanks very much.
I was using close only really because I had used it before and that basically the close line of the current bar is the current price until it actually closes.
Basically I think I was confused.
I will try marketinfo, thanks very much!
Incidentally if I also wanted to add something that would show back testing of the indicator so I wanted to show, probably an arrow, on any 5 minute bar in the past when the close of that bar was above the EMA and also the bars of the 1 hour, 4 hour and day were also above their EMA's would I use close and iclose for that without reference to i?
Just thinking out loud now and I already see a problem with what i just said as the close of the 5 minute bar wouldn't correspond in time to the close of the other timeframes. Is there a way to compare the close of the minute bar at lets say 11:25 and its relation to the EMA with the location to the EMA of the other timeframes at that time period?
Or am I confusing myself again :-)
Yeah, you are right about the close price on the current candle being the same as the current price, but you did not use 0 for the Close and you used 'i'. And since the price would be the same no matter what time frame then the iClose is not needed. This is why I suggested to keep everything the same and get rid of the Close and iClose altogether and just use Bid or MarketInfo.
If you want to see arrows on past candles then you should keep the cycle. If you just want to see text for whenever the current price is above or below the current MA then I would get rid of the cycle. About the last question, I am not sure what you mean.
I was thinking I could do two bits. The first matching on marketinfo for the text.
The second matching in close and iclose with reference to the cycle for the past arrows in relation to EMA for the cycle also.
Think that would do it.
Not sure I know what I meant for the last part either so ignore that
Thanks very much for your help.
No problem and I hope it works out for you
Your problem lies in using Close (0)!
Ever heard of repaint?
You never have a close (0) until 0 closes, if you know what i mean.
Simply put, seriously, "i" should always be greater than zero.
Using a shift of 0 for close is not related to an indicator repainting. If this were the case, all the standard MT4 indicators would be repainting indicators. Repainting is not when the indicator's value on the current unclosed candle changes. This is normal. Repainting is when an indicator changes a value(s) on previously closed candles. The problem with his indicator was not related to repainting anyways.
An indicator does not need to have a shift greater than 0. And just because an indicator does use a shift greater than 0 does not necessarily mean it will not repaint.
I think this indicator could be interesting for you (google it pls)
Detrended Price Oscillator (DPO)
in short: measures the difference between a past price and a moving average