Hi all i was trying to add a an alert to an indicator I found over in the code base section, I am not sure what I did wrong as the alert pops at the end of each candle close now, but not when the arrows are triggered.
Below is the code, and I have also attached the indicator.
//+------------------------------------------------------------------+//| Value Charts.mq5 |//| Copyright 2011, FxGeek. |//| http://www.mql5.com |//+------------------------------------------------------------------+#property copyright"2011, FxGeek."#property link"http://www.mql5.com"//--- indicator settings#property indicator_separate_window#property indicator_buffers7#property indicator_plots1#property indicator_type1 DRAW_COLOR_BARS#property indicator_color1 clrRed,clrGreen,clrBlue#property indicator_width1 1#property indicator_label1 "Open;High;Low;Close"//--- indicator levels#property indicator_level1 8#property indicator_level2 6#property indicator_level3 -6#property indicator_level4 -8#property indicator_levelcolorclrBlack//--- indicator include#include <MovingAverages.mqh>
//--- indicator input parametersinputint Periode = 5;
inputbool Show_Arrow = true;
inputint Arrow_Width = 0;
inputcolor Arrow_Up = clrGreen;
inputcolor Arrow_Down = clrRed;
//--- indicator buffersdouble ExtOBuffer[];
double ExtHBuffer[];
double ExtLBuffer[];
double ExtCBuffer[];
double ExtColorBuffer[];
double RangeAverage[];
double MiddleAverage[];
#define DATA_LIMIT Periode
double _AValue;
double _BValue;
datetime tm = TimeCurrent();
//+------------------------------------------------------------------+//| Custom indicator initialization function |//+------------------------------------------------------------------+voidOnInit()
{
//--- indicator buffers mapping SetIndexBuffer(0,ExtOBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtHBuffer,INDICATOR_DATA);
SetIndexBuffer(2,ExtLBuffer,INDICATOR_DATA);
SetIndexBuffer(3,ExtCBuffer,INDICATOR_DATA);
SetIndexBuffer(4,ExtColorBuffer,INDICATOR_COLOR_INDEX);
SetIndexBuffer(5,RangeAverage,INDICATOR_CALCULATIONS);
SetIndexBuffer(6,MiddleAverage,INDICATOR_CALCULATIONS);
//---IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
IndicatorSetString(INDICATOR_SHORTNAME,"Value Chart "+IntegerToString(Periode));
//--- initialization done
}
//+------------------------------------------------------------------+//| Custom indicator deinitialization function |//+------------------------------------------------------------------+voidOnDeinit(constint reason)
{
ClearMyObjects();
Print("Deinit Value Chart, reason = "+IntegerToString(reason));
}
//+------------------------------------------------------------------+//| Value Chart | //+------------------------------------------------------------------+intOnCalculate(constint rates_total,
constint prev_calculated,
constdatetime &Time[],
constdouble &Open[],
constdouble &High[],
constdouble &Low[],
constdouble &Close[],
constlong &TickVolume[],
constlong &Volume[],
constint &Spread[])
{
int i,limit;
//--- check for bars countif(rates_total<DATA_LIMIT)
return(0);// not enough bars for calculation//--- set first bar from what calculation will startif(prev_calculated<DATA_LIMIT)
limit=DATA_LIMIT;
else
limit=prev_calculated-1;
//--- the main loop of calculationsfor(i=limit;i<rates_total && !IsStopped();i++) {
RangeAverage[i]=High[i]-Low[i];
_AValue=0.2*SimpleMA(i,Periode,RangeAverage);
MiddleAverage[i]=(High[i]+Low[i])/2.0;
_BValue=SimpleMA(i,Periode,MiddleAverage);
ExtOBuffer[i]=((Open[i] - _BValue) / _AValue);
ExtHBuffer[i]=((High[i] - _BValue) / _AValue);
ExtLBuffer[i]=((Low[i] - _BValue) / _AValue);
ExtCBuffer[i]=((Close[i]- _BValue) / _AValue);
//--- set color for candle//--- check for bear candleif(ExtCBuffer[i]<ExtOBuffer[i])
ExtColorBuffer[i]=0.0;
//--- check for bull candleif(ExtCBuffer[i]>ExtOBuffer[i])
ExtColorBuffer[i]=1.0;
//--- check for lower extreme bar if(ExtLBuffer[i]<=-8)
{
ExtColorBuffer[i]=2.0;
if(Show_Arrow)Trace("Value Chart"+IntegerToString(i),1,Low[i],Time[i],Arrow_Up);
}
//--- check for high extreme bar if(ExtHBuffer[i]>=8)
{
ExtColorBuffer[i]=2.0;
if(Show_Arrow)Trace("Value Chart"+IntegerToString(i),-1,High[i],Time[i],Arrow_Down);
}
}
if(isNewBar() == true) {
if(ExtLBuffer[0]!=EMPTY_VALUE) {
Alert("CALL "+Symbol()+" Time: "+TimeToString(tm,TIME_MINUTES));
}
elseif(ExtHBuffer[0]!=EMPTY_VALUE) {
Alert("PUT "+Symbol()+" Time: "+TimeToString(tm,TIME_MINUTES));
}
}
//--- return value of prev_calculated for next callreturn(rates_total);
}
//+------------------------------------------------------------------+//| Trace Arrow Function |//+------------------------------------------------------------------+void Trace(string name,int sens,double price,datetime time,color couleur)
{
ObjectCreate(0,name,OBJ_ARROW,0,time,price);
if(sens==1)
ObjectSetInteger(0,name,OBJPROP_ARROWCODE,233);
//Alert("CALL "+Symbol()+" Time: "+TimeToString(tm,TIME_MINUTES));if(sens==-1)
ObjectSetInteger(0,name,OBJPROP_ARROWCODE,234);
//Alert("PUT "+Symbol()+" Time: "+TimeToString(tm,TIME_MINUTES));ObjectSetInteger(0,name,OBJPROP_COLOR,couleur);
ObjectSetInteger(0,name,OBJPROP_WIDTH,Arrow_Width);
}
//+------------------------------------------------------------------+//| Check Bar Time |//+------------------------------------------------------------------+bool isNewBar() {
staticdatetime last_time=0;
datetime lastbar_time=SeriesInfoInteger(Symbol(),Period(),SERIES_LASTBAR_DATE);
if(last_time==0) {
last_time=lastbar_time;
return(false);
}
if(last_time!=lastbar_time) {
last_time=lastbar_time;
return(true);
}
return(false);
}
//+------------------------------------------------------------------+//| Delete Arrow Function |//+------------------------------------------------------------------+ void ClearMyObjects()
{
string name;
for(int i=ObjectsTotal(0,0); i>=0; i--)
{
name=ObjectName(0,i);
if(StringSubstr(name,0,5)=="Value") ObjectDelete(0,name);
}
}
//+------------------------------------------------------------------+
Hi all i was trying to add a an alert to an indicator I found over in the code base section, I am not sure what I did wrong as the alert pops at the end of each candle close now, but not when the arrows are triggered.
Below is the code, and I have also attached the indicator.