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
This condition does not guarantee that only one position will be opened.
Anyway, comparing open time in the condition will guarantee it. There are a few solutions
Anyway, comparing open time in the condition will guarantee it. There are a few solutions
I have provided links where everything is shown in detail.
Orders and Positions are different.
Positions:
Orders:
In MQL5 the word "orders" is meaning pending orders only. But everything was "order" in MQL4.
I know order and position. i have gold position in $3250,I will add 1 lot of gold position for each $1 price increase.when price in $3251, the Ontick() repeat open sell ,due to delays in broker , somethimes i have 2 short in $3251,
for example: the gold rise in $ 3220 ,the first tick find not position in 3220,it send sell order,due to delays in broker,the second tick also find not position in 3220, open sell again,so i have the 2 position in $ 3220, but i just want to one position.
1. just track the fulfillment of your conditions and mark it with a flag after execution: bool limiter = true; Now in the conditions themselves, set the flag false response as an additional condition so that the conditions can be true: if(!limiter). Now you can most easily set the time gate filter in seconds for the "limiter" logic by using the datetime() and setting it to the required time in seconds, which will set your limiter flag to true and create a suitable delay for you.
2. same time while your conditions are being met use another flag that checks the status of the transaction and set its value. bool processing = true. Now listen to the output of OrderSend(request, result) and if you have received the response result.retcode==TRADE_RETCODE_DONE , it means your order is executed and now you can set status FALSE for your processing flag. Add this flag status also to your transaction acceptance logicNow we have NOR gate logic , this means that you need to have two flags with status false to get our condition true. You must meet the following conditions: if (!limiter && !processing), which allows you to take new trades.
For even faster management of active transactions, if you want to open the exact number of desired trades without the additional delay of the limit flag set on the timer , you can do this: limiter = processing ? limiter : false;
I'm not a big MQL5 syntax guru, but as always in programming, things come down to the coding logic itself. So, at the logical level, such a solution should be foolproof. A similar approach is recommended and it doesn't matter whether you work with OnTick-based HFT systems or with timeframe based executions. Would be useful though to check out posts by professionals like fxsaber, they know well the ins and outs of the MQL5 syntax. You won't understand at first, but understanding will come with time.