Don't use ints when you mean bool or an enumeration. You are not returning a count. int ma_indicator(…){
int signal; if(…) signal = 1; // BUY Signal else if(…) signal = 2; // SELL Signal else signal = 0; // Do Nothing return signal; } ⋮ int ma_indicator_output = ma_indicator(moving_average_array, low, high); if(ma_indicator_output == 1) // BUY
Use an enumeration and make your code self documenting. enum Signal{ SIGNAL_BUY, SIGNAL_SELL, SIGNAL_NONE }; Signal ma_indicator(…){ if(…) return SIGNAL_BUY; if(…) return SIGNAL_SELL; return SIGNAL_NONE; } ⋮ Signal ma_indicator_output = ma_indicator(moving_average_array, low, high); if(ma_indicator_output == SIGNAL_BUY)
-
Check for open position before trying to open.
-
You are looking at a signal. Act on a change of signal.
MQL4 (in Strategy Tester) - double testing of entry conditions - MQL5 programming forum #1 2017.12.12
@william - thanks for your help mate
1. Good point on the bool Vs Ints - I used Ints as there were 3 conditions (BUY, SELL, NO SIGNAL) and not 2 - but that same thing was on my mind too!
2. ENUM usage - you got me. You're right, I'll stop being lazy and fix that up :) Great suggestion.
3. To clarify: are you suggesting I identify the time diff between the first trade and the current time - if less then the chart-period = wait?
If thats the case: Is there a way to make the identification of the period (5m 1h, 4h, etc) variable - so I can program something to say "wait for 1 candle before re-assessing" - and have a scalable solution?
Again - thanks for your help
- 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 all,
Could I please get some advise on the following (very new to all this - so just a simple EA based on a 20SMA)
The intention is: If the high and the low of the last closed candle is clear of the 20SMA && above == BUY, if its clear of the 20SMA && below == SELL
The issue is it seems to (rightly so) create a new position each time a new tick comes in and the conditions are met.
This must be a fundamental concern of MQL (operating functions per tick - but only wanting a condition to fire once, once met)
How do you get around this?
PS: If I could just re-iterate - I'm pretty new, the more detailed a response you can give me the better for my progress.
Thanks in advance for your help.