Auftrag beendet
Spezifikation
Hello , I need to Modify an expert advisor (Trade Manager for other EAs) to add new functionality :
1) Partial Lot Size Close at Floating Loss Amount:
- Close % Partial Lot-size if Loss reached a defined amount (Note: Closing Priority will lead it the orders orders being closed first)
- Close All Modify Take Profit of Remaining Lots to Breakeven (Dollar profit of Zero when taking into account Commission)
BONUS: For the Advanced Coders, I am willing to increase my budget if you are able to achieve the configuration that is shown in the Screenshot "Part 2" . I can elaborate on this more, if you are interested/able to achieve this request.
This will require the following adjustment, modify the Magic Number the Open Orders so that the EA is able to manage them.
Here is an example of some source code that is able to achieve this, however it is not viable for my EA as it modifies the take profit of individuals orders and not the weighted average lot size of the orders for a specific symbol within a sequence.
void OnTick() { for ( int z = OrdersTotal() - 1; z >= 0; z -- ) { if ( !OrderSelect( z, SELECT_BY_POS, MODE_TRADES ) ) { Print( "OrderSelect( ", z, ", SELECT_BY_POS, MODE_TRADES ) - Error #", GetLastError() ); continue; } if ( MagicNumber != -1 && OrderMagicNumber() != MagicNumber ) continue; if ( OnlyCurrentSymbol && OrderSymbol() != _Symbol ) continue; int D = getDigits( OrderSymbol() ); double P = getPoint( OrderSymbol() ); if ( TakeProfit_B > 0.0 && OrderType() == OP_BUY ) { double correct_tp = NormalizeDouble( OrderOpenPrice() + TakeProfit_B*P, D ); if ( fabs( OrderTakeProfit() - correct_tp ) > P/20.0 && !AlreadyModified() ) { Print( "Modifying TP of buy-order #", OrderTicket(), " (", DoubleToString( OrderTakeProfit(), D ), " -> ", DoubleToString( correct_tp, D ), ")..." ); if ( !OrderModify( OrderTicket(), OrderOpenPrice(), OrderStopLoss(), correct_tp, 0 ) ) Print( "OrderModify failed with error #", GetLastError(), "!" ); else OrderSave(); } } if ( TakeProfit_S > 0.0 && OrderType() == OP_SELL ) { double correct_tp = NormalizeDouble( OrderOpenPrice() - TakeProfit_S*P, D ); if ( fabs( OrderTakeProfit() - correct_tp ) > P/20.0 && !AlreadyModified() ) { Print( "Modifying TP of sell-order #", OrderTicket(), " (", DoubleToString( OrderTakeProfit(), D ), " -> ", DoubleToString( correct_tp, D ), ")..." ); if ( !OrderModify( OrderTicket(), OrderOpenPrice(), OrderStopLoss(), correct_tp, 0 ) ) Print( "OrderModify failed with error #", GetLastError(), "!" ); else OrderSave(); } } } }
As a result you may want to use some snippets from this code:
void ModifyTP(int m) { int i,r; double tpnya,dtp,bbep,sbep,ssize,bsize; tpnya=0;dtp=0;bbep=0;sbep=0;ssize=0;bsize=0; for (i=0; i<OrdersTotal();i++) { if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue; if (OrderSymbol() != Symbol()|| OrderMagicNumber() != MagicNumber || OrderType()!=m) continue; tpnya=OrderTakeProfit(); if (m==0) {bbep += OrderOpenPrice()*OrderLots(); bsize= bsize+OrderLots();} if (m==1) {sbep += OrderOpenPrice()*OrderLots(); ssize= ssize+OrderLots();} } if (bbep>0) { bbep/=bsize; tpnya=NormalizeDouble(bbep + TP*pt,Digits); } if (sbep>0) { sbep/=ssize; tpnya=NormalizeDouble(sbep - TP*pt,Digits); } for (i=OrdersTotal()-1; i>=0; i--) { if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue; if(OrderSymbol() != Symbol()|| OrderMagicNumber() != MagicNumber|| OrderType()!=m) continue; dtp=OrderTakeProfit(); //if (m==0) {bbep += OrderOpenPrice()*OrderLots(); bsize= bsize+OrderLots();} //if (m==1) {sbep += OrderOpenPrice()*OrderLots(); ssize= bsize+OrderLots();} Print("tpnya",tpnya,": ",i); Print("dtp",dtp,": ",i); if( MathAbs(tpnya-dtp)>=pt && OrderType()==m) r = OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), tpnya, 0, CLR_NONE); } //if (bbep>0) bbep/=bsize; dtp=bbep; //if (sbep>0) sbep/=ssize; dtp=sbep; }
The key inputs would be as follows:
input string CHART_MANAGEMNET1= "====== Trade Managerment ======"; input string symbol1 = "EURUSD"; // Symbol //Symbol that the modification would occur for int MagicNumber = -1; // * MagicNumber (-1 - modify all) - this is the magic number that the EA would change the Open Orders to input double TakeProfit = 0.0; //Breakeven amount in dollars (excluding commission) - this would be the modification amount in dollars taking into account commision (Note: I don't want pips as I will use this on other symbols that are not just forex)
^//Forgot to add this input double PartialClose = .3; //Partial close percentage of lots when floating loss is reached on symbol
EXAMPLE 1:
extern bool Partial_Close= true;
IF_LOSS = -500 ( $ )
{
Close 30% of Symbol in Loss
Modify Take Profit to breakeven in dollars (taking into account Commission)
}