# Histogram greater than zero green and less than zero red

Hi, I have this standard deviation indicator. I want the histogram greater than zero to be green and less than zero to be red. I tried but something fails. Can you help me?.
At the end of the code are the 2 plots that I want to indicate this.
Regards

``````_SECTION_BEGIN("Desviaciones estándar");

//DESVIACION STANDARD
desv_est = sqrt( EMA( ( C-Ref(C,-1) )^2, 36 ) ) ;
//sqrt(252)*StDev(ln(C/Ref(C,-1)),21);

//NUMERO DE DESV ESTÁNDAR
numdesv = (C - Ref(C,-1)) / Ref(desv_est,-1);

//PINTAR LAS DESVIACIONES Y LOS LÍMITES DE 2 DESV
GraphXSpace = 10;  //añade espacio para ver los letreros
Plot(numdesv,"NumDesv",colorBlueGrey,styleHistogram|styleThick,Null,Null,0,0,6);
Plot(1,"",colorGreen,styleLine);
Plot(-1,"",colorRed,styleLine);
Plot(2,"",colorGreen,styleLine);
Plot(-2,"",colorRed,styleLine);
//SI PASA DE 2 DESV ANOTAMOS EL VALOR
for( i = 0; i < BarCount; i++ )
{
if( numdesv[i] > 1 )
{
PlotText( NumToStr(numdesv[i],1.2), i-1, numdesv[ i ] + 0.25, colorGreen );
}
else if( numdesv[i] < -1 )
{
PlotText( NumToStr(numdesv[i],1.2), i-2, numdesv[ i ] - 0.75, colorRed );
}

}
Plot(numdesv,"NumDesv", ParamColor("numdesv,"NumDesv >0", colorgreen);
Plot(numdesv,"NumDesv", ParamColor("numdesv,"NumDesv< 0", colorred);

_SECTION_END();

``````

_SECTION_BEGIN("Desviaciones estándar");

//DESVIACION STANDARD
desv_est = sqrt( EMA( ( C-Ref(C,-1) )^2, 36 ) ) ;
//sqrt(252)*StDev(ln(C/Ref(C,-1)),21);

//NUMERO DE DESV ESTÁNDAR
numdesv = (C - Ref(C,-1)) / Ref(desv_est,-1);
colorstyle= IIf(numdesv>0,colorGreen,colorRed);
//PINTAR LAS DESVIACIONES Y LOS LÍMITES DE 2 DESV
GraphXSpace = 10; //añade espacio para ver los letreros
Plot(numdesv,"NumDesv",colorstyle,styleHistogram|styleThick,Null,Null,0,0,6);

Plot(1,"",colorGreen,styleLine);
Plot(-1,"",colorRed,styleLine);
Plot(2,"",colorGreen,styleLine);
Plot(-2,"",colorRed,styleLine);
//SI PASA DE 2 DESV ANOTAMOS EL VALOR
for( i = 0; i < BarCount; i++ )
{
if( numdesv[i] > 1 )
{
PlotText( NumToStr(numdesv[i],1.2), i-1, numdesv[ i ] + 0.25, colorGreen );
}
else if( numdesv[i] < -1 )
{
PlotText( NumToStr(numdesv[i],1.2), i-2, numdesv[ i ] - 0.75, colorRed );
}

}

_SECTION_END();

1 Like

I will review how you did it because I was not able.

See

Hello, I know it is very basic but as I am learning I do not give what happens to the code. I want the histogram if it is above zero to be green and if it is below it to be red
Thanks

``````_SECTION_BEGIN("Desviaciones estándar");
desv_est = sqrt( EMA( ( C-Ref(C,-1) )^2, 36 ) ) ;
//sqrt(252)*StDev(ln(C/Ref(C,-1)),21);

//NUMERO DE DESV ESTÁNDAR
numdesv = (C - Ref(C,-1)) / Ref(desv_est,-1);
//PINTAR LAS DESVIACIONES Y LOS LÍMITES DE 2 DESV
GraphXSpace = 10;  //añade espacio para ver los letreros
Plot(numdesv,"NumDesv",colorBlueGrey,styleHistogram|styleThick,Null,Null,0,0,6);
Plot(1,"",colorGreen,styleLine);
Plot(-1,"",colorRed,styleLine);
Plot(2,"",colorGreen,styleLine);
Plot(-2,"",colorRed,styleLine);
Plot ("ParamColor,Color numdesv > 0", colorgreen);
Plot ("ParamColor,Color numdesv < 0", colorred);
//SI PASA DE 2 DESV ANOTAMOS EL VALOR
for( i = 0; i < BarCount; i++ )
{
if( numdesv[i] > 1 )
{
PlotText( NumToStr(numdesv[i],1.2), i-1, numdesv[ i ] + 0.25, colorGreen );
}
else if( numdesv[i] < -1 )
{
PlotText( NumToStr(numdesv[i],1.2), i-2, numdesv[ i ] - 0.75, colorRed);
}
}
_SECTION_END();

``````

_SECTION_BEGIN("Desviaciones estándar");

//DESVIACION STANDARD
desv_est = sqrt( EMA( ( C-Ref(C,-1) )^2, 36 ) ) ;
//sqrt(252)*StDev(ln(C/Ref(C,-1)),21);

//NUMERO DE DESV ESTÁNDAR
numdesv = (C - Ref(C,-1)) / Ref(desv_est,-1);
colorstyle= IIf(numdesv>0,colorGreen,colorRed);
//PINTAR LAS DESVIACIONES Y LOS LÍMITES DE 2 DESV
GraphXSpace = 10; //añade espacio para ver los letreros
Plot(numdesv,"NumDesv",colorstyle,styleHistogram|styleThick,Null,Null,0,0,6);

Plot(1,"",colorGreen,styleLine);
Plot(-1,"",colorRed,styleLine);
Plot(2,"",colorGreen,styleLine);
Plot(-2,"",colorRed,styleLine);
//SI PASA DE 2 DESV ANOTAMOS EL VALOR
for( i = 0; i < BarCount; i++ )
{
if( numdesv[i] > 1 )
{
PlotText( NumToStr(numdesv[i],1.2), i-1, numdesv[ i ] + 0.25, colorGreen );
}
else if( numdesv[i] < -1 )
{
PlotText( NumToStr(numdesv[i],1.2), i-2, numdesv[ i ] - 0.75, colorRed );
}

}

_SECTION_END();

try to edit your post @VARADAN, You can edit / corect your post in 15min since you post it . so please try to place tags in your code

_SECTION_BEGIN("Desviaciones estándar");

//DESVIACION STANDARD
desv_est = sqrt( EMA( ( C-Ref(C,-1) )^2, 36 ) ) ;
//sqrt(252)*StDev(ln(C/Ref(C,-1)),21);

//NUMERO DE DESV ESTÁNDAR
numdesv = (C - Ref(C,-1)) / Ref(desv_est,-1);
colorstyle= IIf(numdesv>0,colorGreen,colorRed);
//PINTAR LAS DESVIACIONES Y LOS LÍMITES DE 2 DESV
GraphXSpace = 10; //añade espacio para ver los letreros
Plot(numdesv,"NumDesv",colorstyle,styleHistogram|styleThick,Null,Null,0,0,6);

Plot(1,"",colorGreen,styleLine);
Plot(-1,"",colorRed,styleLine);
Plot(2,"",colorGreen,styleLine);
Plot(-2,"",colorRed,styleLine);
//SI PASA DE 2 DESV ANOTAMOS EL VALOR
for( i = 0; i < BarCount; i++ )
{
if( numdesv[i] > 1 )
{
PlotText( NumToStr(numdesv[i],1.2), i-1, numdesv[ i ] + 0.25, colorGreen );
}
else if( numdesv[i] < -1 )
{
PlotText( NumToStr(numdesv[i],1.2), i-2, numdesv[ i ] - 0.75, colorRed );
}

}

_SECTION_END();

@LOL111

you need to use IIF function.

Folow the link there are few exables https://forum.amibroker.com/tags/iif

IIF( EXPRESSION, TRUE_PART, FALSE_PART )

``````// @varadan IIF  style code
colorstyle= IIf(numdesv>0,colorGreen,colorRed);
Plot(numdesv,"NumDesv",colorstyle,styleHistogram|styleThick,Null,Null,0,0,6);
``````

or you can use nested iif with 3 colors

``````colordesv = IIf( numdesv >= 0, colorBlueGrey, IIf( numdesv < 0, colorOrange, colorYellow ) );

``````

or you can use both of them nested or not using paramers Ctrl+P

``````colordesv = IIf( numdesv >= 0, colorBlueGrey, IIf( numdesv < 0, colorOrange, colorYellow ) );
if( ParamToggle( "Colorfull Histogram ?", "No|Yes" ) )
Plot( numdesv, "NumDesv", colordesv, styleHistogram | styleThick, Null, Null, 0, 0, 6 );
else
Plot( numdesv, "NumDesv", colorBlueGrey, styleHistogram | styleThick, Null, Null, 0, 0, 6 );

``````
2 Likes