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.
Hi dear,
So you should get the sum of OrderLots() for all open orders. (let's call it totalLots)
Then sum of OredrProfit() for all open orders. (let's call it totalProfit)
if(totalProfit >= totalLots*100/PercentageRisValue) { //close all open orders }
is this what you want?
I apologize if my explanation was not complete and confused you professors
Sample :
TotalLots x TotalProfit =10%of Profit Lot
Postion No1: 1.12000 0.10
Postion No1: 1.11900 0.15
Postion No1: 1.11800 0.20
Postion No1: 1.11700 0.25
Postion No1: 1.11600 0.30
TotalLot Is : 1.00
Whenever our profit reaches 10% lot, the total profit is $ 100, all these 5 positions must be closed
Thanks,
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?
extern int Magic=0; input double PercentageRiskValue=0.10; double MaxPositionProfit; //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { totalOpenLots(); totalProfit(); } //+------------------------------------------------------------------+ double totalOpenLots() { double totalOpenLots = 0; for(int i = OrdersTotal() -1; i >= 0; i--) { if(OrderSelect(i, SELECT_BY_POS) && OrderSymbol() == "GBPUSD" && OrderMagicNumber() == Magic) totalOpenLots += OrderLots(); Comment ("totalOpenLots",totalOpenLots); } return totalOpenLots; } //+------------------------------------------------------------------+ double totalProfit() { double totalProfit = 0; for(int i = OrdersTotal() -1; i >= 0; i--) { if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) && OrderSymbol() == "GBPUSD" && OrderMagicNumber() == Magic) { totalProfit += (OrderProfit() + OrderCommission() + OrderSwap()); MaxPositionProfit=(totalOpenLots()/100*PercentageRiskValue); if (totalProfit > MaxPositionProfit) { bool result=OrderClose ( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(),MODE_BID),5,Red); Comment ("Error - failed to OrderClose."); } } } return totalProfit; }
It's simple, but I think I'm a little wrong
With this code, every time every purification is closed after 10 pips in profit
int Magic=0; int Magic8=8; //+------------------------------------------------------------------+ void OnTick() { Trail2(); } //+------------------------------------------------------------------+ void Trail2() { bool rest; int total = OrdersTotal(); for(int i=total-1; i>=0; i--) { rest=OrderSelect(i, SELECT_BY_POS); int type = OrderType(); bool result = false; // Buy if( OrderMagicNumber()==Magic && (((Bid-OrderOpenPrice())/Point)>100 ) && OrderType()==OP_BUY ) result = OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, CLR_NONE); // Sell if( OrderMagicNumber()==Magic8 && (((OrderOpenPrice()-Ask)/Point)>100) && OrderType()==OP_SELL ) result = OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, CLR_NONE); } }
And here I came up with another function to write the sum of the lots
void totalOpenLots() { double totalOpenLots = 0; for(int iPos = OrdersTotal()-1; iPos >= 0 ; iPos--) if ( OrderSelect(iPos, SELECT_BY_POS) // Only my orders w/ && OrderMagicNumber() == Magic // my magic number && OrderSymbol() == "GBPUSD" // and my pair. ){ totalOpenLots += OrderLots(); Print ("totalOpenLots:" ,totalOpenLots); } }
Now how to close all positions whenever the sum of all positions is multiplied by 10 pips
I mean, how do I integrate this first code with 2 and
Thankful
It's simple, but I think I'm a little wrong
With this code, every time every purification is closed after 10 pips in profit
And here I came up with another function to write the sum of the lots
Now how to close all positions whenever the sum of all positions is multiplied by 10 pips
I mean, how do I integrate this first code with 2 and
Thankful
if (AccountProfit() > totalOpenLots * 100) // is the condition you looking for.
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?
when you're calculating this part:
MaxPositionProfit=(totalOpenLots()/100*PercentageRiskValue);
if totalOpenLots is 1, and Risk is 10, then MaxPositionsProfit equals 0.1 . but you want it to be 100.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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.