ÿþ
#property copyright "Copyright © 2018, Khlystov Vladimir"
#property link "cmillion@narod.ru"
#property strict
#property description "!>25B=8: 2KAB02;O5B 2A5< >B:@KBK< ?>78F8O< ?> 2A5< 8=AB@C<5=B0< SL 8 TP"
extern int Stoploss = 100,
Takeprofit = 50;
int OnInit()
{
DrawLABEL("Stoploss",StringConcatenate("Stoploss ",Stoploss),5,15,Gray);
DrawLABEL("Takeprofit",StringConcatenate("Takeprofit ",Takeprofit),5,35,Gray);
EventSetTimer(1);
return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason)
{
ObjectDelete("Stoploss");
ObjectDelete("Takeprofit");
}
void OnTick() {OnTimer();}
void OnTimer()
{
if(!IsTradeAllowed()) return;
double OOP,OSL,OTP,SL=0,TP=0,POINT;
int tip,STOPLEVEL,DIGITS;
for(int i=0; i<OrdersTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
tip=OrderType();
STOPLEVEL=(int)MarketInfo(OrderSymbol(),MODE_STOPLEVEL);
DIGITS=(int)MarketInfo(OrderSymbol(),MODE_DIGITS);
POINT=MarketInfo(OrderSymbol(),MODE_POINT);
OSL = NormalizeDouble(OrderStopLoss(),DIGITS);
OTP = NormalizeDouble(OrderTakeProfit(),DIGITS);
OOP = NormalizeDouble(OrderOpenPrice(),DIGITS);
SL=OSL;TP=OTP;
if(tip==OP_BUY)
{
if(OSL==0 && Stoploss>=STOPLEVEL && Stoploss!=0)
{
SL=NormalizeDouble(OOP-Stoploss *POINT,DIGITS);
}
if(OTP==0 && Takeprofit>=STOPLEVEL && Takeprofit!=0)
{
TP=NormalizeDouble(OOP+Takeprofit*POINT,DIGITS);
}
if(SL!=OSL || TP!=OTP)
{
if(!OrderModify(OrderTicket(),OOP,SL,TP,0,White)) Comment(OrderSymbol()," Error OrderModify ",GetLastError()," SL=",DoubleToStr(SL,DIGITS)," TP=",DoubleToStr(TP,DIGITS));
else Comment(OrderSymbol()," TimeSet ",TimeCurrent(),"\nSL=",DoubleToStr(SL,DIGITS)," TP=",DoubleToStr(TP,DIGITS));
}
}
if(tip==OP_SELL)
{
if(OSL==0 && Stoploss>=STOPLEVEL && Stoploss!=0)
{
SL=NormalizeDouble(OOP+Stoploss *POINT,DIGITS);
}
if(OTP==0 && Takeprofit>=STOPLEVEL && Takeprofit!=0)
{
TP=NormalizeDouble(OOP-Takeprofit*POINT,DIGITS);
}
if(SL!=OSL || TP!=OTP)
{
if(!OrderModify(OrderTicket(),OOP,SL,TP,0,White)) Comment(OrderSymbol()," Error OrderModify ",GetLastError()," SL=",DoubleToStr(SL,DIGITS)," TP=",DoubleToStr(TP,DIGITS));
else Comment(OrderSymbol()," TimeSet ",TimeCurrent(),"\nSL=",DoubleToStr(SL,DIGITS)," TP=",DoubleToStr(TP,DIGITS));
}
}
}
}
}
void DrawLABEL(string name,string Name,int X,int Y,color clr)
{
if(ObjectFind(name)==-1)
{
ObjectCreate(name,OBJ_LABEL,0,0,0);
ObjectSet(name,OBJPROP_CORNER,1);
ObjectSet(name,OBJPROP_XDISTANCE,X);
ObjectSet(name,OBJPROP_YDISTANCE,Y);
}
ObjectSetText(name,Name,12,"Arial",clr);
}
Comments