- Coding help
- MQL4 Programming Help!!! - Only One Opened Trade Pair, Per Signal.
- Need code to limit total trade in the account and only 1 trade in the chart
Please insert sections of code using the SRC button.
I'm afraid that your post in this format is confusing and you will find that many people will not be bothered to try to decipher it.
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) continue;
if(OrderSymbol()!=Symbol()) continue; nearPosition=true;
if(int(Time[0]-OrderOpenTime())>CandleInterval*PeriodSeconds(0)) nearPosition=false;
}
The SRC button is at the top of the reply panel
Click it , paste your code into the box and click insert
for(int i=OrdersTotal()-1; i>=0; i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) continue; if(OrderSymbol()!=Symbol()) continue; nearPosition=true; if(int(Time[0]-OrderOpenTime())>CandleInterval*PeriodSeconds(0)) nearPosition=false; }
I would indent the code personally, makes it easier to follow
for(int i=OrdersTotal()-1; i>=0; i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) continue; if(OrderSymbol()!=Symbol()) continue; nearPosition=true; if(int(Time[0]-OrderOpenTime())>CandleInterval*PeriodSeconds(0)) nearPosition=false; }
I don't know what you expect from this, but the value of nearPosition is set to true at every pass of the loop where the symbol is the chart symbol. It will only be set to false by the check on the trade at position 0 or the lowest index where the symbol is the chart symbol.
if it's in the chart symbol, can any special case happen as you concern?
Could you please share some examples?
dear GumRai,
if it's in the chart symbol, can any special case happen as you concern?
Could you please share some examples?
Sorry, I don't understand the question.
Here is an example (not compiled, not tested)
This is happening too often now. I put code in SRC but it is not appearing in the post. Sometimes works, sometimes not
datetime earliest_order_time=TimeCurrent(); int earliest_ticket=-1; for(int x=OrdersTotal()-1;x>=0;x--) { if(OrderSelect(x,SELECT_BY_POS,MODE_TRADES)) if(OrderSymbol()==Symbol()) { if(OrderOpenTime()<earliest_order_time) { earliest_order_time=OrderOpenTime(); earliest_ticket=OrderTicket(); } } } if(earliest_ticket!=-1) { //Do whatever you want to do }
If you use OrderSelect to select 'OrdersTotal()-1' , it will be the earliest order open or pending.
if select '0', it will be the latest order. Correct?
However, you said "I don't think that it is reliable to assume that the orders are definitely in chronological order."
Then I asked why and if you have any examples for "not reiable".
Ï don't know in what order the orders are stored.
I have read in the forum that it is best not to assume that they are stored in any set order. That is why I will check as in the example code that I posted.
Note that once pending orders are triggered, their OrderOpenTime changes to the trigger time.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use