discection of a function for closing orders

 

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? 
}

 
Dmitri Mikhalev:

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

Check out the mql help so you know the type of function you're dealing with. Eg OrderClose() is a bool function so will only tell you if the order was closed ,true. Or failed to close - false....



 
Iknow, I have checked the mql help! :D that's where I have amassed the stuff that I have written up in red, but then my reptile brain stops working and I need extra help! :)
 
andrew4789:
I'd be starting with some basics. For example print on the chart all the existing orders showing:
Symbol, Lots, Ordertype etc
I use Comment() to do that so it shows on the chart....
Reason: