Bonjour,
J'utilise couramment l'EA "Close Above Profit Level" sous MT4.
J'aimerais tout simplement modifier cet EA pour définir un niveau de perte en lieu et place du niveau de profit.
C'est à dire créer un EA qui fait exactement le contraire de l'original.
Le code ne me semble pas bien long, mais étant nul en langage de programmation, je ne sais pas apporter les modifications nécessaires !
Une bonne âme pourrait-elle m'aider ?
Ci-dessous, une copie du code original.
Un grand merci !!
// ---------------------------------------------------------------------------------- +
// Mn Close above Profit level +
// ---------------------------------------------------------------------------------- +
#property copyright "Mn"
#property show_confirm
#property show_inputs
extern int mSlippage = 3;
extern string mCAP = "**** USE ENTIRELY AT OWN RISK *****";
extern string mCAPx = "**** Profit level above which the order closes *****";
extern double mProfit = 10.00;
extern string mCAPxx = "** TAKE CARE SETTING THESE OPTIONS *****";
extern string mCAPxxx = "** Set to 1 for all pairs : Set to 0 for CurrentChart Only *****";
extern int mAllSymbol = 1;
extern string mCAPxxxx = "** Set to 1 to close Longs in profit : 0 to ignore Longs *****";
extern int mLong = 1;
extern string mCAPxxxxx = "** Set to 1 to close Shorts in profit : 0 to ignore Shorts *****";
extern int mShort = 1;
// ---------------------------------------------------------------------------------- +
int start()
{
int mType, mTotal = OrdersTotal();
for(int i = mTotal-1; i>=0; i--)
{
OrderSelect(i, SELECT_BY_POS);
mType = OrderType();
bool mResult = false;
if(OrderSymbol() == Symbol() || mAllSymbol == 1)
{
if(OrderProfit() >= mProfit)
{
switch(mType)
{
case OP_BUY :
{
if(mLong == 1)
mResult = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, CLR_NONE );
break;
}
case OP_SELL :
{
if(mShort == 1)
mResult = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, CLR_NONE );
break;
}
default :
break;
}
if(mResult == false)
{
Alert("Order " , OrderTicket() , " Failed to close. Error:" , GetLastError() );
Sleep(2000);
}
} // if(OrderTakeProfit
} // if(OrderSymbol
} // for i
return(0);
}
// ---------------------------------------------------------------------------------- +
J'utilise couramment l'EA "Close Above Profit Level" sous MT4.
J'aimerais tout simplement modifier cet EA pour définir un niveau de perte en lieu et place du niveau de profit.
C'est à dire créer un EA qui fait exactement le contraire de l'original.
Le code ne me semble pas bien long, mais étant nul en langage de programmation, je ne sais pas apporter les modifications nécessaires !
Une bonne âme pourrait-elle m'aider ?
Ci-dessous, une copie du code original.
Un grand merci !!
// ---------------------------------------------------------------------------------- +
// Mn Close above Profit level +
// ---------------------------------------------------------------------------------- +
#property copyright "Mn"
#property show_confirm
#property show_inputs
extern int mSlippage = 3;
extern string mCAP = "**** USE ENTIRELY AT OWN RISK *****";
extern string mCAPx = "**** Profit level above which the order closes *****";
extern double mProfit = 10.00;
extern string mCAPxx = "** TAKE CARE SETTING THESE OPTIONS *****";
extern string mCAPxxx = "** Set to 1 for all pairs : Set to 0 for CurrentChart Only *****";
extern int mAllSymbol = 1;
extern string mCAPxxxx = "** Set to 1 to close Longs in profit : 0 to ignore Longs *****";
extern int mLong = 1;
extern string mCAPxxxxx = "** Set to 1 to close Shorts in profit : 0 to ignore Shorts *****";
extern int mShort = 1;
// ---------------------------------------------------------------------------------- +
int start()
{
int mType, mTotal = OrdersTotal();
for(int i = mTotal-1; i>=0; i--)
{
OrderSelect(i, SELECT_BY_POS);
mType = OrderType();
bool mResult = false;
if(OrderSymbol() == Symbol() || mAllSymbol == 1)
{
if(OrderProfit() >= mProfit)
{
switch(mType)
{
case OP_BUY :
{
if(mLong == 1)
mResult = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, CLR_NONE );
break;
}
case OP_SELL :
{
if(mShort == 1)
mResult = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, CLR_NONE );
break;
}
default :
break;
}
if(mResult == false)
{
Alert("Order " , OrderTicket() , " Failed to close. Error:" , GetLastError() );
Sleep(2000);
}
} // if(OrderTakeProfit
} // if(OrderSymbol
} // for i
return(0);
}
// ---------------------------------------------------------------------------------- +