Hi All,
I want to to know if there some easy way to partial close automatically on the bases of total TP.
For example
Trade buy XAUUSD 1 lot @1800 with TP 1900.
Then automatically partial close 50% 1850 ----> partial close 25% more on 1875 and Then full close 1900.
I FOUND some EA does that but i want something or any EA you know which does this for all trades. Not only to trades opened with that EA. I mean i mostly open trades from Mobile phone and i want EA to handle those trades as well.
Thanks in advance.
There are such utilities in the Market, but you need to make your own search.
Recommendations are not allowed in the forum.
Hi All,
I want to to know if there some easy way to partial close automatically on the bases of total TP.
For example
Trade buy XAUUSD 1 lot @1800 with TP 1900.
Then automatically partial close 50% 1850 ----> partial close 25% more on 1875 and Then full close 1900.
I FOUND some EA does that but i want something or any EA you know which does this for all trades. Not only to trades opened with that EA. I mean i mostly open trades from Mobile phone and i want EA to handle those trades as well.
Thanks in advance.
you can not manage your trades with ea from your mobile/cell phone, however,
there are a few free on codebase that will do what you describe -- from a desktop. just do a quick search.
HI Great people, Please, i have a similar question, i need direction on writing this final snippet to complete my bot, these are my achievements so far :
1. i have included a helper function that calculates the exact lot that risk a specific amount (in this case its 1% per trade), for a $10,000 account that should be $100 per trade
double CalculateUnitSize(string pMarket, double pMoneyCapital, double pRiskPercentage, int pStoplossPoints, double pAllowedMaxUnitSize) { //---Calculate LotSize based on Equity, Risk in decimal and StopLoss in points double maxLots, minLots, oneTickValue, moneyRisk, lotsByRisk, lotSize; int totalTickCount; maxLots = MaxUnitSizeAllowedForMargin(pMarket, pMoneyCapital, pAllowedMaxUnitSize); minLots = SymbolInfoDouble(pMarket, SYMBOL_VOLUME_MIN); oneTickValue = SymbolInfoDouble(pMarket, SYMBOL_TRADE_TICK_VALUE); // Tick value of the asset moneyRisk = (pRiskPercentage/100) * pMoneyCapital; totalTickCount = ToTicksCount(pMarket, pStoplossPoints); //---Calculate the Lot size according to Risk. lotsByRisk = moneyRisk / (totalTickCount * oneTickValue); lotSize = MathMax(MathMin(lotsByRisk, maxLots), minLots); lotSize = NormalizeLots(pMarket, lotSize); return (lotSize); } double MaxUnitSizeAllowedForMargin(string pMarket, double pMoneyCapital, double pAllowedMaxUnitSize) { // Calculate Lot size according to Equity. double marginForOneLot, lotsPossible; if(OrderCalcMargin(ORDER_TYPE_BUY, pMarket, 1, SymbolInfoDouble(pMarket, SYMBOL_ASK), marginForOneLot)) { // Calculate margin required for 1 lot lotsPossible = pMoneyCapital * 0.98 / marginForOneLot; lotsPossible = MathMin(lotsPossible, MathMin(pAllowedMaxUnitSize, SymbolInfoDouble(pMarket, SYMBOL_VOLUME_MAX))); lotsPossible = NormalizeLots(pMarket, lotsPossible); } else { lotsPossible = SymbolInfoDouble(pMarket, SYMBOL_VOLUME_MAX); } return (lotsPossible); } int ToTicksCount(string pMarket, uint pPointsCount) { double uticksize = SymbolInfoDouble(pMarket, SYMBOL_TRADE_TICK_SIZE); int utickscount = uticksize > 0 ? (int)((pPointsCount / uticksize) * uticksize) : 0; //-- fix prices by ticksize return utickscount; } double NormalizeLots(string pMarket, double pLots) { double lotstep = SymbolInfoDouble(pMarket, SYMBOL_VOLUME_STEP); int lotdigits = (int) - MathLog10(lotstep); return NormalizeDouble(pLots, lotdigits); }
2. i place a trade using a breakout strategy and obviously only risk 1% each time thanks to the above function , but there is one small dilemma;
sometimes the price breaks through but can't quite hit the TP which is set by me arbitrarily, I was wondering if there is a way to close as much of the running trade as possible,
so for example;
since we are only risking $100 per trade,
if we have a BUY trade with a TP set at 100pts,
and my function above accurately calculated we need to place 1lots to make $100 at 100pts,
and SL set at the same 100pts so 1:1 RR,
how can one close out 10$ partially after every 10 point increase in price towards my TP programmatically,
figuring out exactly how much out of the 1lot to partially close out each time is extremely tricky in code because remember the distance from the point the trade was taken increases as price gets closer to the TP in this example
e.g
at 10 points from the BUY price we need to close out x amount of lots ,
at 20 points from the BUY price we need to close out y amount of lots ,
at 30 points from the BUY price we need to close out z amount of lots ,
...and so on until we reach 90points
at which point if we add all the lot we closed it should still equal 1lot which is what we placed the trade with
in summary i want to take a $100 trade and close out 10$ after each 10% move towards the price , THANKS
Hi
If you have the EA which close partially trades like you want, you can modify the code and make the EA to work on every trade (not only trades from the EA).
That would be the simplest solution, so you allow EA to change all trades not only with chosen magic number or symbol even.
Best Regards
enum isCheck { isCheck_1 =1, // YES isCheck_2 =2, // NO }; int Bars_PARTIAL = 0; input group "# Partial Close / Breakeven #"; input isCheck Partial_Type = isCheck_1; // Min Reward Partial Close / Breakeven input double MinReward_TP1 = 500; // Min Reward $ (Ticket) input double Partial_Lot1 = 33; // Partial Lot % ( Ticket ) input double MinReward_TP2 = 1000; // Min Reward $ (Ticket) input double Partial_Lot2 = 33; // Partial Lot % ( Ticket ) for(int i=PositionsTotal()-1;i>=0;i--) { ulong PositionTicket = m_position.Ticket(); datetime PositionTime = m_position.Time(); if(Partial_Type == 1){ PartialClose(PositionTicket,PositionTime); } } // CUSTOM FUNCTIONS double Position_Profit(ulong PosID, datetime StartTime) { double result =0; if (HistorySelect(StartTime, TimeCurrent())) { uint total=HistoryDealsTotal(); ulong ticket=0; //long deal_entry; for (uint i=0;i<total;i++) { if((ticket=HistoryDealGetTicket(i))>0) { ulong dealPosID = HistoryDealGetInteger(ticket,DEAL_POSITION_ID); if(dealPosID == PosID){ result+= PositionGetDouble(POSITION_PROFIT); result+= HistoryDealGetDouble(dealPosID, DEAL_COMMISSION); result+= PositionGetDouble(POSITION_SWAP); } } } } return(NormalizeDouble(result,2)); } void PartialClose(ulong GetTicket, datetime StartTime){ if (HistorySelect(StartTime, TimeCurrent())) { uint total=HistoryDealsTotal(); ulong ticket=0; long type; double sl; double tp; long deal_entry; double price; double lot; double spread; double partialLot1; double partialLot2; double remainingLot; for (uint i=0;i<total;i++) { if((ticket=HistoryDealGetTicket(i))>0) { if(ticket == GetTicket){ type =HistoryDealGetInteger(ticket,DEAL_TYPE);//0 BUY | 1 SELL deal_entry = HistoryDealGetInteger(ticket,DEAL_ENTRY); if(deal_entry==DEAL_ENTRY_IN){ sl = HistoryDealGetDouble(GetTicket, DEAL_SL); tp = HistoryDealGetDouble(GetTicket, DEAL_TP); price = HistoryDealGetDouble(GetTicket,DEAL_PRICE); lot = HistoryDealGetDouble(GetTicket,DEAL_VOLUME); partialLot1 = NormalizeDouble(lot*Partial_Lot1/100,2); partialLot2 = NormalizeDouble(lot*Partial_Lot2/100,2); remainingLot = lot-partialLot1; if(m_position.Volume() == lot){ if(type == 0){//BUY if(Position_Profit(GetTicket,StartTime) >= MinReward_TP1){ if(Bars_PARTIAL!=Bars(m_symbol.Name(),0)){ if(m_trade.PositionClosePartial(GetTicket,partialLot1)){ Bars_PARTIAL=Bars(m_symbol.Name(),0); if(m_position.StopLoss() < price || m_position.StopLoss() == 0){ spread = m_symbol.Ask() - m_symbol.Bid(); price = NormalizeDouble((price+spread),_Digits); m_trade.PositionModify(GetTicket,price,tp); } Print("TP1 hits, Orjinal Lot: ",lot," | Closed Partial : ",partialLot1); } } } }else if(type == 1){//SELL if(Position_Profit(GetTicket,StartTime) >= MinReward_TP1){ if(Bars_PARTIAL!=Bars(m_symbol.Name(),0)){ if(m_trade.PositionClosePartial(GetTicket,partialLot1)){ Bars_PARTIAL=Bars(m_symbol.Name(),0); if(m_position.StopLoss() > price || m_position.StopLoss() == 0){ spread = m_symbol.Ask() - m_symbol.Bid(); price = NormalizeDouble((price-spread),_Digits); m_trade.PositionModify(GetTicket,price,tp); } Print("TP1 hits, Orjinal Lot: ",lot," | Closed Partial : ",partialLot1); } } } } }else if(m_position.Volume() == remainingLot){ if(type == 0){//BUY if(Position_Profit(GetTicket,StartTime) >= MinReward_TP2){ if(Bars_PARTIAL!=Bars(m_symbol.Name(),0)){ if(m_trade.PositionClosePartial(GetTicket,partialLot2)){ Bars_PARTIAL=Bars(m_symbol.Name(),0); if(m_position.StopLoss() < price || m_position.StopLoss() == 0){ spread = m_symbol.Ask() - m_symbol.Bid(); price = NormalizeDouble((price+spread),_Digits); m_trade.PositionModify(GetTicket,price,tp); } Print("TP2 hits, Orjinal Lot: ",lot," | Closed Partial : ",partialLot2); } } } }else if(type == 1){//SELL if(Position_Profit(GetTicket,StartTime) >= MinReward_TP2){ if(Bars_PARTIAL!=Bars(m_symbol.Name(),0)){ if(m_trade.PositionClosePartial(GetTicket,partialLot2)){ Bars_PARTIAL=Bars(m_symbol.Name(),0); if(m_position.StopLoss() > price || m_position.StopLoss() == 0){ spread = m_symbol.Ask() - m_symbol.Bid(); price = NormalizeDouble((price-spread),_Digits); m_trade.PositionModify(GetTicket,price,tp); } Print("TP2 hits, Orjinal Lot: ",lot," | Closed Partial : ",partialLot2); } } } } } } } } } } }
You can use it like this.
I wrote it if positions reaches profit (ex 500$ - tp1, close partial.) if reaches (ex 1.000 usd - tp2, close partial)
Edit: Breakeven
Next time, please post your code properly without all the extraneous white-space. For now, I have edited your previous post and corrected it.
- 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,
I want to to know if there some easy way to partial close automatically on the bases of total TP.
For example
Trade buy XAUUSD 1 lot @1800 with TP 1900.
Then automatically partial close 50% 1850 ----> partial close 25% more on 1875 and Then full close 1900.
I FOUND some EA does that but i want something or any EA you know which does this for all trades. Not only to trades opened with that EA. I mean i mostly open trades from Mobile phone and i want EA to handle those trades as well.
Thanks in advance.