Help with this code (Kelvinhand I think your the wiz at this)

#1
Bar or candles

1.Bar colour = Green if 5 SMA > 15 SMA AND 5 SMA > 30 SMA.
2.Bar colour = Red if 5 SMA < 15 SMA AND 5 SMA < 30 SMA.
3.Bar colour = Yellow if 5 SMA < 15 SMA AND 5 SMA > 30 SMA OR
5 SMA > 15 SMA AND 5 SMA < 30 SMA.

Thanks In Advance

IsA
 
#2
Hi isa


First thing
KelvinHands time is precious for us on this forum.We will use his help for critical things.

try this.check it.
ford7k

HTML:
SetChartBkColor(64);
MA5 =MA(C,5); 
MA15 =MA(C,15); 
MA30 =MA(C,30);
//add these three code lines for checking
//once checking is done and ok, just put  // before each of these 3 lines.
Plot(MA5," ma5",colorBlue,styleLine);
Plot(MA15," ma15",colorRed,styleLine);
Plot(MA30," ma30",colorCustom12,styleLine);



barcolor =IIf(MA5>MA15 AND MA5>MA30,colorGreen,IIf(MA5<MA15 AND MA5<MA30,colorRed,IIf(MA5>MA15 AND MA5<MA30,colorYellow,colorGrey50)));
Plot(C,"close",barcolor,styleCandle);
//add these if you want bar or line-whatevrrt you want just remove // before that line
//plot(c,"c",barcolor,stylebar);
//plot(c,"c",barcolor,styleline);
dont use all three candle,bar,line at once.
use candle or bar
 
Last edited:
#3
Thanks Ford I think thats it,
Is it possible to have both canle sticks and bars as well as line charts,

In either event that's really great work, thanks again
 
#4
Hi isa


First thing
KelvinHands time is precious for us on this forum.We will use his help for critical things.

try this.check it.
ford7k

HTML:
SetChartBkColor(64);
MA5 =MA(C,5); 
MA15 =MA(C,15); 
MA30 =MA(C,30);
//add these three code lines for checking
//once checking is done and ok, just put  // before each of these 3 lines.
Plot(MA5," ma5",colorBlue,styleLine);
Plot(MA15," ma15",colorRed,styleLine);
Plot(MA30," ma30",colorCustom12,styleLine);



barcolor =IIf(MA5>MA15 AND MA5>MA30,colorGreen,IIf(MA5<MA15 AND MA5<MA30,colorRed,IIf(MA5>MA15 AND MA5<MA30,colorYellow,colorGrey50)));
Plot(C,"close",barcolor,styleCandle);
//add these if you want bar or line-whatevrrt you want just remove // before that line
//plot(c,"c",barcolor,stylebar);
//plot(c,"c",barcolor,styleline);

Ok lemme check gimme bout 10 mins
 
#5
Ford this line of code seems to b a lil out
IIf(MA5>MA15 AND MA5<MA30,colorYellow,colorGrey50)));

it should be
Bar colour = Yellow if 5 SMA < 15 SMA AND 5 SMA > 30 SMA OR ( this second part is imp )
5 SMA > 15 SMA AND 5 SMA < 30 SMA.

Pse change
 
Last edited:

extremist

Well-Known Member
#6
plz change the line :

Plot(C,"close",barcolor,styleCandle);

with following line.

PlotOHLC(O,H,L,C,"", colorBlack, ParamStyle("Price style",styleCandle,maskPrice));


_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} \n Op=> %g, \n Hi=> %g, \n Lo=> %g, \n Cl=> %g \n
{{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

u will get better view of chart and u can also change the style of graph frm parameter.
 
#7
plz change the line :

Plot(C,"close",barcolor,styleCandle);

with following line.

PlotOHLC(O,H,L,C,"", colorBlack, ParamStyle("Price style",styleCandle,maskPrice));


_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} \n Op=> %g, \n Hi=> %g, \n Lo=> %g, \n Cl=> %g \n
{{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

u will get better view of chart and u can also change the style of graph frm parameter.

Dosent have the desired effect of color changing
 
#8
HI ISA

barcolor =IIf(MA5>MA15 AND MA5>MA30,colorGreen,IIf(MA5<MA15 AND MA5<MA30,colorRed,colorYellow));

IS ENOUGH


BOTH UP, BOTH DOWN,ANYTHING OTHER THAN THESE TWO
CONDITION IS OK
once first two condition are defined, yellow comes automatically no need to define it.
Dont worry.it is ok
 

KelvinHand

Well-Known Member
#10
Hey Guys,
Can any one help me out codeing this;-

1.Bar colour = Green if 5 SMA > 15 SMA AND 5 SMA > 30 SMA.
2.Bar colour = Red if 5 SMA < 15 SMA AND 5 SMA < 30 SMA.
3.Bar colour = Yellow if 5 SMA < 15 SMA AND 5 SMA > 30 SMA OR
5 SMA > 15 SMA AND 5 SMA < 30 SMA.

Oh ya the option of line, candle or OHLC should be available .
Thank ya all

IsA
It happen that i got this Price Chart.
So I combine the works from above guys that had help you.

I know you will love it. Don't ask me anymore.:hug:


PHP:
//-- Author : KelvinHand
//bgTop = ParamColor("BgTop",    colorBlack);
//bgBot = ParamColor("BgBottom", colorBlack);
//SetChartBkGradientFill( bgTop ,bgBot);

pStyle = ParamList("Style.Price", "Candle|Solid Candle|Bar|Line|None");

cBull = ParamColor("Color.Bull", colorLime);
CBear = ParamColor("Color.Bear", colorRed);
CChaos = ParamColor("Color.Chaos", colorYellow);
cLine = ParamColor("Color.Line", colorGrey50);

ShowMAs = ParamToggle("Show MAs", "No|Yes");


SetChartOptions(0,chartShowArrows|chartShowDates|chartWrapTitle );
_N(Title = StrFormat("{{NAME}}- {{INTERVAL}} {{DATE}} O= %g, H= %g, L= %g, C= %g (%.1f%%) V= " +WriteVal( V, 1.0 ) +"\n{{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));

ThisStyle = styleCandle;
ThisTitle = "";

_O=O; _C=C; _H=H; _L=L;


	MA5  = MA(C,5); 
	MA15 = MA(C,15); 
	MA30 = MA(C,30);

	Cond_1 = MA5>MA15 AND MA5>MA30;
	Cond_2 = MA5<MA15 AND MA5<MA30;
	Cond_3 = MA5<MA15 AND MA5>MA30 OR MA5 > MA15 AND MA5 < MA30;

	ThisColor = IIf (Cond_1,  cBull,
			 		IIf (Cond_2,  CBear,
			 		IIf (Cond_3,  CChaos,  
						cLine)));

switch (pStyle )
{

  case "Solid Candle":   
        SetBarFillColor( ThisColor ); 
        break;


  case "Bar": 
       ThisStyle = styleBar;
       break;

  case "Line": 
      ThisStyle = styleLine;
       break;


  case "None":
       break;

  default:   
        SetBarFillColor( ThisColor ); 
        ThisColor = cLine;

       break;

}

  if (pStyle !="None")
  PlotOHLC( _O, _H, _L, _C, ThisTitle, ThisColor, ThisStyle); 
 
  GraphXSpace = 8;



if (ShowMAs)
{
	Plot(MA5,"ma5",colorYellow,styleNoLabel);
	Plot(MA15,"ma15",colorRed,styleNoLabel);
	Plot(MA30,"ma30",colorAqua,styleNoLabel);

}
 
Last edited:

Similar threads

Broker Special Offers

Intraday Higher Leverage

Save up to 90% in brokerage and get higher leverage for intraday trades.

Name:Phone:
Email:City:
State:
Are you a day trader?