[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 314

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
bool Times=true;
if (OrdersTotal()>0){
for(int g=OrdersTotal()-1; g>=0; g--){
datetime t;
OrderSelect(g,SELECT_BY_POS);
if (OrderMagicNumber()!=MagicNumber){continue;}
if (t<OrderOpenTime() || g==OrdersTotal()-1) t=OrderOpenTime();
if (t>=Time[0]) Times=false;}}
is this correct?
bool Times=true;
datetime t=Time[1];
if (OrdersTotal()>0){
for(int g=OrdersTotal()-1; g>=0; g--){
OrderSelect(g,SELECT_BY_POS);
if (OrderMagicNumber()!=MagicNumber){continue;}
if (t<OrderOpenTime()) t=OrderOpenTime();
if (t>=Time[0]) Times=false;}}
is this correct?
No. You don't need to declare a variable inside the loop at each iteration.
I hope I didn't delete anything, otherwise the compiler would complain about the word else:
bool Torg=true;
if(OrdersTotal()>0){for(int i=OrdersTotal()-1;i>=0;i--){
if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)){
if(OrderMagicNumber()!=MagicNumber) continue;
if(OrderOpenTime()>=Time[0]) Torg=false;
}
}
}
I hope I didn't delete anything I needed, otherwise the compiler would complain about the word else:
if(OrdersTotal()>0){// unnecessary line - if there are no orders, then the loop counter will be at zero and the loop will not be executed
for(int i=OrdersTotal()-1;i>=0;i--){// go through all orders
if (! OrderSelect(i, SELECT_BY_POS, MODE_TRADES)){// if no order is selected, then...
if(OrderMagicNumber()!=MagicNumber) continue; //if the magic number is not ours, then proceed to another order
if(OrderOpenTime()>=Time[0]) Torg=false;
}
// But what if the order is still selected from the list?
}
}
P.S.
The line that signals an error number when selecting an order should not have been removed for some reason - it sometimes happens that it blows up. In general, error handling is better used wherever it can occur.
if(OrdersTotal()>0){// unnecessary line - if there are no orders, the loop counter will be at zero and the loop will not be executed
for(int i=OrdersTotal()-1;i>=0;i--){// go through all orders
if (! OrderSelect(i, SELECT_BY_POS, MODE_TRADES)){// if no order is selected, then.
if(OrderMagicNumber()!=MagicNumber) continue; //if the magic number is not ours, then proceed to another order
if(OrderOpenTime()>=Time[0]) Torg=false;
}
// But what if the order is still selected from the list?
}
}
bool Torg;
if(OrdersTotal()==0) Torg=true;
if(OrdersTotal()>0){
for(int i=OrdersTotal()-1;i>=0;i--){
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)){
if(OrderMagicNumber()!=MagicNumber) continue;
if(OrderOpenTime()>=Time[0]) Torg=false;
if(OrderOpenTime()<Time[0]) Torg=true;
}
}
}
How about this?
What if you try to check this loop in the script yourself? Well, just byprinting the result - what position the Torg variable takes in different cases. Do you think you can't do it yourself?
I don't think so.
Download - it will help - http://depositfiles.com/files/eg4fmn3bp