//+------------------------------------------------------------------+ //| Indicator: Example_0001.mq5 | //| Created with EABuilder.com | //| https://www.eabuilder.com | //+------------------------------------------------------------------+ #property copyright "Created with EABuilder.com" #property link "https://www.eabuilder.com" #property version "1.00" #property description "" //--- indicator settings #property indicator_chart_window #property indicator_buffers 1 #property indicator_plots 1 #property indicator_type1 DRAW_ARROW #property indicator_width1 1 #property indicator_color1 0xFFAA00 #property indicator_label1 "Buy" #define PLOT_MAXIMUM_BARS_BACK 5000 #define OMIT_OLDEST_BARS 50 //--- indicator buffers double Buffer1[]; input int Fast_Triple = 14; input int Slow_Doble = 25; datetime time_alert; //used when sending alert double myPoint; //initialized in OnInit int TEMA_handle; double TEMA[]; int DEMA_handle; double DEMA[]; double Low[]; void myAlert(string type, string message) { if(type == "print") Print(message); else if(type == "error") { Print(type+" | Example_0001 @ "+Symbol()+","+IntegerToString(Period())+" | "+message); } else if(type == "order") { } else if(type == "modify") { } else if(type == "indicator") { Print(type+" | Example_0001 @ "+Symbol()+","+IntegerToString(Period())+" | "+message); } } //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { SetIndexBuffer(0, Buffer1); PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, EMPTY_VALUE); PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, MathMax(Bars(Symbol(), PERIOD_CURRENT)-PLOT_MAXIMUM_BARS_BACK+1, OMIT_OLDEST_BARS+1)); PlotIndexSetInteger(0, PLOT_ARROW, 241); //initialize myPoint myPoint = Point(); if(Digits() == 5 || Digits() == 3) { myPoint *= 10; } TEMA_handle = iTEMA(NULL, PERIOD_CURRENT, Fast_Triple, 0, PRICE_CLOSE); if(TEMA_handle < 0) { Print("The creation of iTEMA has failed: TEMA_handle=", INVALID_HANDLE); Print("Runtime error = ", GetLastError()); return(INIT_FAILED); } DEMA_handle = iDEMA(NULL, PERIOD_CURRENT, Slow_Doble, 0, PRICE_CLOSE); if(DEMA_handle < 0) { Print("The creation of iDEMA has failed: DEMA_handle=", INVALID_HANDLE); Print("Runtime error = ", GetLastError()); return(INIT_FAILED); } return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ 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 limit = rates_total - prev_calculated; //--- counting from 0 to rates_total ArraySetAsSeries(Buffer1, true); //--- initial zero if(prev_calculated < 1) { ArrayInitialize(Buffer1, EMPTY_VALUE); } else limit++; datetime Time[]; if(BarsCalculated(TEMA_handle) <= 0) return(0); if(CopyBuffer(TEMA_handle, 0, 0, rates_total, TEMA) <= 0) return(rates_total); ArraySetAsSeries(TEMA, true); if(BarsCalculated(DEMA_handle) <= 0) return(0); if(CopyBuffer(DEMA_handle, 0, 0, rates_total, DEMA) <= 0) return(rates_total); ArraySetAsSeries(DEMA, true); if(CopyLow(Symbol(), PERIOD_CURRENT, 0, rates_total, Low) <= 0) return(rates_total); ArraySetAsSeries(Low, true); if(CopyTime(Symbol(), Period(), 0, rates_total, Time) <= 0) return(rates_total); ArraySetAsSeries(Time, true); //--- main loop for(int i = limit-1; i >= 0; i--) { if (i >= MathMin(PLOT_MAXIMUM_BARS_BACK-1, rates_total-1-OMIT_OLDEST_BARS)) continue; //omit some old rates to prevent "Array out of range" or slow calculation //Indicator Buffer 1 if(TEMA[i] > DEMA[i] && TEMA[i+1] < DEMA[i+1] //Triple Exponential Moving Average crosses above Double Exponential Moving Average ) { Buffer1[i] = Low[i]; //Set indicator value at Candlestick Low if(i == 0 && Time[0] != time_alert) { myAlert("indicator", "Buy"); time_alert = Time[0]; } //Instant alert, only once per bar } else { Buffer1[i] = EMPTY_VALUE; } } return(rates_total); } //+------------------------------------------------------------------+