//+------------------------------------------------------------------+ //| Razor.mq4 | //| Стеценко | //| | //+------------------------------------------------------------------+ #property copyright "Стеценко" #property link "" //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int lastTime; int x, limitX; int controlTime; int direction = 0; double TakeProfit, StopLoss, y, Lots; int MagicNumber = 150; extern double Lot = 0.1; int FractalUp[3]; int FractalDown[3]; int w1, w2, w3; int Ord; bool ReadySet = false; extern double point = 0.0001; int distance = 15; extern bool Rul_EMA = false; extern bool Rul_Close = true; extern bool Rul_Count = false; extern bool Rul_DelOnNewChannel = true; int SystemState=0; extern double ProfitFactor = 0.6;//0.8 void DrawFiboChannel(int pos1, int pos2, int pos3, int dir) { if(Rul_DelOnNewChannel==true)DelOrder(); int x1, x2, x3, x; x1 = iTime(NULL, 0, pos1); x2 = iTime(NULL, 0, pos2); x3 = iTime(NULL, 0, pos3); double k = 0.85; x = x2 + k*x3 - k*x1; k = 1.15; limitX = x2 + k*x3 - k*x1; direction = dir; if(controlTime!=x2)ReadySet = true; controlTime = x2; ObjectDelete("Fibo_Channel"); ObjectDelete("Fibo_HLine"); ObjectDelete("Fibo_VLine"); w1 = pos1; w2 = pos2; w3 = pos3; if(dir==1) { //Alert("Channel Up"); ObjectCreate("Fibo_Channel", OBJ_FIBOCHANNEL, 0, iTime(NULL, 0, pos1), iLow(NULL, 0, pos1), iTime(NULL, 0, pos2), iHigh(NULL, 0, pos2), iTime(NULL, 0, pos3), iLow(NULL, 0, pos3)); ObjectCreate("Fibo_HLine", OBJ_HLINE, 0, 0, iHigh(NULL, 0, pos2)); ObjectCreate("Fibo_VLine", OBJ_VLINE, 0, x, 0); y = iHigh(NULL, 0, pos2); TakeProfit = NormalizeDouble((iHigh(NULL, 0, pos1) - iLow(NULL, 0, pos2))*ProfitFactor, Digits); StopLoss = iLow(NULL, 0, pos3); } if(dir==-1) { //Alert("Channel Down"); ObjectCreate("Fibo_Channel", OBJ_FIBOCHANNEL, 0, iTime(NULL, 0, pos1), iHigh(NULL, 0, pos1), iTime(NULL, 0, pos2), iLow(NULL, 0, pos2), iTime(NULL, 0, pos3), iHigh(NULL, 0, pos3)); ObjectCreate("Fibo_HLine", OBJ_HLINE, 0, 0, iLow(NULL, 0, pos2)); ObjectCreate("Fibo_VLine", OBJ_VLINE, 0, x, 0); y = iLow(NULL, 0, pos2); TakeProfit = NormalizeDouble((iHigh(NULL, 0, pos2) - iLow(NULL, 0, pos1))*ProfitFactor, Digits); StopLoss = iHigh(NULL, 0, pos3); } ObjectSet("Fibo_Channel", OBJPROP_FIBOLEVELS, 4); ObjectSet("Fibo_Channel", OBJPROP_FIRSTLEVEL+0, 0.15); ObjectSet("Fibo_Channel", OBJPROP_FIRSTLEVEL+1, -0.15); ObjectSet("Fibo_Channel", OBJPROP_FIRSTLEVEL+2, -0.85); ObjectSet("Fibo_Channel", OBJPROP_FIRSTLEVEL+3, -1.15); ObjectSet("Fibo_Channel", OBJPROP_LEVELCOLOR, FireBrick); } void SetFiboChannel() { GetFractals(); if(FractalUp[0]==FractalDown[0])return; if(FractalUp[1]==FractalDown[1])return; if(FractalUp[0]>FractalDown[0]) //Trend Up { if(FractalUp[0]>FractalDown[1])return; if(FractalDown[1]>FractalUp[1])return; DrawFiboChannel(FractalDown[1], FractalUp[0], FractalDown[0], 1); } if(FractalUp[0]FractalUp[1])return; if(FractalUp[1]>FractalDown[1])return; DrawFiboChannel(FractalUp[1], FractalDown[0], FractalUp[0], -1); } } void GetFractals() { int posUp=0; int posDown=0; bool cont=true; int pos=3; while(cont==true) { double valUp = iFractals(NULL, 0, MODE_UPPER, pos); double valDown = iFractals(NULL, 0, MODE_LOWER, pos); if((valUp>0)&&(posUp<3)) { FractalUp[posUp]=pos; posUp++; } if((valDown>0)&&(posDown<3)) { FractalDown[posDown]=pos; posDown++; } pos++; if((posDown>2)&&(posUp>2))cont=false; } } int init() { //---- Lots = Lot; DelOrder(); //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } bool CheckEMA(int dir) { int i; if(Rul_EMA==true) for(i=w2; il2) { //Alert("not allow"); return(false); } } } if(Rul_Close==true) for(i=w3; iClose[w2]) { //Alert("not allow"); return(false); } } if(dir==-1) { if(Close[i]=0;i--) { select = OrderSelect(i, SELECT_BY_POS, MODE_TRADES); if((select == true) && (OrderMagicNumber() == MagicNumber)&& (OrderSymbol()==Symbol()) && ((OrderType() == OP_SELLSTOP)||(OrderType() == OP_BUYSTOP))) { OrderDelete(Ord); } } } int start() { //---- if(Time[0]>lastTime) { lastTime=Time[0]; SetFiboChannel(); int t0 = iTime(NULL, 0, 0); int t1 = iTime(NULL, 0, 1); if((x