|
|||||||
| Register in Forex TSD! | |
|
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time). Click here to register and get more information |
|
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
||||
|
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); } //+------------------------------------------------------------------+
__________________
http://img.photobucket.com/albums/v4...sa/userbar.jpg |
|
||||
|
Hi,
before Alert(....) I suggest to place if ( i == 0) Because Alert work on the current bar only. Igor
__________________
Let's improve trade skills together http://finance.groups.yahoo.com/group/TrendLaboratory |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Trade Once Only - Coding Help needed | hoosain | Suggestions for Trading Systems | 5 | 05-02-2006 02:01 PM |
| Coding Needed | nnjeim | Metatrader 4 | 1 | 03-15-2006 05:18 AM |
| Help coding a cam indicator needed. | DanielTyrkiel | Suggestions for Trading Systems | 5 | 11-29-2005 12:48 PM |