problem with a building a simple indicator

 

I build this indicator whitch has the task of buyng when the ADX is greater than 30 and the candle is bullish and sell when the ADX is greater than 30 and the candle is bearish , but it does not work and I cannot enderstand why , can you tell me where i went wrong ?

Thank you in advance for the answer!! 


this is the code :


#property indicator_buffers 6 

double Buf0[];
double Buf1[];

input int period = 30;

input GrandezzaFreccia = 6 ; 

int Init () {

SetIndexBuffer (0, Buf0);
SetIndexStyle ( 0, DRAW_ARROW , EMPTY , GrandezzaFreccia, clrGreen);
SetIndexArrow ( 0, 233 ); 

SetIndexBuffer ( 1, Buf1) ;
SetIndexStyle ( 1, DRAW_ARROW , EMPTY , GrandezzaFreccia , clrRed ); 
SetIndexArrow ( 1, 234 );

IndicatorShortName (" ") ;

SetIndexLabel ( 0, NULL);
SetIndexLabel ( 2, NULL) ;
IndicatorSetInteger ( INDCATOR_DIGITS, 0);
IndicatorSetDouble ( INDICATOR_MAXIMUM , 200);
IndicatorSetDouble (INDICATOR_MINIMUM , 0);
SetLevelValue ( 0, 100) ;
SetLevelStyle ( STYLE_DASH , 0);

return 0
}

int start () {

inizializzazioneIndicatore ();

for ( int i= Bars - 1 ; i> =0 ; i--){
if (iADX (Symbol () ,  PERIOD_CURRENT , period ) > 30)
if (PRICE_CLOSE > PRICE_OPEN ) {
Buf0[i] = 100; 
}
if ( iADX (Symbol () , PERIOD_CURRENT , period ) > 30 )
if (PRICE_CLOSE < PRICE_OPEN ) {
Buf1 [0] = 100 ;
}
}





 

An indicator cannot buy and sell

you need an expert advisor

 
  1. indicators can not trade.
  2. if (PRICE_CLOSE > PRICE_OPEN ) {

    PRICE_CLOSE equals zero and PRICCE_OPEN equals one. Zero is never greater than one.

  3. You never made any buffers.

    "Init" is not the same as "init."

    You should stop using the old event handlers and IndicatorCounted() and start using new event handlers.
              Event Handling Functions - MQL4 Reference
              How to do your lookbacks correctly - MQL4 programming forum #9-14 & #19 (2016.05.11)