It takes a fair amount of time to learn the intricacies of coding. Something that will take time to learn. For those of you that are wanting to add alerts to some of your indicators , I have found a tool that could possibly help you do so. I am not affiliated with in any way , shape or form. So I am not really trying to promote anything. I have just recently found the site while searching for ways to add alerts to indicators and find it could be useful to those of us without coding experience. It seems to be something for simpler tasks. Not sure how complex you can get. So...If you have an indicator that you would like to add some simple alerts to
PS - Not sure what Admin is going to think about this post but , I'm just trying to help people with the same problems I have had.
Re: How to add alerts to your indicators
12Here is the code for a Historical Volatility Alert that I created. I need to play around with it a bit more but , it was fairly easy to do. Feel free to change it around for your personal use.
Code: Select all
#property copyright ""
#property link ""
#property version "1.00"
#property description ""
#include <stdlib.mqh>
#include <stderror.mqh>
//--- indicator settings
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_type1 DRAW_ARROW
#property indicator_width1 1
#property indicator_color1 0xFFAA00
#property indicator_label1 "Buy"
//--- indicator buffers
double Buffer1[];
datetime time_alert; //used when sending alert
double myPoint; //initialized in OnInit
void myAlert(string type, string message)
{
if(type == "print")
Print(message);
else if(type == "error")
{
Print(type+" | HV @ "+Symbol()+","+Period()+" | "+message);
}
else if(type == "order")
{
}
else if(type == "modify")
{
}
else if(type == "indicator")
{
Print(type+" | HV @ "+Symbol()+","+Period()+" | "+message);
}
}
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
IndicatorBuffers(1);
SetIndexBuffer(0, Buffer1);
SetIndexEmptyValue(0, 0);
SetIndexArrow(0, 241);
//initialize myPoint
myPoint = Point();
if(Digits() == 5 || Digits() == 3)
{
myPoint *= 10;
}
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, 0);
}
else
limit++;
//--- main loop
for(int i = limit-1; i >= 0; i--)
{
if (i >= MathMin(5000-1, rates_total-1-50)) continue; //omit some old rates to prevent "Array out of range" or slow calculation
//Indicator Buffer 1
if(iCustom(NULL, PERIOD_CURRENT, "HistVolatility6", 8, 365, true, 0, 1000, 1, 0, i) > 18 //HistVolatility6 > fixed value
)
{
Buffer1[i] = Open[1+i] - iATR(NULL, PERIOD_CURRENT, 14, i); //Set indicator value at Candlestick Open - Average True Range
if(i == 0 && Time[0] != time_alert) { myAlert("indicator", "Buy"); time_alert = Time[0]; } //Instant alert, only once per bar
}
else
{
Buffer1[i] = 0;
}
}
return(rates_total);
}
//+------------------------------------------------------------------+
Re: How to add alerts to your indicators
13Right now it is set to alert anytime Volatility is over 18% for the current time frame you are on. Like I said , I need to play around with it a bit.
Re: How to add alerts to your indicators
15Find the last line starting with extern (older MT4 indicators) or input (MT5 and newer MT4 indicators) statement.
Insert the following code after that line:
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;
This code uses empty initial alert text and email subject. They will be filled during alert evaluation.
Insert the following code after that line:
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;
This code uses empty initial alert text and email subject. They will be filled during alert evaluation.
what we want: 1+1+1+1+1+1+1+1+1=9
what market delivers: 1+2+8+7-4+0-5+8-4-5+1=9

what market delivers: 1+2+8+7-4+0-5+8-4-5+1=9

Re: How to add alerts to your indicators
16
bilbao wrote: Fri Jan 31, 2020 6:57 am Find the last line starting with extern (older MT4 indicators) or input (MT5 and newer MT4 indicators) statement.
Insert the following code after that line:
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;
This code uses empty initial alert text and email subject. They will be filled during alert evaluation.
Hi, I did as you said but I couldn't, can you check what I did wrong? Thank you