Ichimoku Alert not working

Jixo man

Trader
Jul 26, 2020
46
2
14
//+------------------------------------------------------------------+
//| Ichimoku.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Ichimoku Kinko Hyo"
//--- indicator settings
#property indicator_chart_window
#property indicator_buffers 5
#property indicator_plots 4
#property indicator_type1 DRAW_LINE
#property indicator_type2 DRAW_LINE
#property indicator_type3 DRAW_FILLING
#property indicator_type4 DRAW_LINE
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 SandyBrown,Thistle
#property indicator_color4 Lime
#property indicator_label1 "Tenkan-sen"
#property indicator_label2 "Kijun-sen"
#property indicator_label3 "Senkou Span A;Senkou Span B"
#property indicator_label4 "Chikou Span"
//--- input parameters
input int InpTenkan=9; // Tenkan-sen
input int InpKijun=26; // Kijun-sen
input int InpSenkou=52; // Senkou Span B

input int TriggerCandle = 1;
input bool EnableNativeAlerts = true;
input bool EnableSoundAlerts = true;
input bool EnableEmailAlerts = true;
input bool EnablePushAlerts = true;
input string AlertEmailSubject = "";
input string AlertText = "";
input string SoundFileName = "alert.wav";

datetime LastAlertTime = D'01.01.1970';
int LastAlertDirection = 0;
//--- indicator buffers
double ExtTenkanBuffer[];
double ExtKijunBuffer[];
double ExtSpanABuffer[];
double ExtSpanBBuffer[];
double ExtChikouBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,ExtTenkanBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtKijunBuffer,INDICATOR_DATA);
SetIndexBuffer(2,ExtSpanABuffer,INDICATOR_DATA);
SetIndexBuffer(3,ExtSpanBBuffer,INDICATOR_DATA);
SetIndexBuffer(4,ExtChikouBuffer,INDICATOR_DATA);
//---
IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
//--- sets first bar from what index will be drawn
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpTenkan);
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,InpKijun);
PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,InpSenkou-1);
//--- lines shifts when drawing
PlotIndexSetInteger(2,PLOT_SHIFT,InpKijun);
PlotIndexSetInteger(3,PLOT_SHIFT,-InpKijun);
//--- change labels for DataWindow
PlotIndexSetString(0,PLOT_LABEL,"Tenkan-sen("+string(InpTenkan)+")");
PlotIndexSetString(1,PLOT_LABEL,"Kijun-sen("+string(InpKijun)+")");
PlotIndexSetString(2,PLOT_LABEL,"Senkou Span A;Senkou Span B("+string(InpSenkou)+")");
//--- initialization done
}
//+------------------------------------------------------------------+
//| get highest value for range |
//+------------------------------------------------------------------+
double Highest(const double&array[],int range,int fromIndex)
{
double res=0;
//---
res=array[fromIndex];
for(int i=fromIndex;i>fromIndex-range && i>=0;i--)
{
if(res<array) res=array;
}
//---
return(res);
}
//+------------------------------------------------------------------+
//| get lowest value for range |
//+------------------------------------------------------------------+
double Lowest(const double&array[],int range,int fromIndex)
{
double res=0;
//---
res=array[fromIndex];
for(int i=fromIndex;i>fromIndex-range && i>=0;i--)
{
if(res>array) res=array;
}
//---
return(res);
}
//+------------------------------------------------------------------+
//| Ichimoku Kinko Hyo |
//+------------------------------------------------------------------+
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;
//---
if(prev_calculated==0) limit=0;
else limit=prev_calculated-1;
//---
for(int i=limit;i<rates_total && !IsStopped();i++)
{
ExtChikouBuffer=close;
//--- tenkan sen
double _high=Highest(high,InpTenkan,i);
double _low=Lowest(low,InpTenkan,i);
ExtTenkanBuffer=(_high+_low)/2.0;
//--- kijun sen
_high=Highest(high,InpKijun,i);
_low=Lowest(low,InpKijun,i);
ExtKijunBuffer=(_high+_low)/2.0;
//--- senkou span a
ExtSpanABuffer=(ExtTenkanBuffer+ExtKijunBuffer)/2.0;
//--- senkou span b
_high=Highest(high,InpSenkou,i);
_low=Lowest(low,InpSenkou,i);
ExtSpanBBuffer=(_high+_low)/2.0;
}
//--- done
return(rates_total);
if (((TriggerCandle > 0) && (time[rates_total - 1] > LastAlertTime)) || (TriggerCandle == 0))
{
string Text;
// This is the code for buy
if (((ExtKijunBuffer[rates_total - 1 - TriggerCandle] > ExtTenkanBuffer[rates_total - 1 - TriggerCandle]) && (ExtKijunBuffer[rates_total - 2 - TriggerCandle] <= ExtTenkanBuffer[rates_total - 2 - TriggerCandle])) && ((TriggerCandle > 0) || ((TriggerCandle == 0) && (LastAlertDirection != 1))))
{
Text = AlertText + "Alligator jaw is above Alligator Teeth: " + Symbol() + " - " + EnumToString(Period()) + " - Alligator jaw has cross Alligator Teeth.";
if (EnableNativeAlerts) Alert(Text);
if (EnableEmailAlerts) SendMail(AlertEmailSubject + "please check for buy signal", Text);
if (EnableSoundAlerts) PlaySound(SoundFileName);
if (EnablePushAlerts) SendNotification(Text);
LastAlertTime = time[rates_total - 1];
LastAlertDirection = 1;
}
// the code below is for sell signal
if (((ExtTenkanBuffer[rates_total - 1 - TriggerCandle] < ExtKijunBuffer[rates_total - 1 - TriggerCandle]) && (ExtTenkanBuffer[rates_total - 2 - TriggerCandle] >= ExtKijunBuffer[rates_total - 2 - TriggerCandle])) && ((TriggerCandle > 0) || ((TriggerCandle == 0) && (LastAlertDirection != -1))))
{
Text = AlertText + "Alligator Jaws is below Alligator Teeth : " + Symbol() + " - " + EnumToString(Period()) + " - Alligator Jaws is below Alligator Teeth.";
if (EnableNativeAlerts) Alert(Text);
if (EnableEmailAlerts) SendMail(AlertEmailSubject + "please check for buy signal", Text);
if (EnableSoundAlerts) PlaySound(SoundFileName);
if (EnablePushAlerts) SendNotification(Text);
LastAlertTime = time[rates_total - 1];
LastAlertDirection = -1;
}
}



}
//+------------------------------------------------------------------+
 

Attachments

  • Ichimoku mt5 code.txt
    7.1 KB · Views: 3

Enivid

Administrator
Staff member
Nov 30, 2008
18,530
1,355
144
Odesa
www.earnforex.com
Please do not post such long pieces of unformatted code. It is best just to attach the .mq4 file instead.

PS: Your alert code is placed just below the return() call of the OnCalculate() function - it will never have a chance to execute.
 

Jixo man

Trader
Jul 26, 2020
46
2
14
Please do not post such long pieces of unformatted code. It is best just to attach the .mq4 file instead.

PS: Your alert code is placed just below the return() call of the OnCalculate() function - it will never have a chance to execute.
Thanks for your timely response.