Here is the code of the indicator.
Code: Select all
//+------------+-----------------------------------------------------+
//| v.22.04.05 | up and Down.mq4 |
//| Copyright © 2005, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "UP&DOWN ARROW ALERT Copyright © 2020, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
#property indicator_chart_window
#property indicator_buffers 7
#property indicator_color1 clrNONE
#property indicator_color2 clrLimeGreen
#property indicator_color3 clrRed
#property indicator_color4 Red
#property indicator_color5 Blue
#property indicator_color6 Red
#property indicator_color7 Blue
#property indicator_width5 2
#property indicator_width7 2
#property indicator_width4 2
#property indicator_width6 2
#define PREFIX ""
extern int Periodic = 14;
extern color ArrowOnUpColor = LimeGreen;
extern color ArrowOnDnColor = Red;
extern int ArrowDnCode = 234;
extern int ArrowUpCode = 233;
extern int ArrowSize = 5;
extern int ArrowGap = 1;
extern bool AlertsMessage = false;
extern bool AlertsSound = false;
extern string SoundFile = "wait.wav";
bool b=1,s=1;
datetime t=0, ta=0;
double begin_sign[],up[],dn[];
double trend_Up[];
double trend_Dn[];
double trend_Up_top[];
double trend_Dn_down[];
// -------------------------------------------------------------------------------------------------------------
int init()
{
SetIndexBuffer(0,begin_sign);
IndicatorShortName("UP&DOWN ARROW");
SetIndexLabel(0,"begin_sign");
SetIndexStyle(1, DRAW_ARROW, EMPTY,ArrowSize,ArrowOnUpColor);
SetIndexArrow(1, ArrowUpCode);
SetIndexDrawBegin(1,0.0);
SetIndexBuffer(1,up);
SetIndexLabel(1,"up");
SetIndexStyle(2, DRAW_ARROW, EMPTY,ArrowSize,ArrowOnDnColor);
SetIndexArrow(2, ArrowDnCode);
SetIndexDrawBegin(2,0.0);
SetIndexBuffer(2,dn);
SetIndexLabel(2,"dn");
SetIndexBuffer(3,trend_Up);
SetIndexStyle(3,DRAW_LINE,STYLE_DOT);
SetIndexLabel(3,"trend_Up");
// SetIndexArrow(2,233);
SetIndexBuffer(4,trend_Dn);
SetIndexStyle(4,DRAW_LINE,STYLE_DOT);
SetIndexLabel(4,"trend_Dn");
SetIndexBuffer(5,trend_Up_top);
SetIndexStyle(5,DRAW_LINE,STYLE_DOT);
SetIndexLabel(5,"trend_Up_top");
// SetIndexArrow(2,233);
SetIndexBuffer(6,trend_Dn_down);
SetIndexStyle(6,DRAW_LINE,STYLE_DOT);
SetIndexLabel(6,"trend_Dn_down");
ta=Time[0];
return(0);
}
// -------------------------------------------------------------------------------------------------------------
int deinit()
{
for(int i = ObjectsTotal()-1; i >= 0; i--)
if(StringSubstr(ObjectName(i), 0, StringLen(PREFIX)) == PREFIX)
ObjectDelete(ObjectName(i));
return(0);
}
// -------------------------------------------------------------------------------------------------------------
int start()
{
int limit;
int counted_bars;
//double prev, current, old;
double Value=0,Value1=0,Value2=0,ndelta=0,ndelta1=0,ndelta2=0;
double price;
double MinL=0;
double MaxH=0;
counted_bars = IndicatorCounted();
if(counted_bars > 0)
counted_bars--;
limit = Bars - counted_bars;
for(int i=0; i<=limit; i++)
{
MaxH = High[iHighest(NULL,0,MODE_CLOSE,Periodic,i)];
MinL = Low[iLowest(NULL,0,MODE_CLOSE,Periodic,i)];
price = (Open[i]+ Close[i])/2;
if(MaxH-MinL == 0)
Value = 0.33*2*(0-0.5) + 0.67*Value1;
else
Value = 0.33*2*((price-MaxH)/(MinL-MaxH)-0.5) + 0.67*Value1;
Value=MathMin(MathMax(Value,-0.999999),0.9999999);
if(1-Value == 0)
begin_sign[i]=0.5+0.5*ndelta1;
else
begin_sign[i]=0.5*MathLog((1+Value)/(1-Value))+0.5*ndelta1;
Value1=Value;
ndelta1=begin_sign[i];
if(begin_sign[i]<0 )
{
trend_Up[i]=Low[i];
trend_Up_top[i]=High[i];
}
if(begin_sign[i]>0 )
{
trend_Dn[i]=Low[i];
trend_Dn_down[i]=High[i];
}
if(t!=Time[0])
{
if(begin_sign[i]>0 && begin_sign[i-1]<0 && b)
{
up[i]=Low[i]-5*ArrowGap*Point;
if(ta<Time[0])
{
if(AlertsMessage) Alert(Symbol(), (" M"), Period()," ", " UP&DOWN ARROW : BUY!");
if (AlertsSound) PlaySound(SoundFile);
ta=Time[0];
}
b=0;
s=1;
}
if(begin_sign[i]<0 && begin_sign[i-1]>0 && s)
{
dn[i]=High[i]+5*ArrowGap*Point;;
if(ta<Time[0])
{
if(AlertsMessage) Alert(Symbol(), (" M"), Period()," "," UP&DOWN ARROW : SELL!");
if (AlertsSound) PlaySound(SoundFile);
ta=Time[0];
}
s=0;
b=1;
}
}
}
return(0);
}
//========================================
string PeriodString()
{
switch (_Period)
{
case PERIOD_M1: return("M1");
case PERIOD_M5: return("M5");
case PERIOD_M15: return("M15");
case PERIOD_M30: return("M30");
case PERIOD_H1: return("H1");
case PERIOD_H4: return("H4");
case PERIOD_D1: return("D1");
case PERIOD_W1: return("W1");
case PERIOD_MN1: return("MN1");
default: return("M"+(string)_Period);
}
return("M"+(string)_Period);
}
Thank you.