Dear colleagues, I'm still a complete "dummy"in MQL programming, I started studying this topic quite recently. But I already started to write my first Expert Advisor, or at least I tried to.
On the 182nd page of this topic I've laid out trading criteria this EA should trade by. Please see what it says (last post on the page). I've been struggling for three weeks and I still cannot write here the part of the code responsible for the trading criteria. I've readthe tutorial chapter dedicated to this topic, but it didn't help me in this particular case.
I have written dozens of variants of this part of the code during my programming battles, but none of them works properly. Obviously I do not have enough knowledge, Icannot masterMQLthat quickly .Anyway, here is one of the code variants that works, at least approximately, as I want it to.
I know the code is all crooked and slanted, and in general the baypositions and sell are mixed up. But this is the only variant of the code, when Stochastic and Envelope are trading together, without ignoring each other. At the same time, Parabolic signals are not taken into account in trading for some reason. Anyway, please don't scold me too much for such "ass-kicking", I am well aware that the code is not correct.
Please help me, please fix the code of my Expert Advisor. I am having a hard time with it. I have implemented easier strategies (Mooving + Momentum; Mooving +RSI), but this one works. Please help. Please rewrite all wrong lines to make my EA trade by those rules, that I have describedon page 182. I really need it.
P.S.: I didn't write the whole code of the Expert Advisor, because I used ready-made MQL templates.
I think I figured out what my main (and maybe not the only) mistake was. All conditions in my trading criteria are combined with logical "and". As far as I understand it, it means that all conditions must be fulfilled simultaneously. But according to the system rules it is not correct. The signals of Envelope and Stochastic should be synchronous - yes. But the Parabolic should confirm opening of a position afterreceiving signals from the Envelope and the St ochastic.It may even happen (and this is quite normal) that it confirms after 5-10 bars.
Question: How can this "after" be put into the code? If it's possible, please show me an example of my code. Please help me very much. I'm already exhausted with these trading criteria.
I think I've figured out what my main (maybe not the only) mistake was. All the conditions in my trading criteria are lumped together with a logical "and". As far as I understand it, this means that all conditions must be met at the same time. But according to the system rules it is not correct. The signals of Envelope and Stochastic should be synchronous - yes. But the Parabolic should confirm opening of a position afterreceiving signals from the Envelope and the St ochastic.It may even happen (and this is quite normal) that it can confirm positions after 5-10 bars.
My question is: How do I paste this "after" in my code? If possible, please show me an example of my code. Please help me very much. I'm just getting exhausted with these trading criteria.
So try it, I've fixed your code right here on the page - didn't check it myself - pay attention to the comments.
All as described on page 182.
bool Buy_signal=false, Sell_signal=false; // эту строку разместить в глобальные переменные эксперта!!!!!!!!!!//+-------------------------------------------------------------------------------------+//| Расчет значений технических индикаторов с формированием сигналов для позиций |//+-------------------------------------------------------------------------------------+void GetSignal()
{
Signal = 0;
// - 1 - == Получение значений индикаторов ==============================================double SAR = iSAR(Symbol(), 0, SARStep, SARMaximum, 1); // тут тоже правки в коде - вместо "0"-го используем первый бар double EnvUp = iEnvelopes(Symbol(), 0, EnvPeriod, EnvMethod, EnvShift, EnvPrice,
EnvDeviation, MODE_UPPER, 1);
double EnvDn = iEnvelopes(Symbol(), 0, EnvPeriod, EnvMethod, EnvShift, EnvPrice,
EnvDeviation, MODE_LOWER, 1);
double StochM1 = iStochastic(Symbol(), 0, StochK, StochD, StochSlowing, StochMethod,
StochPrice, MODE_MAIN, 1);
double StochS1 = iStochastic(Symbol(), 0, StochK, StochD, StochSlowing, StochMethod,
StochPrice, MODE_SIGNAL, 1);
double StochM2 = iStochastic(Symbol(), 0, StochK, StochD, StochSlowing, StochMethod,
StochPrice, MODE_MAIN, 2);
double StochS2 = iStochastic(Symbol(), 0, StochK, StochD, StochSlowing, StochMethod,
StochPrice, MODE_SIGNAL, 2);
// - 1 - == Окончание блока =============================================================// - 2 - == Генерация сигнала ===========================================================if (SAR > High[1]) {Buy_signal=false; Sell_signal=false; // сбрасываем флаги условий открытия по стохастику и энвелопсу
Signal = 4;} // Закрытие BUY
if (SAR < Low[1]) {Buy_signal=false; Sell_signal=false;
Signal = 3;} // Закрытие Sellif ( StochM2 < StochS2 && StochM1 > StochS1 && StochM1 <= 20 && Low[1] <= EnvDn) // ставим флаги условий открытия по стохастику и энвелопсу в лонг
{
Buy_signal=true;
Sell_signal=false;
}
if (SAR < Low [1] && Buy_signal==true && Sell_signal==false)
Signal = 1; // Открытие BUYif ( StochM2 > StochS2 && StochM1 < StochS1 && StochM1 >= 80 && High[1] >= EnvUp) // ставим флаги условий открытия по стохастику и энвелопсу в шорт
{
Buy_signal=false;
Sell_signal=true;
}
if (SAR > High [1] && Buy_signal==false && Sell_signal==true)
Signal = 2; // Открытие SELL// - 2 - == Окончание блока =============================================================
}
Is that all the difference you could see?
Maybe that's the way to do it. :
Do I understand correctly that if I optimise three bool parameters in the tester, it will run all 9 combinations of their values? i.e.
1) bool1=true, bool2=true, bool3=true,Do I understand correctly that if you optimise three bool parameters in the tester, it will run all 9 combinations of their values...?
I thought you could just put in a bool and it would run true and false variants.
I've never used optimization before, I'm getting familiar with the topic
Dear colleagues, I'm still a complete "dummy"in MQL programming, I started studying this topic quite recently. But I already started to write my first Expert Advisor, or at least I tried to.
On the 182nd page of this topic I've laid out trading criteria this EA should trade by. Please see what it says (last post on the page). I've been struggling for three weeks and I still cannot write here the part of the code responsible for the trading criteria. I've readthe tutorial chapter dedicated to this topic, but it didn't help me in this particular case.
I have written dozens of variants of this part of the code during my programming battles, but none of them works properly. Obviously I do not have enough knowledge, Icannot masterMQL that quickly .Anyway, here is one of the code variants that works, at least approximately, as I want it to.
I know the code is all crooked and slanted, and in general the baypositions and sell are mixed up. But this is the only variant of the code, when Stochastic and Envelope are trading together, without ignoring each other. At the same time, Parabolic signals are not taken into account in trading for some reason. Anyway, please don't scold me too much for such "ass-kicking", I am well aware that the code is not correct.
Please help me, please fix the code of my Expert Advisor. I am having a hard time with it. I have implemented easier strategies (Mooving + Momentum; Mooving +RSI), but this one works. Please help. Please rewrite all wrong lines to make my EA trade by those rules, that I have describedon page 182. I really need it.
P.S.: I didn't write the whole code of the Expert Advisor, because I used ready-made MQL templates.
I think I figured out what my main (and maybe not the only) mistake was. All conditions in my trading criteria are combined with logical "and". As far as I understand it, it means that all conditions must be fulfilled simultaneously. But according to the system rules it is not correct. The signals of Envelope and Stochastic should be synchronous - yes. But the Parabolic should confirm opening of a position afterreceiving signals from the Envelope and the St ochastic.It may even happen (and this is quite normal) that it confirms after 5-10 bars.
Question: How can this "after" be put into the code? If it's possible, please show me an example of my code.Please help me very much. I'm already exhausted with these trading criteria.
Do I understand correctly that if the tester optimises three bool parameters, it will run all 9 combinations of their values? i.e.
Two to the third power has always been eight :-)
I think I've figured out what my main (maybe not the only) mistake was. All the conditions in my trading criteria are lumped together with a logical "and". As far as I understand it, this means that all conditions must be met at the same time. But according to the system rules it is not correct. The signals of Envelope and Stochastic should be synchronous - yes. But the Parabolic should confirm opening of a position afterreceiving signals from the Envelope and the St ochastic.It may even happen (and this is quite normal) that it can confirm positions after 5-10 bars.
My question is: How do I paste this "after" in my code? If possible, please show me an example of my code.Please help me very much. I'm just getting exhausted with these trading criteria.
So try it, I've fixed your code right here on the page - didn't check it myself - pay attention to the comments.
All as described on page 182.
Two to the third power has always been eight :-)
Nice observation :-)))