//+------------------------------------------------------------------+ //| Copyright © 2015, Vladimir Hlystov | //+------------------------------------------------------------------+ #property copyright "Copyright © 2015, http://cmillion.ru" #property link "cmillion@narod.ru" #property version "1.00" #property strict //------------------------------------------------------------------- extern double Lot = 0.01; extern double K_Martin = 1.0; // Умножение последующих лотов extern double Sum_Lot = 0.01; // Добавка последующих лотов extern double MaxLot = 1.00; // Максимальный лот extern int TrailingStart= 150; extern int TrailingStop = 50; extern int Magic = 0; extern bool DrawInfo = true; // Вывод информации на экран extern color text_color = Aqua; // Цвет вывода информации extern int DigitsLot = 2; // Округление лотов ордеров 1- десятые (0.1) 2 сотые (0.01) extern int slippage = 3; //------------------------------------------------------------------- string AC; //------------------------------------------------------------------- void OnTick() { if(!IsTradeAllowed()) { DrawLABEL("Торговля",1,0,0,Red,"Торговля запрещена"); return; } else DrawLABEL("Торговля",1,0,0,Lime,"Торговля разрешена"); //--- double STOPLEVEL=MarketInfo(Symbol(),MODE_STOPLEVEL); if(TrailingStop0) { NLb=NormalizeDouble(price_b/LB+TrailingStart*Point/b,Digits); if(DrawInfo) { ObjectCreate("infoБезубыток Buy",OBJ_ARROW,0,Time[0],NLb,0,0,0,0); ObjectSet("infoБезубыток Buy",OBJPROP_ARROWCODE,6); ObjectSet("infoБезубыток Buy",OBJPROP_COLOR,Blue); } } if(s>0) { NLs=NormalizeDouble(price_s/LS-TrailingStart*Point/s,Digits); if(DrawInfo) { ObjectCreate("infoБезубыток Sell",OBJ_ARROW,0,Time[0],NLs,0,0,0,0); ObjectSet("infoБезубыток Sell",OBJPROP_ARROWCODE,6); ObjectSet("infoБезубыток Sell",OBJPROP_COLOR,Red); } } //--- if(b+s>0) { for(i=0; iOSL && SL>NLb) { if(!OrderModify(OrderTicket(),OOP,SL,0,0,White)) Print("Error Order Modify ",GetLastError()); } } if(tip==OP_SELL) { SL=NormalizeDouble(Ask+TrailingStop*Point,Digits); if((SL0,Lime,Red),StringConcatenate("Profit ",DoubleToStr(Profit,2),AC)); DrawLABEL("Всего лот Buy",1,5,100,Color(ProfitB>0,Lime,Red),StringConcatenate("Buy ",b," | ",DoubleToStr(LB,DigitsLot)," | ",DoubleToStr(ProfitB,2),AC)); DrawLABEL("Всего лот Sell",1,5,120,Color(ProfitS>0,Lime,Red),StringConcatenate("Sell ",s," | ",DoubleToStr(LS,DigitsLot)," | ",DoubleToStr(ProfitS,2),AC)); //--- double lot=NormalizeDouble(Lot*MathPow(K_Martin,MathMax(b,s))+Sum_Lot*MathMax(b,s),2); if(lot>MaxLot) return; if(AccountFreeMarginCheck(Symbol(),OP_SELL,lot)+AccountFreeMarginCheck(Symbol(),OP_BUY,lot)>0) if(b==0 || s==0) { if(OrderSend(Symbol(),OP_BUY,lot,NormalizeDouble(Ask,Digits),slippage,0,0,NULL,Magic,0,CLR_NONE)==-1) Print("Ошибка ",GetLastError()," открытия ордера "); //--- if(OrderSend(Symbol(),OP_SELL,lot,NormalizeDouble(Bid,Digits),slippage,0,0,NULL,Magic,0,CLR_NONE)==-1) Print("Ошибка ",GetLastError()," открытия ордера "); } return; } //------------------------------------------------------------------ void OnDeinit(const int reason) { if(DrawInfo && !IsTesting()) { ObjectsDeleteAll(0); } } //------------------------------------------------------------------- void DrawLABEL(string name,int CORNER,int X,int Y,color clr,string Name) { if(!DrawInfo) return; if(ObjectFind(name)!=-1) ObjectDelete(name); ObjectCreate(name,OBJ_LABEL,0,0,0); ObjectSet(name,OBJPROP_CORNER,CORNER); ObjectSet(name,OBJPROP_XDISTANCE,X); ObjectSet(name,OBJPROP_YDISTANCE,Y); ObjectSetText(name,Name,12,"Arial",clr); } //+------------------------------------------------------------------+ int OnInit() { AC=StringConcatenate(" ",AccountCurrency()); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ color Color(bool P,color a,color b) { if(P) return(a); else return(b); } //------------------------------------------------------------------