//+------------------------------------------------------------------+ //| ProjectName | //| Copyright 2018, CompanyName | //| http://www.companyname.net | //+------------------------------------------------------------------+ #property copyright "PaulDV 2019" #define VERSION "1.0" #property version VERSION #property indicator_chart_window #property indicator_buffers 2 #property indicator_color1 clrWhite #property indicator_color2 clrWhite #property strict #define buy 888 #define sell -888 input double TriggerCandleRatio=3.0; // Ratio of current candle to previous input double TriggerHLRatio=1.9; // Ratio between closing wicks input double TriggerCloseRatio=0.07; // Min ratio of close/open to bar. input double ArrowGap = 1.0; // Additional room for SL (pips) input bool alertsOn = false; // Turn alerts on/off? input bool alertsOnCurrent = true; // Alerts on still opened bar on/off? input bool alertsMessage = true; // Alerts message on/off? input bool alertsSound = false; // Alerts sound on/off? input bool alertsPushNotif = false; // Alerts push notification on/off? input bool alertsEmail = false; // Alerts email on/off? input string soundFile = "alert2.wav"; // Sound file double CrossUp[], CrossDn[], trend[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { IndicatorBuffers(3); SetIndexBuffer(0,CrossUp); SetIndexStyle(0,DRAW_ARROW); SetIndexArrow(0,233); SetIndexBuffer(1,CrossDn); SetIndexStyle(1,DRAW_ARROW); SetIndexArrow(1,234); SetIndexBuffer(2,trend); return(INIT_SUCCEEDED); } void OnDeinit(const int reason) { } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { int i,counted_bars=prev_calculated; if(counted_bars<0) return(-1); if(counted_bars>0) counted_bars--; int limit = fmin(rates_total-counted_bars,rates_total-1); for(i = limit; i >=0; i--) { CrossUp[i] = EMPTY_VALUE; CrossDn[i] = EMPTY_VALUE; trend[i] = 0; if(i < rates_total-2) { int operation=signal(i); if(operation==buy) { trend[i]=1; } if(operation==sell) { trend[i]=-1; } if(trend[i] == 1) CrossUp[i] = Low[i+1]-ArrowGap*Point*10; if(trend[i] == -1) CrossDn[i] = High[i+1]+ArrowGap*Point*19; } } if(alertsOn) { int whichBar = 1; if(alertsOnCurrent) whichBar = 0; if(trend[whichBar] != trend[whichBar+1]) { if(trend[whichBar] == 1) doAlert(_Symbol + "(" + timeFrameToString(Period())+")"+" BUY"); if(trend[whichBar] ==-1) doAlert(_Symbol + "(" + timeFrameToString(Period())+")"+" SELL"); } } return(rates_total); } //------------------------------------------------------------------ // //------------------------------------------------------------------ int signal(int i) { double l1=High[i+1]-Low[i+1]; double l2=High[i+2]-Low[i+2]; double r1; double r2; double d1; double d2; if(l2>0 && l1/l2>=TriggerCandleRatio && High[i+1]=TriggerCloseRatio && r2>=TriggerCloseRatio && d2>0 && d1/d2>=TriggerHLRatio) { return(buy); } } if(l2>0 && l1/l2>=TriggerCandleRatio && High[i+1]>High[i+2] && Low[i+1]>Low[i+2]) { d1=MathAbs(High[i+1]-Close[i+1]); d2=MathAbs(High[i+2]-Close[i+2]); r1=d1/l1; r2=d2/l2; if(r1>=TriggerCloseRatio && r2>=TriggerCloseRatio && d2>0 && d1/d2>=TriggerHLRatio) { return(sell); } } return 0; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void doAlert(string doWhat) { static string previousAlert="nothing"; static datetime previousTime; string message; if(previousAlert != doWhat || previousTime != Time[0]) { previousAlert = doWhat; previousTime = Time[0]; message = doWhat; if(alertsMessage) Alert(message); if(alertsPushNotif) SendNotification(message); if(alertsEmail) SendMail("Currency Grail",message); if(alertsSound) PlaySound(soundFile); } } string sTfTable[] = {"M1","M5","M15","M30","H1","H4","D1","W1","MN"}; int iTfTable[] = {1,5,15,30,60,240,1440,10080,43200}; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ string timeFrameToString(int tf) { for(int i=ArraySize(iTfTable)-1; i>=0; i--) if(tf==iTfTable[i]) return(sTfTable[i]); return(""); } //+------------------------------------------------------------------+