Jr_attain: It closes a position only when the next signal happens. Then it, instantly, opens another position, the opposite to the first.
- No it does not. It closes the order and then on some subsequent tick it opens another position.
That can only happen if Teste_condicao(...) has returned a 1 or a 5 if(Sinal_vencedor==1) { ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,"My EA v0.91",NumeroMagico,0,Green);
Don't check levels. Check for a change in level. if(Sinal_vencedor==1 && Sinal_perdedor==0){ ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,"My EA v0.91",NumeroMagico,0,Green);
if(total>0) { for(cnt=0;cnt<total;cnt++) {
The if statement is unnecessary; if the count is zero the for loop does nothing. In the presence of multiple orders (one EA multiple charts, multiple EA's, manual trading) you must count down when closing/deleting/modifying in a position loop. Get in the habit of always counting down. Loops and Closing or Deleting Orders - MQL4 forumDon't use constants when you mean an enumeration static int condicao_atual = 0; condicao_atual=1; condicao_atual=5; if(Sinal_vencedor==1) { Sinal_perdedor=5; if(Sinal_vencedor==5) { if((Sinal_vencedor==0) && (Sinal_perdedor==1)) Sinal_vencedor=1; if((Sinal_vencedor==0) && (Sinal_perdedor==5)) Sinal_vencedor=5; if(Sinal_vencedor==5) { if(Sinal_vencedor==1) {
Write self documenting code. enum Direction { NONE, SHORT, LONG=5 }; static Direction condicao_atual = NONE; condicao_atual=SHORT; condicao_atual=LONG; if(Sinal_vencedor==SHORT) { Sinal_perdedor=LONG; if(Sinal_vencedor==LONG) { if(Sinal_vencedor==NONE && Sinal_perdedor==SHORT) Sinal_vencedor=SHORT; if(Sinal_vencedor==NONE && Sinal_perdedor== LONG) Sinal_vencedor=LONG; if(Sinal_vencedor==LONG) { if(Sinal_vencedor==SHORT) {
WHRoeder:
- No it does not. It closes the order and then on some subsequent tick it opens another position. That can only happen if Teste_condicao(...) has returned a 1 or a 5
- The if statement is unnecessary; if the count is zero the for loop does nothing. In the presence of multiple orders (one EA multiple charts, multiple EA's, manual trading) you must count down when closing/deleting/modifying in a position loop. Get in the habit of always counting down. Loops and Closing or Deleting Orders - MQL4 forum
Don't use constants when you mean an enumeration Write self documenting code.
WHRoeder,
Thank you so much for the valuable help.
JR
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello to all,
Regarding the code scheme below, could anybody help me? It closes a position only when the next signal happens. Then it, instantly, opens another position, the opposite to the first.
However, in the case of 'condicao=0', it was intended just to close the current position and 'do nothing more', only wait for a next signal and, finally, open a new position.
The way it is, all the profit may return to the market.
Thanks a lot for any help.
JR