But to become more professional, it needs a few modifications
We want this code to calculate the volume of positions (buy and sell) separately and also to close the positions separately.
When I use your code and just change the magic number, it does the calculations well
But if I want to use 2 magic separately, only the positions (bye with magic 3) are calculated correctly and it is closed and the positions (tuberculosis with magic 4) are not calculated and are not closed.
I modified the code like this and got no result
//+------------------------------------------------------------------+void GetProfitBuy()
{
//Closingif(TheCloseState==true)
{
TheCloseState=false;
for(int i = OrdersTotal() -1; i >= 0; i--)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) && OrderSymbol() == "GBPUSD" && OrderMagicNumber() == Magic3 && OrderType()==OP_BUY)//Exactly OrderType()should <=1 and many other conditions you want
{
bool result=OrderClose ( OrderTicket(), OrderLots(), OrderClosePrice(),5,Red);
if(result==false)
{
TheCloseState=true;//If Close Failed Still On Closingcontinue;
}
}
}//end forif(TheCloseState==true) return;
}
GetTotalLotsProfit();//get Lots and Profitif(totalOpenLots > 0 && totalProfit > 0)
{
MaxPositionProfit=1000*totalOpenLots*PercentageRiskValue;
//100 =1000*1.0 *0.1;//for example: 1.0 Lot -- 10% RiskValue Need 100.00$ Profitif(totalProfit >=MaxPositionProfit)
{
TheCloseState=true;
return;
}
}
}
//+------------------------------------------------------------------+void GetTotalLotsProfit()
{
totalProfit = 0;
totalOpenLots = 0;
for(int i = OrdersTotal() -1; i >= 0; i--)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) && OrderSymbol() == "GBPUSD" && OrderMagicNumber() == Magic3 && OrderType()==OP_BUY)//Exactly OrderType()should <=1 and many other conditions you want
{
totalOpenLots += OrderLots();
totalProfit += (OrderProfit() + OrderCommission() + OrderSwap());
}
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////void GetProfitSell()
{
//Closingif(TheCloseState==true)
{
TheCloseState=false;
for(int i = OrdersTotal() -1; i >= 0; i--)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) && OrderSymbol() == "GBPUSD" && OrderMagicNumber() == Magic4 && OrderType()==OP_SELL)//Exactly OrderType()should <=1 and many other conditions you want
{
bool result=OrderClose ( OrderTicket(), OrderLots(), OrderClosePrice(),5,Red);
if(result==false)
{
TheCloseState=true;//If Close Failed Still On Closingcontinue;
}
}
}//end forif(TheCloseState==true) return;
}
GetTotalLotsProfitSell();//get Lots and Profitif(totalOpenLots > 0 && totalProfit > 0)
{
MaxPositionProfit=1000*totalOpenLots*PercentageRiskValue;
//100 =1000*1.0 *0.1;//for example: 1.0 Lot -- 10% RiskValue Need 100.00$ Profitif(totalProfit >=MaxPositionProfit)
{
TheCloseState=true;
return;
}
}
}
//+------------------------------------------------------------------+void GetTotalLotsProfitSell()
{
totalProfit = 0;
totalOpenLots = 0;
for(int i = OrdersTotal() -1; i >= 0; i--)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) && OrderSymbol() == "GBPUSD" && OrderMagicNumber() == Magic4 && OrderType()==OP_SELL)//Exactly OrderType()should <=1 and many other conditions you want
{
totalOpenLots += OrderLots();
totalProfit += (OrderProfit() + OrderCommission() + OrderSwap());
}
}
}
But to become more professional, it needs a few modifications
We want this code to calculate the volume of positions (buy and sell) separately and also to close the positions separately.
When I use your code and just change the magic number, it does the calculations well
But if I want to use 2 magic separately, only the positions (bye with magic 3) are calculated correctly and it is closed and the positions (tuberculosis with magic 4) are not calculated and are not closed.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Hello to all professors
I wrote another code with higher accuracy
But I think it should work properly
But I could not draw conclusions from this code
Where is my code problem?
Just For Reference
Try this one.... test yourself before using.....
Try this one.... test yourself before using.....
Some Shortcomings :
First of All,one For() Loop cannot make sure that all orders can be colsed those should be,if some failed they will be ignored by your code;
Secondly,we can get total Lots and Profit in only one For() Loop,that is higher efficient.
Hello to all professors, with this code I want to come and calculate the whole Lot first (for example, purchase)
Then we calculate that if 10% of the imported Lot goes to profit, it will close all the orders.
But it has a little problem and it does not do that.
Just For Reference
Hello dear teacher and friend
I tried your code, it works properly
But to become more professional, it needs a few modifications
We want this code to calculate the volume of positions (buy and sell) separately and also to close the positions separately.
When I use your code and just change the magic number, it does the calculations well
But if I want to use 2 magic separately, only the positions (bye with magic 3) are calculated correctly and it is closed and the positions (tuberculosis with magic 4) are not calculated and are not closed.
I modified the code like this and got no result
Thanks to all the professors (for helping)
The problem was solved.
Hello dear teacher and friend
I tried your code, it works properly
But to become more professional, it needs a few modifications
We want this code to calculate the volume of positions (buy and sell) separately and also to close the positions separately.
When I use your code and just change the magic number, it does the calculations well
But if I want to use 2 magic separately, only the positions (bye with magic 3) are calculated correctly and it is closed and the positions (tuberculosis with magic 4) are not calculated and are not closed.
I modified the code like this and got no result
I've tested only by mind because there is no order open module in this code
I've tested only by mind because there is no order open module in this code