((nick35))
Nuovo Utente
- Registrato
- 18/1/11
- Messaggi
- 1.763
- Punti reazioni
- 73
ciao, apprezzo molto la disponibilità! mi servirebbe un'aggiunta a questo expert che ho fatto io scopiazzando qua e là, attualmente se i trades son in positivo di almeno un numero predefinito di pips sposta lo stop in pari. vorrei che chiudesse tutte le posizioni qualora il guadagno (parliamo di floating non di beginning equity+x )raggiunga x euro, puoi aiutarmi?
extern double e_BreakEvenStop = 15;
double g_Point = 0.0001;
int init() {
if (Point == 0.00001) g_Point = 0.0001;
else {
if (Point == 0.001) g_Point = 0.01;
else g_Point = Point;
}
return (0);
}
//+------------------------------------------------------------------+
//| script program start function |
//+------------------------------------------------------------------+
int start()
{
//----
string curr = Symbol();
int ot = OrdersTotal();
int ords[200], ordType[200], ordTicket[200]; double ordLots[200];
string ordComments[200];
int ix=0;
for (int i=0; i<ot; i++)
{
int o = OrderSelect(i, SELECT_BY_POS);
if (OrderSymbol() == Symbol())
if ((OrderType() == OP_BUY) || (OrderType() == OP_SELL))
{
double sl = 0;
if ((OrderType() == OP_BUY) && (Bid - OrderOpenPrice()) > (e_BreakEvenStop * g_Point))
sl = OrderOpenPrice() ;
if ((OrderType() == OP_SELL) && (OrderOpenPrice() - Ask) > (e_BreakEvenStop * g_Point))
sl = OrderOpenPrice() ;
if (sl != 0)
OrderModify(OrderTicket(), OrderOpenPrice(), sl, OrderTakeProfit(), 0);
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
in casi anaoghi uso un ea come questo su altro chart:
extern double My_Money_Profit_Target=300; //The amount of money profit at which you want to close ALL open trades.
int Slippage=5;
int i;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
if (AccountProfit()>= My_Money_Profit_Target)
{
for(i=OrdersTotal()-1;i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS);
int type = OrderType();
bool result = false;
switch(type)
{
//Close opened long positions
case OP_BUY : result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),Slippage,Pink);
break;
//Close opened short positions
case OP_SELL : result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),Slippage,Pink);
}
if(result == false)
{
Sleep(3000);
}
}
Print ("Account Profit Reached. All Open Trades Have Been Closed");
return(0);
}
Comment("Balance: ",AccountBalance(),", Account Equity: ",AccountEquity(),", Account Profit: ",AccountProfit(),
"\nMy Account Profit Target: ",My_Money_Profit_Target);
return(0);
}