Coding a Profitable Stochastic Moving Average EA for MT5 (mql5 Tutorial)

preview_player
Показать описание

Learn about the benefits of automated trading. After programming trading strategies for a while I started teaching how to program expert advisors for the MT4 (MetaTrader 4) and MT5 (MetaTrader 5). Until now I only did videos in German but now I will start this channel with English videos to reach a larger audience of traders and help them improve their trading. There will be no fake trading on this channel and no lies. I show trading as it is - the good and the bad sides. Stay tuned and subscribe because you don't want to miss ;)

Trading in derivative products such as futures, options, CFDs, Forex and certificates involves a considerable risk. These products are not suitable for every investor. Investors could potentially lose all or more of the original investment. If anything, only money that equals personal risk capital and can be lost without jeopardizing financial security or lifestyle should be used. Partially or fully automated trading programs can only be used to support the trader. Past performance is not an indication of future results.
Рекомендации по теме
Комментарии
Автор

Source Code:

#include <Trade/Trade.mqh>

input group "Trading Inputs"
input double Lots = 0.1;
input double TpDist = 0.001;
input double SlDist = 0.005;

input group "Indicator Inputs"
input ENUM_TIMEFRAMES StochTimeframe = PERIOD_H1;
input int StochK = 5;
input int StochD = 3;
input int StochSlowing = 3;
input double StochUpperLevel = 80;
input double StochLowerLevel = 20;

input bool IsMaFilterActive = false;
input ENUM_TIMEFRAMES MaTimeframe = PERIOD_D1;
input int MaPeriod = 100;
input ENUM_MA_METHOD MaMethod = MODE_SMA;

int handleStoch;
int handleMa;

int totalBars;

CTrade trade;

int OnInit(){
handleStoch = iStochastic(_Symbol, StochTimeframe, StochK, StochD, StochSlowing, MODE_SMA, STO_LOWHIGH);
handleMa = iMA(_Symbol, MaTimeframe, MaPeriod, 0, MaMethod, PRICE_CLOSE);

return(INIT_SUCCEEDED);
}

void OnDeinit(const int reason){

}

void OnTick(){
int bars = iBars(_Symbol, StochTimeframe);
if(totalBars != bars){
totalBars = bars;

double stoch[];
CopyBuffer(handleStoch, MAIN_LINE, 1, 2, stoch);

double ma[];
CopyBuffer(handleMa, MAIN_LINE, 1, 1, ma);

double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);

if(stoch[1] < StochUpperLevel && stoch[0] > StochUpperLevel){
if(!IsMaFilterActive || bid < ma[0]){
trade.Sell(Lots, _Symbol, bid, bid+SlDist, bid-TpDist);
}
}else if(stoch[1] > StochLowerLevel && stoch[0] < StochLowerLevel){
if(!IsMaFilterActive || bid > ma[0]){
trade.Buy(Lots, _Symbol, ask, ask-SlDist, ask+TpDist);
}
}
}
}

Автор

Hello my friend ..
Dozens of expert consultants can be made by watching all your videos... the fact that each video contains information and repetition allows us to reinforce the coding.. in fact, those who have knowledge can catch fine details in some of your videos... you are a very serious and important resource for us.. at least from my point of view. 😁 thank you so much 🙏

rzgakademi
Автор

Hi, René. There's a way to change coding style(indent) more conveniently. In the top left column, click Tools - Options. In the Styler section choose Style to be Java and then select any codes that you wish to be your style. Then click Styler which is a comb sign that locates in the far right of Compile. That will make all codes automatically fit your style. If you want to make all codes to be this style you can click anywhere in the coding area and press Ctrl + A to select all codes and click Styler.

johnvoidman
Автор

I love how you said stochastic. German accent on point!

Matetodaslasmananas
Автор

As usual, everytime I view your videos, I am amazed! Thank you very much! Appreciate your work and dedication.Merry Christmas!

jesjan
Автор

"One idea for programing video would be to program 3-10 Oscillator introduced by Linda Raschke." I second that statement!

michaelaldan
Автор

Hi René, thank you for the video(s) and your efforts to explain programming in mql5.
I found this video and the one before extremely good to learn an important lesson for trading: it is amazing how an expert advisor can be simple but still profitable, really amazing.
Thank you again René.

musicontheroad_gsbt
Автор

@ReneBalke Thank you very much for this tutorial. I was able to use this idea to create a Stochastic + MACD EA. The MACD replaced the MA on higher timeframe as a filter.

georgeeffanga
Автор

@ReneBalke Now that I have used the idea in the video to create the same EA but replaced the MA with MACD as filter, I'm motivated to try out something else. I want to code the same Stochastic + MA expert adviser but I want to add an extra filter. I want to add a Volume indicator to it. A signal is tradable if the Stochastic and MA align and volume is rising. I hope this is possible and will try it out. Danke, Rene.

georgeeffanga
Автор

Vielen Dank fuer all die Erklaerungen.

eos
Автор

Sería excelente que tus videos tengan subtítulos en spanish

ericsoldevilla
Автор

This was fantastic! Thank you so much for this

jwia
Автор

Hello Sir, you are really blessing us with your videos thank you very much. Please can you do a video on how the write a code for just stochastic crossovers

gabrielopokunyarkoh
Автор

Hey Rene, great video!
Thanks for sharing this.
One idea for programing video would be to program 3-10 Oscillator introduced by Linda Raschke.

markovelikonja
Автор

Hey, good work but to define else-if you are at the wrong program.

OSWALD
Автор

YOU ARE A GREAT MAN, , , THUMB UP BROTHER

danielmacharia
Автор

hello brother, im doing pretty much same EA but in Mt4 and is showing me all time this error : ema_handle =iMA(NULL, 0, 120, 0, MODE_EMA, PRICE_CLOSE); 'iMA' - wrong parameters count --- ( im using 120 ema) . Can you help me to fix it . I used chat GBP for coding .

pajtimukaj
Автор

Thanks a lot mate! More of that please ;-)

biberhund
Автор

hello rene ....I need an automatic ea with configurable lotage + automatic activation buy WHEN CROSSING UP THE LOW LEVEL LINE or ACTIVATE SELL WHEN CROSSING UPPER LINE LEVEL AND TP MEDIUM LEVEL LINE IN THE bollinger bands %b indicator or in the average of 20 bb that would be the same + option only buy only sell and sl points ... ... THANK YOU VERY MUCH... OR IF YOU CAN'T YOU COULD RECOMMEND ME TO SOME AVAILABLE CREATOR.... A HUG THANK YOU

Jesusdelrioversiones
Автор

@Rene Balke,
Hi Rene, I like the expert adviser, but I would like to make a suggestion of a trailing stop and using an option to control or limit the number of trades being placed while above the MA (currently multiple trades) having these options would help control the losing trading.

With thanks for the expert

MAS-