Help!! simple color change indicator problem..

 

Anyone help with this?? I've spent the last three hours trying to make this indicator change the bar color when it is below 0. Green above 0, red below 0. I'm not very good with coding, so any help would be greatly appreciated, thanks!

//+------------------------------------------------------------------+

//| DiNapoli Detrend Oscillator.mq4

//| Ramdass - Conversion only

//+------------------------------------------------------------------+

#property indicator_separate_window

#property indicator_buffers 1

#property indicator_color1 Blue

extern int x_prd=14;

extern int CountBars=3000;

//---- buffers

double dpo[];

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

int init()

{

string short_name;

//---- indicator line

IndicatorBuffers(1);

SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,3);

SetIndexBuffer(0,dpo);

//----

return(0);

}

//+------------------------------------------------------------------+

//| DPO |

//+------------------------------------------------------------------+

int start()

{

if (CountBars>=Bars) CountBars=Bars;

SetIndexDrawBegin(0,Bars-CountBars+x_prd+1);

int i,counted_bars=IndicatorCounted();

double t_prd;

//----

if(Bars<=x_prd) return(0);

//---- initial zero

if(counted_bars<x_prd)

{

for(i=1;i<=x_prd;i++) dpo[CountBars-i]=0.0;

}

//----

i=CountBars-x_prd-1;

t_prd=x_prd/2+1;

while(i>=0)

{

dpo=Close-iMA(NULL,0,7,MODE_SMA,0,PRICE_CLOSE,i);

i--;

}

return(0);

}

//+------------------------------------------------------------------+

 

Only way I know how is to add another indicator buffer

Maybe you figured it out already but here's what I did neway:

//+------------------------------------------------------------------+

//| DiNapoli Detrend Oscillator.mq4

//| Ramdass - Conversion only

//+------------------------------------------------------------------+

#property indicator_separate_window

#property indicator_buffers 2

#property indicator_color1 Lime

#property indicator_color2 Red

extern int x_prd=14;

extern int CountBars=3000;

//---- buffers

double dpo[], dpo2[];

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

int init()

{

string short_name;

//---- indicator line

IndicatorBuffers(2);

SetIndexBuffer(0,dpo);

SetIndexBuffer(1,dpo2);

//----

return(0);

}

//+------------------------------------------------------------------+

//| DPO |

//+------------------------------------------------------------------+

int start()

{

//Putting the SetIndexStyle here allows the setting to remain after each time you re-compile

//If you dont, the setting will only be applied if you reload the indicator (manually or from a saved template)

SetIndexStyle(0, DRAW_HISTOGRAM, STYLE_SOLID, 3, Lime);

SetIndexStyle(1, DRAW_HISTOGRAM, STYLE_SOLID, 3, Red);

if (CountBars>=Bars) CountBars=Bars;

SetIndexDrawBegin(0,Bars-CountBars+x_prd+1);

int i,counted_bars=IndicatorCounted();

double t_prd;

//----

if(Bars<=x_prd) return(0);

//---- initial zero

if(counted_bars<x_prd)

{

for(i=1;i<=x_prd;i++) dpo[CountBars-i]=0.0;

}

//----

i=CountBars-x_prd-1;

t_prd=x_prd/2+1;

double val = 0;

while(i>=0)

{

val=Close-iMA(NULL,0,7,MODE_SMA,0,PRICE_CLOSE,i);

if (val >= 0) {

dpo = val;

dpo2 = 0;

} else if (val < 0) {

dpo2 = val;

dpo = 0;

}

i--;

}

return(0);

}

//+------------------------------------------------------------------+

 

no I was still having problems coding it, it just wasn't coming out right.. But this is PERFECT!! thank you very much!!

 

How to reference the DiNapoli DPO in an expert?

Hello Jamrok,

This PM is concerning your post regarding the DiNapoli Detrend Price Oscillator. Hope you don't mind but thought you might not see the question if I posted it following your post of last May .

I'm trying the reference the DiNap DPO from an expert but don't know how to configure the line of code that follows, 'iCustom'. Would you know what I would include?

For example for reference to the custom indicator 'Stochastic DiNapoli" I would include the following;

doublestom1 = iCustom(NULL,0,"StochasticDiNapoli", 12,6,7,MODE_EMA,0,MODE_MAIN,1);

On a related topic, do you know what phrase should be included in a similar expert reference to the 'Stochastic' indicator included with MT4, to require the Close/Close price field be used? It seems to default to low/high.

If you can help it will be appreciated,

- MJ

P.S.- The copy of the DiNapoli Price Detrend indicator code is below.

----------------------------------------

//+------------------------------------------------------------------+

//| DiNapoli Detrend Oscillator.mq4

//| Treberk, www.forex-tsd.com - Conversion only

//+------------------------------------------------------------------+

#property indicator_separate_window

#property indicator_buffers 1

#property indicator_color1 Blue

extern int x_prd=14;

extern int CountBars=300;

//---- buffers

double dpo[];

extern int MAPeriod=7;

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

int init()

{

string short_name;

//---- indicator line

IndicatorBuffers(1);

SetIndexStyle(0,DRAW_LINE);

SetIndexBuffer(0,dpo);

//----

return(0);

}

//+------------------------------------------------------------------+

//| DPO |

//+------------------------------------------------------------------+

int start()

{

if (CountBars>=Bars) CountBars=Bars;

SetIndexDrawBegin(0,Bars-CountBars+x_prd+1);

int i,counted_bars=IndicatorCounted();

//----

if(Bars<=x_prd) return(0);

//---- initial zero

if(counted_bars<x_prd)

{

for(i=1;i<=x_prd;i++) dpo[CountBars-i]=0.0;

}

//----

i=CountBars-x_prd-1;

while(i>=0)

{

dpo=Close-iMA(NULL,0,MAPeriod,MODE_SMA,0,PRICE_CLOSE,i);

i--;

}

return(0);

}

//+------------------------------------------------------------------+

Reason: