I want to write an indicator which prints 3 different types of signals, each signal can be up or down and I don't know how to do that. I know how to make an indicator that prints an Up arrow if some conditions are met and down if the complementary conditions are met.
Here's is the main code that I use to write that kind of indicators with only 1 type of signal:
Code: Select all
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 White
#property indicator_color2 White
//extern string CornerSel = "0:topleft, 1:top-right, 2:bottom-left, 3:bottom-right";
extern bool limitarBarras = true;
extern int limite = 15000;
int n_digits = 0, flagval1 = 0, flagval2 = 0;
double serieUp[], serieDown[];
bool SoundON = true;
datetime prevtime;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
SetIndexStyle(0, DRAW_ARROW, EMPTY, 1);
SetIndexArrow(0, 233);
SetIndexBuffer(0, serieUp);
SetIndexStyle(1, DRAW_ARROW, EMPTY, 1);
SetIndexArrow(1, 234);
SetIndexBuffer(1, serieDown);
GlobalVariableSet("AlertTime"+Symbol()+Period(),CurTime());
GlobalVariableSet("SignalType"+Symbol()+Period(),OP_SELLSTOP);
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
GlobalVariableDel("AlertTime"+Symbol()+Period());
GlobalVariableDel("SignalType"+Symbol()+Period());
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
static datetime Time0; if (Time0 == Time[0]) return(0); Time0 = Time[0]; //Solo continua al comienzo de una barra nueva
RefreshRates();
WindowRedraw();
int limit, i, counter;
double tmp=0;
int MA_Mode = 1, PriceMode = 0;
double Range, AvgRange;
int counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
if(limitarBarras) counted_bars = Bars-limite;
limit=Bars-counted_bars;
for(i = limit; i >= 0; i--) {
counter=i;
Range=0;
AvgRange=0;
for (counter=i ;counter<=i+9;counter++) AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
Range=AvgRange/10;
if(conditionsUp)
{
if (i == 1 && flagval1==0){ flagval1=1; flagval2=0; }
serieUp[i+2] = Low[i+2] - Range*0.4;
}
else if(conditionsDown)
{
if (i == 1 && flagval2==0) { flagval2=1; flagval1=0; }
serieDown[i+2] = High[i+2] + Range*0.4;
}
}
if (flagval1==1 && CurTime() > GlobalVariableGet("AlertTime"+Symbol()+Period()) && GlobalVariableGet("SignalType"+Symbol()+Period())!=OP_BUY)
{
//if (SoundON) Alert(Symbol() );
tmp = CurTime() + (Period()-MathMod(Minute(),Period()))*60;
GlobalVariableSet("AlertTime"+Symbol()+Period(),tmp);
GlobalVariableSet("SignalType"+Symbol()+Period(),OP_BUY);
}
if (flagval2==1 && CurTime() > GlobalVariableGet("AlertTime"+Symbol()+Period()) && GlobalVariableGet("SignalType"+Symbol()+Period())!=OP_SELL)
{
//if (SoundON) Alert(Symbol() );
tmp = CurTime() + (Period()-MathMod(Minute(),Period()))*60;
GlobalVariableSet("AlertTime"+Symbol()+Period(),tmp);
GlobalVariableSet("SignalType"+Symbol()+Period(),OP_SELL);
}
return(0);
}
Regards!
Adrian