Wow thank you, MQL has it all :), but i'm still wondering why my code doesn't work, the simple logic behind it shoud make it work.
I need to find the highest high in the last 11 bars [...]
RaptorUK is rightly saying that iHighest() is an easy way to do what you want. However, it's worth looking at what your code is doing, and why it isn't working. If someone says to you that they're going to call out a list of 11 numbers and they want you to work out the highest one, then I'm sure that the method you would use is completely different to the code you have tried to write. You'd hear the first number, and make a note of it. If the second number was higher, then you'd drop the first number and compare all the remaining numbers against the second number, etc. Basically, you'd continually be remembering the highest number you'd heard so far, and comparing the latest number to it.
A simple version of that in code would go as follows - this is designed to be clear, not to be optimal:
double HighestSoFar = High[0]; for (int i = 1; i <= 10; i++) { if (High[i] > HighestSoFar) HighestSoFar = High[i]; }
What your code is doing is so completely different that I think you must have blinded yourself to the obvious by thinking "I am writing computer code!". Basically, if you look at what your code is doing, then it is always going to put High[10] into temp3. On the very last of the 121 passes round the loops, where h=10 and z=10, then the code is going is to be saying "is High[10] greater or equal to High[10] ?", and therefore it will put High[10] into temp3.
What your code is doing is so completely different that I think you must have blinded yourself to the obvious by thinking "I am writing computer code!". Basically, if you look at what your code is doing, then it is always going to put High[10] into temp3. On the very last of the 121 passes round the loops, where h=10 and z=10, then the code is going is to be saying "is High[10] greater or equal to High[10] ?", and therefore it will put High[10] into temp3.
I need to find the highest high in the last 11 bars
for(h=0;h<=10;h++){ for(z=0;z<=10;z++){ if(High[h]>=High[z]) { temp3 = High[h]+0.00010; } } } Comment("Lot Size Buy " + temp3); // LotSizeSell());
It would also be nice if i could display only the digits useful to me in my comment, i would like to see 1.44944 instead of 1.44944000.
double highest = 0; for(h=0; h<11; h++) if (highest < High[h]) highest = High[h]; temp3 = highest+0.00010; Comment("Lot Size Buy " + temp3); // LotSizeSell());
or
int iHighest = Highest(NULL, 0, 11, 0); double highest = High[iHighest]; temp3 = highest+0.00010;
string PriceToStr(double p){ return( DoubleToStr(p, Digits) ); } : Comment("Lot Size Buy " + PriceToStr(temp3)); // LotSizeSell());
- See also pips2dbl
Okay, i have a new error... can't figure what to do.
Print("blabla"); if(NormalizeDouble(Ask,4) == NormalizeDouble(OrderTakeProfit()-Value1*4,4)) { Print("123"); OrderModify(ticket,Ask,StopLossBuy()+Value1,Ask+Value1*4,0,Blue); }
Okay it prints Blabla, that means that the program works until now
Then It doesn't print 123 that means that the error is not in OrderModify
This means that the condition is false, the condition is theorically true
Comment(Hour(),"\n", DoubleToStr(Ask,4), "=", DoubleToStr((OrderTakeProfit()-Value1*4),4) );
I use this comment to show on my chart the value of Ask and the value of OrderTakeProfit()-Value1*4
As you can see in my comment the condition is true, but my
if
doesn't work.
I'm going crazy this is the last step necessary to finish my FIRST ea, my brain hurts from working too much.
You are on a 5 digit broker and just printing 4 digits in your comment . . . . . what if the values are 1.31560 and 1.31562 . . . they are not equal.
Use DoubleToStr()
You are on a 5 digit broker and just printing 4 digits in your comment . . . . . what if the values are 1.31560 and 1.31562 . . . they are not equal.
Use DoubleToStr()
It should work anyway because i'm rounding the numbers so 1.31560 becomes 1.3156 and 1.31562 becomes 1.3156 too
i did this because the ask price sometimes moves by 2 points instead of 1
anyway i tried what you suggested anyway and it doesn't work
if(DoubleToStr(Ask,4)==DoubleToStr(OrderTakeProfit()-Value1*4,4))
Okay, i have a new error... can't figure what to do.
Okay it prints Blabla, that means that the program works until now
Then It doesn't print 123 that means that the error is not in OrderModify
This means that the condition is false, the condition is theorically true
I use this comment to show on my chart the value of Ask and the value of OrderTakeProfit()-Value1*4
As you can see in my comment the condition is true, but my
doesn't work.
I'm going crazy this is the last step necessary to finish my FIRST ea, my brain hurts from working too much.
If it doesn't print 123 then this condition
if(NormalizeDouble(Ask,4) == NormalizeDouble(OrderTakeProfit()-Value1*4,4))
is not come true. What is it ??? Why not use Digits here
if(NormalizeDouble(Ask,Digits) == NormalizeDouble(OrderTakeProfit()-Value1*4,Digits))
and why has it to be equal before you modify and not >= (buy) or <= (sell)
and maybe you could trie
if(Ask >= NormalizeDouble(OrderTakeProfit()-(Value1*4,Digits)))
or
if(Ask >= (OrderTakeProfit()-(NormalizeDouble(Value1*4,Digits))))
and did you select the open trades with a loop
so you select the right trade to modify...
If it doesn't print 123 then this condition
is not come true. What is it ??? Why not
and why has it to be equal before you modify and not >= (buy) or <= (sell)
and maybe you could trie
I have tried >= it doesn't work anyway
i tried to use Digits, well it doesn't make a difference
i have tried to select the trade, it doesn't work anyway. But also i only trade 1 order at a time, so it can't be wrong anyway.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I need to find the highest high in the last 11 bars
The variables are already initialized of course.
Please don't mind the horrible format nor the added pip value (0.00010) nor the number of bars 11 or 12 (because i still haven't figured if the current moving bar is -1 or 0)
I also found out that i could use the MathMax() function instead of that if.
The thing is that it isn't working like i planned. I attached a screenshot
It would also be nice if i could display only the digits useful to me in my comment, i would like to see 1.44944 instead of 1.44944000.
Thank you for your help.