close order works comparing to moving average, but not when it's moving average with offset - please help
Hi, thanks in advance for the help!
I've spent hours trying to get this to work but after searching everywhere I still don't understand why it's not working. Any help would be appreciated.
The following is defined at the top of the program for users to enter their offset from the exit moving average:
The only difference between Code1 and Code2 is these lines:
Code1
Code2
For whatever reason, it's like the comparison operator cannot compare the two values and breaks on Code2? Any ideas? Thank you once again!
---------------------------------------------------------------------------------------------------------------------------
Full code below:
Code1 (works in tester showing positions are exited when close price crosses moving average (ma)):
Code 2 (does NOT work in tester, positions do not get closed (it's supposed to exit when close price crosses moving average + offset)):
double ma_offset_buy=NormalizeDouble(ma-ma_offset,5); double ma_offset_sell=NormalizeDouble(ma+ma_offset,5);Try with ' Digits' instead of 5
Try with ' Digits' instead of 5
thank you for your quick response
i tried
double ma_offset_buy=NormalizeDouble(ma-ma_offset,Digits); double ma_offset_sell=NormalizeDouble(ma+ma_offset,Digits);
still no luck
this EA is for multiple symbols including indices, forex, metals
the broker is CMC Markets (cfd)
is it because Close[1] cannot be compared to a float value or real value or something similar?
- whats1thingnow:
double ma_offset=ma*TrailingExitMAOffsetPct;
Always post all relevant code. If TrailingExistMAOffsetPct is actually a percent, price × 25 is not a price difference (price × 0.25 would be.)
How To Ask Questions The Smart Way. 2004
Be precise and informative about your problem -
if(Volume[0]>1) return;
For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart,) volume is unreliable (miss ticks,) Price is unreliable (duplicate prices and The == operand. - MQL4 programming forum.) Always use time.
New candle - MQL4 programming forum #3 2014.04.04I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
Running EA once at the start of each bar - MQL4 programming forum 2011.05.06
William Roeder:
-
Always post all relevant code. If TrailingExistMAOffsetPct is actually a percent, price × 25 is not a price difference (price × 0.25 would be.)
How To Ask Questions The Smart Way. 2004
Be precise and informative about your problem -
For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart,) volume is unreliable (miss ticks,) Price is unreliable (duplicate prices and The == operand. - MQL4 programming forum.) Always use time.
New candle - MQL4 programming forum #3 2014.04.04I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
Running EA once at the start of each bar - MQL4 programming forum 2011.05.06
thanks for the help
1. TrailingExitMAOffsetPct is default set to 1% as per posted at the very top:
extern double TrailingExitMAOffsetPct = 0.01;
i have the print there to make sure the calculation is correct... it is doing the 1% offset
Print("ma_offset_buy",ma_offset_buy);
the problem remains that when i use the variables ma_offset_buy and ma_offset_sell, positions are not closed:
if(Close[1]<ma_offset_buy && OrderProfit() > 0)
if(Close[1]>ma_offset_sell && OrderProfit() > 0)
2. slightly confused regarding this point - i understand you are saying don't use volume b/c it's unreliable
if(Volume[0]>1) return;
instead use time as per https://www.mql5.com/en/forum/150885#comment_3766801
can you elaborate on
-
I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
Running EA once at the start of each bar - MQL4 programming forum 2011.05.06
--------------
Ahmet Metin Yilmaz:
You can change with this
yes, i have tried both
Close[1]<ma_offset_buy
iClose(Symbol(), 0,1)<ma_offset_buy
positions do not get closed for neither
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi, thanks in advance for the help!
I've spent hours trying to get this to work but after searching everywhere I still don't understand why it's not working. Any help would be appreciated.
The following is defined at the top of the program for users to enter their offset from the exit moving average:
The only difference between Code1 and Code2 is these lines:
Code1
Code2
For whatever reason, it's like the comparison operator cannot compare the two values and breaks on Code2? Any ideas? Thank you once again!
---------------------------------------------------------------------------------------------------------------------------
Full code below:
Code1 (works in tester showing positions are exited when close price crosses moving average (ma)):
Code 2 (does NOT work in tester, positions do not get closed (it's supposed to exit when close price crosses moving average + offset)):