#property description "Based from Ronz AutoSL-TP"
#property version "1.3"
#property strict
#include <Trade\Trade.mqh> CTrade trade;
enum ENUM_CHARTSYMBOL
{
CurrentChartSymbol=0,//Current Chart Only
AllOpenOrder=1//All Opened Orders
};
enum ENUM_SLTP_MODE
{
Server=0,//Place SL n TP
Client=1 //Hidden SL n TP
};
enum ENUM_LOCKPROFIT_ENABLE
{
LP_DISABLE=0,//Disable
LP_ENABLE=1//Enable
};
enum ENUM_TRAILINGSTOP_METHOD
{
TS_NONE=0,//No Trailing Stop
TS_CLASSIC=1,//Classic
TS_STEP_DISTANCE=2,//Step Keep Distance
TS_STEP_BY_STEP=3 //Step By Step
};
sinput const string SLTP="";//-=[ SL & TP SETTINGS ]=-
input int TakeProfit=550;//Take Profit
input int StopLoss=350;//Stop Loss
input ENUM_SLTP_MODE SLnTPMode=Server;//SL & TP Mode
sinput const string Lock="";//-=[ LOCK PROFIT SETTINGS ]=-
input ENUM_LOCKPROFIT_ENABLE LockProfitEnable=LP_ENABLE;//Enable/Disable Profit Lock
input int LockProfitAfter=100;//Target point to Lock Profit
input int ProfitLock=60;//Profit To Lock
sinput const string Trailing="";//-=[ TRAILING STOP SETTINGS ]=-
input ENUM_TRAILINGSTOP_METHOD TrailingStopMethod=TS_CLASSIC;//Trailing Method
input int TrailingStop=50;//Trailing Stop
input int TrailingStep=10;//Trailing Stop Step
input int Slippage = 10; //Slippage
input ENUM_CHARTSYMBOL ChartSymbolSelection=AllOpenOrder;//
input bool inpEnableAlert=false;//Enable Alert
input bool inpEnableTest=false;//Enable Test on Strategy Tester
class AutoSLTP
{
private:
bool CheckMoneyForTrade(string sym, double lots,ENUM_ORDER_TYPE type);
bool CheckVolumeValue(string sym, double volume);
bool RZ_TrailingStop(ulong ticket, int JumlahPoin,int Step=1,ENUM_TRAILINGSTOP_METHOD Method=TS_STEP_DISTANCE);
bool LockProfit(ulong ticket, int Targetpoint,int Lockedpoint);
public:
ENUM_SLTP_MODE autoMode;
ENUM_LOCKPROFIT_ENABLE LPMode;
ENUM_CHARTSYMBOL chartMode;
ENUM_TRAILINGSTOP_METHOD trailingMode;
int slip;
int TPa;
int SLa;
int LPA;
int PL;
int TS;
int TST;
bool SetInstantSLTP();
int CalculateInstantOrders();
void OrderTest();
};
AutoSLTP auto;
bool AutoSLTP::SetInstantSLTP()
{
double SL=0, TP=0;
double ask = 0, bid = 0, point = 0;
int digits = 0, minstoplevel = 0;
for(int i=PositionsTotal()-1; i>=0; i--)
{
if(PositionGetTicket(i))
if(chartMode==CurrentChartSymbol && PositionGetString(POSITION_SYMBOL)!=Symbol())
continue;
{
ask = SymbolInfoDouble(PositionGetString(POSITION_SYMBOL),SYMBOL_ASK);
bid = SymbolInfoDouble(PositionGetString(POSITION_SYMBOL),SYMBOL_BID);
point = SymbolInfoDouble(PositionGetString(POSITION_SYMBOL),SYMBOL_POINT);
digits =(int)SymbolInfoInteger(PositionGetString(POSITION_SYMBOL),SYMBOL_DIGITS);
minstoplevel =(int)SymbolInfoInteger(PositionGetString(POSITION_SYMBOL),SYMBOL_TRADE_STOPS_LEVEL);
double ClosePrice=0;
int Poin=0;
color CloseColor=clrNONE;
if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)
{
CloseColor=clrBlue;
ClosePrice=bid;
Poin=(int)((ClosePrice-PositionGetDouble(POSITION_PRICE_OPEN))/point);
}
else
if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL)
{
CloseColor=clrRed;
ClosePrice=ask;
Poin=(int)((PositionGetDouble(POSITION_PRICE_OPEN)-ClosePrice)/point);
}
if(autoMode == Server)
{
if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)
{
SL=(SLa>0)?NormalizeDouble(PositionGetDouble(POSITION_PRICE_OPEN)-((SLa+minstoplevel)*point),digits):0;
TP=(TPa>0)?NormalizeDouble(PositionGetDouble(POSITION_PRICE_OPEN)+((TPa+minstoplevel)*point),digits):0;
if(SLa > 0 && TPa > 0 && PositionGetDouble(POSITION_SL)==0.0 && PositionGetDouble(POSITION_TP)==0.0)
{
trade.PositionModify(PositionGetInteger(POSITION_TICKET),SL,TP);
}
else
if(TPa > 0 && PositionGetDouble(POSITION_TP)==0.0)
{
trade.PositionModify(PositionGetInteger(POSITION_TICKET),PositionGetDouble(POSITION_SL),TP);
}
else
if(SLa > 0 && PositionGetDouble(POSITION_SL)==0.0)
{
trade.PositionModify(PositionGetInteger(POSITION_TICKET),SL,PositionGetDouble(POSITION_TP));
}
}
else
if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL)
{
SL=(SLa>0)?NormalizeDouble(PositionGetDouble(POSITION_PRICE_OPEN)+((SLa+minstoplevel)*point),digits):0;
TP=(TPa>0)?NormalizeDouble(PositionGetDouble(POSITION_PRICE_OPEN)-((TPa+minstoplevel)*point),digits):0;
if(SLa > 0 && TPa > 0 && PositionGetDouble(POSITION_SL)==0.0 && PositionGetDouble(POSITION_TP)==0.0)
{
trade.PositionModify(PositionGetInteger(POSITION_TICKET),SL,TP);
}
else
if(TPa > 0 && PositionGetDouble(POSITION_TP)==0.0)
{
trade.PositionModify(PositionGetInteger(POSITION_TICKET),PositionGetDouble(POSITION_SL),TP);
}
else
if(SLa > 0 && PositionGetDouble(POSITION_SL)==0.0)
{
trade.PositionModify(PositionGetInteger(POSITION_TICKET),SL,PositionGetDouble(POSITION_TP));
}
}
}
else
if(autoMode == Client)
{
if((TPa>0 && Poin>=TPa) || (SLa>0 && Poin<=(-SLa)))
{
if(trade.PositionClose(PositionGetInteger(POSITION_TICKET),slip))
{
if(inpEnableAlert)
{
if(PositionGetDouble(POSITION_PROFIT)>0)
Alert("Closed by Virtual TP #",PositionGetInteger(POSITION_TICKET)," Profit=",PositionGetDouble(POSITION_PROFIT)," Points=",Poin);
if(PositionGetDouble(POSITION_PROFIT)<0)
Alert("Closed by Virtual SL #",PositionGetInteger(POSITION_TICKET)," Loss=",PositionGetDouble(POSITION_PROFIT)," Points=",Poin);
}
}
}
}
if(LPA>0 && PL>0 && Poin>=LPA)
{
if(Poin<=LPA+TS)
{
LockProfit(PositionGetInteger(POSITION_TICKET),LPA,PL);
}
else
if(Poin>=LPA+TS)
{
RZ_TrailingStop(PositionGetInteger(POSITION_TICKET),TS,TST,trailingMode);
}
}
else
if(LPA==0)
{
RZ_TrailingStop(PositionGetInteger(POSITION_TICKET),TS,TST,trailingMode);
}
}
}
return (false);
}
void AutoSLTP::OrderTeПоказано первые 50% кода (символов: 10839)
Введите ваш email и нажмите кнопку, чтобы перейти к оплате.