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
The position is reversed because the program sends two identical requests to the server. The program sends two identical requests to the server because its code doesn't check for an earlier sent request (and doesn't check for the result of processing this request on the server).
Yedelkin writes: its code doesn't check for a previously sent request. Can you tell me which function does this check?
Everyone has a different understanding of the right code. So you have to write the "correct" code in the end. And as another tip - try to see if this code works in the right way (schematic use of sentRequest flag):
Everyone has a different understanding of the right code. So you have to write the "correct" code in the end. And as another tip - try to see if this code works in the right key (schematic use of sentRequest flag):
Thank you very much! Trying it out...
The result is as follows: the code properly closes a long position and does not open a short one... When re-opening a long position, the EA does not close it according to the condition. There are messages in the EA window all the time:
How can I use this code in the Expert Advisor body, if it only works once)?
oldiol: При повторном открытии лонга, эксперт не закрывает больше позу по условию. В окне эксперта всё время идут сообщения: Как же использовать этот код в теле эксперта, если он работает только 1 раз)?
It should be quite simple in this matter. In the schematic code the sentRequest flag should be set to zero if the open position is not a Buy position (last line of code). See why this flag is not set to zero in your code when either there is no open position or the open position is not a Buy position.
Hooray! It worked)))) Removed if(sentRequest) sentRequest=false; And wrote before the block if(PositionsTotal()==0) sentRequest=false; Thanks a lot to Yedelkin for his help, GOOD Luck!
oldiol : When reopening a long, EA does not close the position by condition anymore. There are messages in EA window all the time: How can I use this code in EA body, if it works only 1 time)? Sorry, my mistake... There is one more condition in the code
if(PositionSelect(_Symbol)==true) // there is an open position
{
POSITION CLOSE BLOCK
} // ... therefore
if(sentRequest) sentRequest=false;// placed it behind the next bracket and everything works perfectly. Yedelkin THANK YOU!