View Single Post
  #1 (permalink)  
Old 05-08-2006, 03:58 PM
camisa's Avatar
camisa camisa is offline
Senior Member
 
Join Date: Dec 2005
Location: Portugal
Posts: 229
camisa is on a distinguished road
Very basic coding help needed

Hi all,

My basic problem is programming alerts for already written indicators. I know how to use the iCustom to program simple indicator buy/sell alerts

But I want now to program conditional alerts using 2 or 3 indicators that do not appear on the same candle, for example If i have this strategy:

1. ma10 cross ma20 --> bull signal but wait until
2. price touches ma20 then
3. issue buy signal alert with audio beep and print a green bar on a histogram

I'm only stating this as an example as I need 3 or 4 conditions from different indicators to be met before the alert is issued

I have tried the following code but I have not any signals because I think my code only works when conditions are met on the SAME candle (i think it does not record the value of the first condition and adds it to the value of the 2nd condition and only then issue the alert):

//+------------------------------------------------------------------+
//| Alerta(exemplo).mq4 |
//| Copyright © 2006, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 LawnGreen
#property indicator_color2 Red
double TrigerLong[];
double TrigerSchort[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(2);

SetIndexStyle(0,DRAW_HISTOGRAM,1,LawnGreen);

SetIndexBuffer(0, TrigerLong);
SetIndexLabel(0,"TrigerLong");

SetIndexStyle(1,DRAW_HISTOGRAM,1,Red);

SetIndexBuffer(1, TrigerSchort);
SetIndexLabel(1,"TrigerSchort");

IndicatorShortName("Triger Long/Schort ");
return(0);
}


//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int i;
double ma1,ma;
int counted_bars=IndicatorCounted();
if(counted_bars<0) counted_bars=0;
if(counted_bars>0) counted_bars--;
i=Bars-counted_bars;


while(i>=0)


{
//indicador 1:
ma1 = iMA(Symbol(),0,20,0,MODE_EMA,PRICE_CLOSE,i);
ma = iMA(Symbol(),0,10,0,MODE_EMA,PRICE_CLOSE,i);



if( ma > ma1 )
{
if( Close[i]<= ma1 )
{
TrigerLong[i]=1;
Alert("SINAL LONGO EM ", Symbol());
}

if( Close[i]>ma1)
{
TrigerLong[i]=0;
}

}
else
{ TrigerLong[i]=0; }


// Alerta CURTO:

if( ma < ma1 )
{
if( Close[i]>= ma1 )
{

TrigerSchort[i]=-1;
Alert("SINAL CURTO EM ", Symbol());
}

if( Close[i]<ma1 )
{
TrigerSchort[i]=0;
}

}

else
{ TrigerSchort[i]=0; }



Comment(" ATENÇAO: ALERTA APLICADO AO CROSS ",Symbol());


/* A ZONA DE ACTUAÇAO DO 2º INDICADOR TEM QUE SER LIMITADA DE FORMA
A O ALERTA NAO FICAR ETERNAMENTE A BUZINAR UMA SITUAÇAO JA OCORRIDA. NESTE CASO
APENAS SINALIZA DURANTE O TEMPO DE CONSTRUÇAO DA BARRA QUE FEZ A PASSAGEM PELO VALOR -150
*/
i--;

}

return(0);
}



//+------------------------------------------------------------------+
Reply With Quote