Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 413

 

Can such a code be prescribed?

(The distance between lines should be 10 pips)

int OnInit()
{

ObjectCreate("Средняя линия",OBJ_HLINE,0,0,Bid); 

ObjectCreate("Верхняя линия",OBJ_HLINE,0,0,Bid+0.0010); 

ObjectCreate("Нижняя линия",OBJ_HLINE,0,0,Bid-0.0010); 


return(INIT_SUCCEEDED);
}


Or may it happen, that the EA draws the midline, and then the bid changes, and the second line will not depart from the midline by 10 pips?

Is it possible that the Bid changes during the EA execution? Or the value of Bid will change only if RefreshRates is running?


Maybe it would be more correct?

int OnInit()
{

sredn=Bid;
verhn=sredn+0.0010;
nizhn=sredn-0.0010;


ObjectCreate("Средняя линия",OBJ_HLINE,0,0,sredn); 

ObjectCreate("Верхняя линия",OBJ_HLINE,0,0,verhn); 

ObjectCreate("Нижняя линия",OBJ_HLINE,0,0,nizhn); 



return(INIT_SUCCEEDED);
}
 
igrok333:

Is it possible to write this code?

(distance between lines should be 10 pips)


Or may it happen that the EA draws the midline, and then the Bid changes, and the second line is no longer 10 pips away from the midline?


Is it right?

Bid will not change if there is no RefreshRates call in the middle,

But it's not quite correct to use Bid in OnInit(). First, the connection may be broken or the market may be closed, this is one; the Bid support in OnInit is a feature, which can be changed, this is two :-) And finally - the purpose of OnInit() is initialization, ie check everything is ready for further work and answer YES / NO. Relying on trading functions or creating graphical objects there is no good. It is acceptable, but not correct.

 
Maxim Kuznetsov:

Bid will not change if there is no RefreshRates call in the middle,

But ! Using Bid in OnInit() is not quite correct. First, the connection may not exist or the market may be closed, this is one; The very support of Bid in OnInit is a feature, which can be changed, this is two :-) And finally - the purpose of OnInit() is initialization, ie check everything is ready for further work and answer YES / NO. Relying on trading functions or creating graphical objects there is no good. It is acceptable, but not correct.

yes indeed.

i then have a trade open on the midline.

If you want to open a position on the middle line, you'd better move the onitics to the ontick function, because it will wait for the new onitick to open.

it is better to move the line construction to the beginning of the onitics function

 

Is it possible to make the script work in the tester?
I throw it in the window, nothing happens. On a normal chart the script works

 
RomanRott:

Is it possible to make the script work in the tester?

No and there is no need to. Everything can be tested on any chart or in debug mode.
 
RomanRott:

I mean to write some code in my indicator/advisor that will connect some other indicators at once
What and how do I add?


If you want another indicator to pounce itself, you can't do that!

It is possible to draw another one next to your indicator. For this purpose, you can use iCustom function and use it to draw the data you need.

 

I've created three EAs in MT4 with different "magics" and strategies, combined them into one EA, each strategy works separately, but when I turn on three at once, the third strategy does not modify its "magics" WHY??? everything in the tester.

And also, should put one selimit, but puts equal number of selimits. (if 2 sels, then 2 selimits bets, if 5 sels, then bets 5 selimits).

 
ZZuretc:

Can you advise me, in MT4 I created three EAs with different "magics" and strategies, I combined them into one EA, separately each strategy works, but when I turn on three at once, the third strategy modifies not its "magics" WHY??? all in the tester.

And also, should put one selimit, and puts equal to the number of sells. (If 2 sels, then 2 selimits puts, if 5 sels, then puts 5 selimits).


What can I say, it does not correctly identify its orders, positions for each of the strategies.

I have to look at the code.

 
ZZuretc:

I've created three EAs in MT4 with different "magics" and strategies, combined them into one EA, each strategy works separately, but when I turn on three at once, the third strategy does not modify its "magics" WHY??? everything in the tester.

And also, should put one selimit, but puts equal number of selimits. (if 2 sels, then 2 selimits bets, if 5 sels, then bets 5 selimits).

When combining 3 ---> 1 you have to follow a certain rule. Each strategy has head, torso, legs. You take all three heads. And the torso and legs, you pick the best of the three. Three torsos and six legs is excessive...

 
ZZuretc:
I'm posting expert, libraries and include files, check for errors, at first it works without errors, but then it may give a different one each time. (For testing, put a tic and moose 20)

For starters:

variables, variable visibility

how are they declared, where?

Reason: