void OnTick(){ int movingAverageDefinition1 = iMA(_Symbol,_Period,3,0,MODE_EMA,PRICE_CLOSE); int movingAverageDefinition2 = iMA(_Symbol,_Period,13,0,MODE_EMA,PRICE_CLOSE);
Perhaps you should read the manual, especially the examples.
How To Ask Questions The Smart Way. (2004)
How To Interpret Answers.
RTFM and STFW: How To Tell You've Seriously Screwed Up.
They all (including iCustom) return a handle (an int). You get that in OnInit. In OnTick/OnCalculate (after the indicator has updated its buffers), you use the handle, shift and count to get the data.
Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 (2020)
How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 (2020)
MQL5 for Newbies: Guide to Using Technical Indicators in Expert Advisors - MQL5 Articles (2010)
How to call indicators in MQL5 - MQL5 Articles (2010)
Vengeance Seeker:
But my EA is opening both BUY and SELL positions - I'm struggling to understand why.
Are you confusing the closure of a sell position with a buy for a new buy position?
Perhaps you should read the manual, especially the examples.
How To Ask Questions The Smart Way. (2004)
How To Interpret Answers.
RTFM and STFW: How To Tell You've Seriously Screwed Up.
They all (including iCustom) return a handle (an int). You get that in OnInit. In OnTick/OnCalculate (after the indicator has updated its buffers), you use the handle, shift and count to get the data.
Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 (2020)
How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 (2020)
MQL5 for Newbies: Guide to Using Technical Indicators in Expert Advisors - MQL5 Articles (2010)
How to call indicators in MQL5 - MQL5 Articles (2010)
I don't know maybe I'm interpreting the tester the wrong way. But its showing filled Buy positions there. Does the code look fine tho? I don't understand what that William is telling me to do
I can't comment much about your code as you use
#include <Trade\Trade.mqh>
CTrade trade;
and I don't use that.
I can only say that you should create the handles for the indicators in OnInit as William has already pointed out.
In MT5 when you open a sell (In)
when it is closed it is closed by opening a buy(Out) and this may be confusing you.
I know that I found it a bit confusing when I started with MQL5 after coding with the much more user friendly MQL4.
I've created an EA that uses the 3 and 13 EMA to ONLY execute SELL positions. When the 3 crosses bellow the 13, a sell position must be executed. When the 3 crosses above the 13, all positions of the CURRENT symbol should be closed. But my EA is opening both BUY and SELL positions - I'm struggling to understand why.
To those who viewed my first attempt at an EA - I hope this is an improvement :)
If your EA doesn't what you expect use the debugger to check the processing:
https://www.metatrader5.com/en/metaeditor/help/development/debug
https://www.mql5.com/en/articles/654
https://www.mql5.com/en/articles/35
https://www.mql5.com/en/articles/2041
https://www.mql5.com/en/articles/272
https://www.mql5.com/en/articles/150
You can solve your problems a lot faster :)
- www.metatrader5.com
I can't comment much about your code as you use
and I don't use that.
I can only say that you should create the handles for the indicators in OnInit as William has already pointed out.
In MT5 when you open a sell (In)
when it is closed it is closed by opening a buy(Out) and this may be confusing you.
I know that I found it a bit confusing when I started with MQL5 after coding with the much more user friendly MQL4.
If your EA doesn't what you expect use the debugger to check the processing:
https://www.metatrader5.com/en/metaeditor/help/development/debug
https://www.mql5.com/en/articles/654
https://www.mql5.com/en/articles/35
https://www.mql5.com/en/articles/2041
https://www.mql5.com/en/articles/272
https://www.mql5.com/en/articles/150
You can solve your problems a lot faster :)
Oooh! Now it makes sense! Thank you so much. The code runs perfectly then. Its profitable too.
You buy at Ask and close it (=sell) at Bid.
You sell at Bid and close it (=buy) at Ask.
For a sell SL is always above Ask+10.0*_Point (>min. distance) otherwise you'll get the error Invalid Stop.
- 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've created an EA that uses the 3 and 13 EMA to ONLY execute SELL positions. When the 3 crosses bellow the 13, a sell position must be executed. When the 3 crosses above the 13, all positions of the CURRENT symbol should be closed. But my EA is opening both BUY and SELL positions - I'm struggling to understand why.
To those who viewed my first attempt at an EA - I hope this is an improvement :)