You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
well I still havent figured it out, I have narrowed it down to the buffer it doesnt make sense though, the lines for both buffers are drawn correctly on the screen lma and hma are doubles declared like this:
double hma=Buf_4[0], lma=Buf_5[0];
Buf_4[i]=iMA(NULL,0,3,0,MODE_LWMA,PRICE_HIGH,i+1);
Buf_5[i]=iMA(NULL,0,3,0,MODE_LWMA,PRICE_LOW,i+1);
I make Alerts like this at the relevent places at the point when the conditions are met, the bid is lower than lma or the bid is higher than hma
I get the expected value for hma but lma returns a crazy number, the alerts read like this:
lma=214782647 Bid=1.3502
hma= 1.3504 Bid= 1.3505
I let the Alerts run for a while, sometimes both Alerts returns a proper value like this:
lma=1.3499 Bid=1.3495
hma=1.3510 Bid=1.3511
it doesnt make sense how can hma return the expected value, while lma returns a totaly irrelevent value but yet the lines are drawn correctly on the screen and then other times both values returns the expected values i beleive this must be a bug im going to reboot my computer and see what happens.
Looks like you're using drawing buffers. They are automatically initialized with EMPTY_VALUE which is the 'crazy number' you're seeing.
Where's the loop? Using index usually involves a loop. I usually use plain variables if buffers are not necessary :
yes they are drawing buffers in an indicator to draw the lines for the EA that uses the same values, the variables lma and hma are declared and initialized with the values of Buf_4[0] and Buf_5[0] respectively before the buffers are filled is that the reason for this ?
i didnt think that would matter as the buffers are subsequently filled before those variables are called in the program, I am going to modify the code to initialize those two doubles after the buffers are filled, but why would this happen intermittently sometimes the variable lma returns the expected value, sometimes it doesnt, it seems this is related to a post last week https://www.mql5.com/en/forum/129872 I tried to replicate his results they also returned that same number when he did it, but when I ran the same test as him it didnt happen.
loops are like this
so then when i use those doubles declared as the buffer values should I assume they are unreliable ? I will need to change more than just the arrow function if that is the case because I used the values of the buffers for other things too.
Posting that earlier could save us couple of goose-chases ;)
No, both are reliable. We should use the right tool for each purpose. Let me see if I can sort your code from the two pages.
thanks for looking at it cameofx, I have run up against a simalar problem before with another indicator i wrote that also appeared to work correctly untill i tried using its line values to buy or sell if the price was above or below the line, the results were simalar, the buy/ sell signals were in the wrong place, I narrowed that down to iCustom was not returning the same values for the buffers as what was being displayed on the screen, that was one of my first forrays into indicator coding and I figured I must have done something wrong and discarded that indicator, it looks like I am still making the same mistake.
Try this. Amend it to your need of course. There are still omitted parts from what you posted.
Thanks for taking the time to look at that for me I'll change it according to your code and see what happens
Your welcome, I got your full version. I can't promise a quick fix though. I'll see what I can do.