Hi all,
So I'm new to this, and I am trying to dissect a function for closing orders and translate it to English, in order to actually learn something. I have to say it's a bit slow and I need help. So please help! :)
I have highlighted my questions / comments in red so they are easily spotted
Tank you :)
//Function for closing an order
bool CloseOrder()
//
We start by declaring the function
{
int i;
//some variables
double Price_close;
int count = 0;
for(i=OrdersTotal()-1; i>=0; i--) //here,
the loop takes the total number of all orders (pending and open, right?) and subtracts 1 from that number until everything is subtracted.
Yes? :)
{
if(OrderSelect(i, SELECT_BY_POS,
MODE_TRADES))
//so here, we basically select an order, right? and emm..
I don't know, is this generally how you select orders?
if(OrderSymbol()==Symbol())
// so then, the order symbol has to be the same as symbol. Can they be different? What is the difference between those two?
if(OrderMagicNumber()==magik) // and
then, the order's magic number has to be the same as an integer that I declared earlier, which is 5. Why? I don't know...
{
if(OrderType()==OP_BUY) // So when the above stuff is as it should, we end up here, and if it's a
BUY-order,
Price_close = NormalizeDouble(Bid, Digits); //..then
we sell it, round the decimals aaaannd? why do we round the decimals? Are they printed automatically?
if(OrderType() == OP_SELL) //Same
stuff for sell orders
Price_close = NormalizeDouble(Ask, Digits);
if(OrderClose(OrderTicket(),OrderLots(),Price_close,slippage))
// and then, if there is an order that got closed, we
ask the function to return all the stuff in the parenthesis for us, like the price, and the slippage and whatnot.
return(true);
}
}
return(false);
//Why is it false here?
}Fals

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi all,
So I'm new to this, and I am trying to dissect a function for closing orders and translate it to English, in order to actually learn something. I have to say it's a bit slow and I need help. So please help! :)
I have highlighted my questions / comments in red so they are easily spotted
Tank you :)
//Function for closing an order
bool CloseOrder() // We start by declaring the function
{
int i; //some variables
double Price_close;
int count = 0;
for(i=OrdersTotal()-1; i>=0; i--) //here, the loop takes the total number of all orders (pending and open, right?) and subtracts 1 from that number until everything is subtracted. Yes? :)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) //so here, we basically select an order, right? and emm.. I don't know, is this generally how you select orders?
if(OrderSymbol()==Symbol()) // so then, the order symbol has to be the same as symbol. Can they be different? What is the difference between those two?
if(OrderMagicNumber()==magik) // and then, the order's magic number has to be the same as an integer that I declared earlier, which is 5. Why? I don't know...
{
if(OrderType()==OP_BUY) // So when the above stuff is as it should, we end up here, and if it's a BUY-order,
Price_close = NormalizeDouble(Bid, Digits); //..then we sell it, round the decimals aaaannd? why do we round the decimals? Are they printed automatically?
if(OrderType() == OP_SELL) //Same stuff for sell orders
Price_close = NormalizeDouble(Ask, Digits);
if(OrderClose(OrderTicket(),OrderLots(),Price_close,slippage)) // and then, if there is an order that got closed, we ask the function to return all the stuff in the parenthesis for us, like the price, and the slippage and whatnot.
return(true);
}
}
return(false); //Why is it false here?
}