яю//+------------------------------------------------------------------+ //| Price Movements.mq4 | //| Copyright 2014, Moneystrategy.ru | //| http://www.moneystrategy.ru | //+------------------------------------------------------------------+ #property copyright "Copyright (c) 2014. Moneystrategy.ru" #property link "http://www.moneystrategy.ru" #property version "1.0" #property description "!>25B=8: @01>B05B =5?>A@54AB25==> A F5=>9 8 =5 8A?>;L7C5B B5E=8G5A:85 8=48:0B>@K.\n" "A5 2KG8A;5=8O >ACI5AB2;ONBAO A ?@8<5=5=85< B5:CI59 F5=K 8 2@5<5=8. >340\n" "A:>@>ABL F5=K @57:> 2>7@0AB05B, A>25B=8: >B:@K205B >@45@ 2 AB>@>=C 5Q 42865=8O.\n" "5 8A?>;L7C5B 2 B>@3>2;5 2KA>:>@8A:>20==KE AB@0B5389 =0 ?>4>188 0@B8=359;0.\n" "!:>@>ABL 42865=8O F5=K 87<5@O5BAO ?@>18B85< 28@BC0;L=KE C@>2=59, :>B>@K5\n" "CAB0=02;820NBAO >B B5:CI59 F5=K 8 <>48D8F8@CNBAO ?> 8AB5G5=88 7040==>3> 2@5<5=8.\n" " 01>B05B =0 4 8 5 7=0:5.\n" #property strict #include <stderror.mqh> #include <stdlib.mqh> #define miz 0.00000001 extern double Lots = 0.01; extern double MaxRisk = 5; extern double TakeProfit = 250; extern double StopLoss = 10; extern int TrailingStop = 5; extern int TrailingStep = 10; extern int PriceStep = 10; extern int TimeStep = 15; extern int Slipage = 2; extern int MaxTrades = 5; extern int Magic = 12345; extern int LicenseKey = 0; extern color TextColor = clrWhite; color UpCol = 0; color DnCol = 0; string Com = ""; string Symboll = Symbol(); int Number = 12345; int AccNumber; bool Demo = (!IsDemo()) && (!IsTesting()); datetime time; bool opnovis, sigN=true, testing=false, SignalBuy=true, SignalSell=true; int OnInit() { if (Digits == 3 || Digits == 5) { Slipage = Slipage *= 10; PriceStep = PriceStep *= 10; TakeProfit = TakeProfit *= 10; StopLoss = StopLoss *= 10; TrailingStop = TrailingStop *= 10; TrailingStep = TrailingStep *= 10; } AccNumber = AccountNumber(); time = TimeCurrent(); if(IsOptimization() || (IsTesting() && !IsVisualMode())) { opnovis=false; } else opnovis=true; if (IsTesting()) { if(IsVisualMode() != true) { Print("H81:0! :;NG8B5 287C0;L=K9 @568<"); } } if(!IsOptimization() && !IsTesting()) EventSetTimer(1); else testing=true; DelBP(Com); return(INIT_SUCCEEDED); } void OnDeinit(const int reason) { if(IsTesting() || IsOptimization())return; EventKillTimer(); int ur = UninitializeReason(); if(ur == 1 || ur == 6) DelBP(Com); ObjectsDeleteAll(); return; } void OnTick() { if(!IsTradeAllowed()) { SetLabel("Label1", " =8<0=85! 01>B0 A>25B=8:0 =0 AG5B5 ! " + DoubleToString( AccountNumber(), 0) + " =5 @07@5H5=0.", TextColor, 5, 30); SetLabel("Label2", " # 0A =5 2:;NG5=0 2B>-B>@3>2;O. ;O @5H5=8O 40==>9 ?@>1;5<K,", TextColor, 5, 50); SetLabel("Label3", " 0< =C6=> @07@5H8BL 2B>-B>@3>2;N A>25B=8:0<8. ;O MB>3>", TextColor, 5, 70); SetLabel("Label4", " =06<8B5 =0 :=>?:C 2B>-B>@3>2;O =0 ?0=5;8 8=AB@C<5=B>2,", TextColor, 5, 90); SetLabel("Label5", " :=>?:0 4>;6=0 AB0BL 75;5=>9.", TextColor, 5, 110); SetLabel("Label6", " ", TextColor, 5, 130); SetLabel("Label7", " ", TextColor, 5, 150); return; } if (Demo && LicenseKey != 5 * AccNumber + Number) { SetLabel("Label1", " =8<0=85! 01>B0 A>25B=8:0 =0 AG5B5 ! " + DoubleToString( AccountNumber(), 0) + " 70?@5I5=0.", TextColor, 5, 30); SetLabel("Label2", " >7<>6=> K =5 225;8 ;8F5=78>==K9 :;NG 8;8 >H81;8AL ?@8 53>", TextColor, 5, 50); SetLabel("Label3", " =0?8A0=88. >60;C9AB0, ?@>25@LB5 ?@028;L=>ABL 22>40 =><5@0", TextColor, 5, 70); SetLabel("Label4", " 8 ?>2B>@8B5 ?>?KB:C. A;8 C 0A =5B ;8F5=78>==>3> =><5@0", TextColor, 5, 90); SetLabel("Label5", " :;NG0, B> K <>65B5 53> ?@8>1@5AB8. !B>8<>ABL ;8F5=788 4;O", TextColor, 5, 110); SetLabel("Label6", " >4=>3> =><5@0 B>@3>2>3> AG5B0 A>AB02;O5B 25 USD.", TextColor, 5, 130); SetLabel("Label7", " >=B0:BK: mail@moneystrategy.ru.", TextColor, 5, 150); return; } double ProfCount = Profit(0); SetLabel("Label1", " 0@0=B8@>20==0O ?@81K;L ?> >B:@KB>9 A45;:5: " + (DoubleToString(ProfitIFStopInCurrency(Symbol(), OrderType(), OrderMagicNumber()), 2)) + " " + AccountCurrency(), TextColor, 5, 30); SetLabel("Label2", " @81K;L/#1KB>: ?@54K4CI59 A45;:8: " + (DoubleToString(profhistory(Symbol(), OrderType(), OrderMagicNumber()), 2)) + " " + AccountCurrency(), TextColor, 5, 50); SetLabel("Label3", " @81K;L/#1KB>: 70 A53>4=O: " + DoubleToStr(Profit(0), 2) + " " + AccountCurrency(), TextColor, 5, 70); SetLabel("Label4", " @81K;L/#1KB>: 2G5@0: " + DoubleToStr(Profit(1), 2) + " " + AccountCurrency(), TextColor, 5, 90); SetLabel("Label5", " @81K;L/#1KB>: 2 B5:CI5< <5AOF5: " + DoubleToStr(ProfitMons(0), 2) + " " + AccountCurrency(), TextColor, 5, 110); SetLabel("Label6", " @81K;L/#1KB>: 2 ?@54K4CI5< <5AOF5: " + DoubleToStr(ProfitMons(1), 2) + " " + AccountCurrency(), TextColor, 5, 130); SetLabel("Label7", " 0H B5:CI89 10;0=A: " + DoubleToStr(AccountBalance(), 2) + " " + AccountCurrency(), TextColor, 5, 150); if(TrailingStop>0)MoveTrailingStop(); CloseAllOrders(); time=TimeCurrent(); if(testing) { if(TimeStep==0)sigN=true; else { static datetime tim; if(tim==0)tim=time; if(time>=tim+TimeStep){sigN=true;tim+=TimeStep;} } } if(sigN) { datetime tim1=iTime(_Symbol,0,0),tim2=tim1+_Period*240; double pr=Ask+PriceStep*_Point; Tline(Com+"Up",tim1,pr,tim2,pr,UpCol,true); pr=Bid-PriceStep*_Point; Tline(Com+"Dn",tim1,pr,tim2,pr,DnCol,true); sigN=false; SignalBuy=true; SignalSell=true; } if(SignalBuy) { double up=GetDou(Com+"Up",OBJPROP_PRICE1); if(up>0.0 && !(up-Ask>miz)) { if(DayOfWeek() == 5 && Hour() >= 22) { return; } if (CountBuy() + CountSell() <= MaxTrades - 1) int ticket = OrderSend (Symbol(), OP_BUY, LotByRisk(), Ask, Slipage, Ask-StopLoss*Point, Ask+TakeProfit*Point, "", Magic, 0, clrNONE);SignalBuy=false; } } if(SignalSell) { double dn=GetDou(Com+"Dn",OBJPROP_PRICE1); if(dn>0.0 && !(Bid-dn>miz)) { if(DayOfWeek() == 5 && Hour() >= 22) { return; } if (CountBuy() + CountSell() <= MaxTrades - 1) int ticket = OrderSend (Symbol(), OP_SELL, LotByRisk(), Bid, Slipage, Bid+StopLoss*Point, Bid-TakeProfit*Point, "", Magic, 0, clrNONE);SignalSell=false; } } } int CountBuy() { int count = 0; for (int i = OrdersTotal() - 1; i >= 0; i --) { if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_BUY) count ++; } } return (count); } int CountSell() { int count = 0; for (int i = OrdersTotal() - 1; i >= 0; i --) { if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_SELL) count ++; } } return (count); } double LotByRisk(int op_type, double risk, int sl) { double lot_min = MarketInfo(Symbol(), MODE_MINLOT); double lot_max = MarketInfo(Symbol(), MODE_MAXLOT); double lot_steep = MarketInfo(Symbol(), MODE_LOTSTEP); double lot_cost = MarketInfo(Symbol(), MODE_TICKVALUE); double lot = 0; double pip_cost = 0; lot = AccountBalance() * risk/100; pip_cost = lot/sl; lot = NormalizeDouble(pip_cost/lot_cost, 2); lot = NormalizeDouble(lot/lot_steep, 0) * lot_steep; if (lot < lot_min) lot = lot_min; if (lot > lot_max) lot = lot_max; return(lot); } void Tline(string name,datetime tim1,double pr1,datetime tim2,double pr2,color col,bool fl=false) { if(!opnovis)return; if(ObjectFind(name)<0){if(!ObjectCreate(name,OBJ_TREND,0,tim1,pr1,tim2,pr2))return;} ObjectSetInteger(0,name,OBJPROP_COLOR,col); ObjectSetInteger(0,name,OBJPROP_TIMEFRAMES,-1); ObjectSetInteger(0,name,OBJPROP_TIME1,tim1); ObjectSetInteger(0,name,OBJPROP_TIME2,tim2); ObjectSetDouble(0,name,OBJPROP_PRICE1,pr1); ObjectSetDouble(0,name,OBJPROP_PRICE2,pr2); if(fl)ChartRedraw(); } double GetDou(string name,int id) { double res=0.0; if(opnovis && ObjectFind(name)>-1)res=ObjectGetDouble(0,name,id); return(res); } void DelBP(string name) { if(!opnovis)return; int obj=ObjectsTotal(); for(int i=obj-1;i>=0;i--) {if(StringFind(ObjectName(i),name,0)==0)ObjectDelete(ObjectName(i));} } void OnTimer() { static int sec; sec++; if(sec>=TimeStep){sigN=true;sec=0;OnTick();} } void SetLabel(string nm, string tx, color cl, int xd, int yd, int cr=0, int fs=12) { if (ObjectFind(nm)<0) ObjectCreate(nm, OBJ_LABEL, 0, 0,0); ObjectSetText(nm, tx, fs); ObjectSet(nm, OBJPROP_COLOR , cl); ObjectSet(nm, OBJPROP_XDISTANCE, xd); ObjectSet(nm, OBJPROP_YDISTANCE, yd); ObjectSet(nm, OBJPROP_CORNER , cr); ObjectSet(nm, OBJPROP_FONTSIZE , fs); ObjectSet(nm, OBJPROP_BACK , false); ObjectSet(nm, OBJPROP_SELECTABLE , false); ObjectSet(nm, OBJPROP_READONLY , false); } double LotByRisk() {double Free =AccountFreeMargin(); double LotVal =MarketInfo(Symbol(),MODE_TICKVALUE); double Min_Lot =MarketInfo(Symbol(),MODE_MINLOT); double Max_Lot =MarketInfo(Symbol(),MODE_MAXLOT); double Step1 =MarketInfo(Symbol(),MODE_LOTSTEP); double Lot =MathFloor((Free*MaxRisk/100)/(StopLoss*LotVal)/Step1)*Step1; if(Lot<Min_Lot) Lot=Min_Lot; if(Lot>Max_Lot) Lot=Max_Lot; return(Lot);} void MoveTrailingStop() { int cnt,total=OrdersTotal(); for(cnt=0;cnt<total;cnt++) { if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)) { if(OrderType()<=OP_SELL&&OrderSymbol()==Symbol()) { if(OrderType()==OP_BUY) { if(TrailingStop>0) { if((NormalizeDouble(OrderStopLoss(),Digits)<NormalizeDouble(Bid-Point*(TrailingStop+TrailingStep),Digits))||(OrderStopLoss()==0)) { bool res = OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-Point*TrailingStop,Digits),OrderTakeProfit(),0,Green); } } } else { if(TrailingStop>0) { if((NormalizeDouble(OrderStopLoss(),Digits)>(NormalizeDouble(Ask+Point*(TrailingStop+TrailingStep),Digits)))||(OrderStopLoss()==0)) { bool res = OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+Point*TrailingStop,Digits),OrderTakeProfit(),0,Red); } } } } } } } double profhistory(string t,int x, int m) { string sym=""; int z=0 ; double prof=0; if ( t=="") sym=Symbol(); else sym = t ; for( int i=OrdersHistoryTotal()-1; i>=0; i-- ) if ( OrderSelect(i,SELECT_BY_POS,MODE_HISTORY) == true ) if ( OrderSymbol() == sym && (OrderMagicNumber() == m || m==-1 ) && OrderType()<=1) if ( x == -1 || OrderType() == x ) if ( OrderCloseTime()>z) {z =OrderCloseTime(); prof=OrderProfit();} return(prof);} double Profit(int Bar) { double OProfit = 0; for (int i = 0; i < OrdersHistoryTotal(); i ++) { if (!(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))) break; if ((OrderSymbol() == Symbol() && OrderMagicNumber() == Magic ) || ( Magic < 0 && Symboll == "-1" ) || (Symboll == OrderSymbol()) || (Symboll == "0" && OrderSymbol() == Symbol())) if (OrderCloseTime() >= iTime(Symbol(), PERIOD_D1, Bar) && OrderCloseTime() < iTime(Symbol(), PERIOD_D1, Bar) + 86400) OProfit += OrderProfit(); } return (OProfit); } double ProfitMons(int Bar) { double OProfit = 0; for (int i = 0; i < OrdersHistoryTotal(); i ++) { if (!(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))) break; if ((OrderSymbol() == Symbol() && OrderMagicNumber() == Magic ) || ( Magic < 0 && Symboll == "-1" ) || (Symboll == OrderSymbol()) || (Symboll == "0" && OrderSymbol() == Symbol())) if (OrderCloseTime() >= iTime(Symbol(), PERIOD_MN1, Bar) && OrderCloseTime() < iTime(Symbol(), PERIOD_MN1, Bar) + 2592000) OProfit += OrderProfit(); } return (OProfit); } double ProfitIFStopInCurrency(string sy="", int op=-1, int mn=-1) { if (sy=="0") sy=Symbol(); int i, k = OrdersTotal(); int m = 0; double l; double p; double t; double v; double s = 0; for (i=0; i<k; i++) { if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { if ((OrderSymbol()==sy || sy=="") && (mn<0 || OrderMagicNumber()==mn)) { if ((OrderType()==OP_BUY || OrderType()==OP_SELL) && (op<0 || OrderType()==op)) { l=MarketInfo(OrderSymbol(), MODE_LOTSIZE); p=MarketInfo(OrderSymbol(), MODE_POINT); t=MarketInfo(OrderSymbol(), MODE_TICKSIZE); v=MarketInfo(OrderSymbol(), MODE_TICKVALUE); if (OrderType()==OP_BUY) { if (m==0) s-=(OrderOpenPrice()-OrderStopLoss())/p*v*OrderLots(); if (m==1) s-=(OrderOpenPrice()-OrderStopLoss())/p*v/t/l*OrderLots(); if (m==2) s-=(OrderOpenPrice()-OrderStopLoss())/p*v*OrderLots(); s+=OrderCommission()+OrderSwap(); } if (OrderType()==OP_SELL) { if (OrderStopLoss()>0) { if (m==0) s-=(OrderStopLoss()-OrderOpenPrice())/p*v*OrderLots(); if (m==1) s-=(OrderStopLoss()-OrderOpenPrice())/p*v/t/l*OrderLots(); if (m==2) s-=(OrderStopLoss()-OrderOpenPrice())/p*v*OrderLots(); s+=OrderCommission()+OrderSwap(); } else s=-AccountBalance(); } } } } } if (AccountBalance()+s<0) s=-AccountBalance(); return(s); } double lotshistory(string t,int x, int m) { string sym=""; int z=0 ; double lot=0; if ( t=="") sym=Symbol(); else sym = t ; int d=OrdersHistoryTotal(),i;for( i=0;i<=d;i++) if ( OrderSelect(i,SELECT_BY_POS,MODE_HISTORY) == true ) if ( OrderSymbol() == sym && (OrderMagicNumber() == m || m==-1 ) && OrderType()<=1) if ( x == -1 || OrderType() == x ) if ( OrderCloseTime()>z) {z =OrderCloseTime(); lot=OrderLots();} return(lot);} void CloseAllOrders() { if(DayOfWeek() == 5 && Hour() >= 22) { for(int cnt = OrdersTotal()-1;cnt >= 0; cnt--) { if( !OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES) ) continue; if( OrderSymbol()==Symbol() && OrderMagicNumber() == Magic) { if(OrderType()==OP_SELL) { bool CloseAllOrders = OrderClose(OrderTicket(), OrderLots(), Ask, Slipage, clrNONE); } else if(OrderType()==OP_BUY) { bool CloseAllOrders = OrderClose(OrderTicket(), OrderLots(), Bid, Slipage, clrNONE); } } } } }