Plot Color not changing

Hi,

I have been trying to plot camrilla pivots, however, when I use PlotOHLC (I want line breaks), I can only plot in red color, despite giving green color. Can you help

_SECTION_BEGIN("Camrilla Pivots");
_N(DropBox=ParamList("Time","D|W|M"));

if(DropBox=="D")
{
DayH = TimeFrameGetPrice( "H", inDaily,-1 );
DayL = TimeFrameGetPrice( "L", inDaily,-1 );
DayC = TimeFrameGetPrice( "C", inDaily,-1 );
}
else if (DropBox=="W")
{
DayH = TimeFrameGetPrice( "H",inWeekly,-1 );
DayL= TimeFrameGetPrice( "L",inWeekly,-1 );
DayC = TimeFrameGetPrice( "C",inWeekly,-1 );
}

else if (DropBox=="M")
{
DayH = TimeFrameGetPrice( "H",inMonthly,-1 );
DayL= TimeFrameGetPrice( "L",inMonthly,-1 );
DayC = TimeFrameGetPrice( "C",inMonthly,-1 );
}

//............Camarilla pivots

H5 = ( DayH / DayL ) * DayC;
H4 = ( (DayH-DayL) * (1.1/2) ) + DayC;
H3 = ( (DayH-DayL) * (1.1/4) ) + DayC;
H2 = ( (DayH-DayL) * (1.1/6) ) + DayC;
H1 = ( (DayH-DayL) * (1.1/12) ) + DayC;

L1 = DayC - ( (DayH-DayL) * (1.1/12) );
L2 = DayC - ( (DayH-DayL) * (1.1/6) ) ;
L3 = DayC - ( (DayH-DayL) * (1.1/4) ) ;
L4 = DayC - ( (DayH-DayL) * (1.1/2) ) ;
L5 = DayC - ( H5 - DayC );

	
//PlotOHLC(H4,H4,H4,H4,"H4",colorBlue, styleCandle | styleNoLabel | styleNoTitle);
	
	
PlotOHLC(H4,H4,H4,H4,"H4",colorBrightGreen,styleCandle | styleNoLabel | styleNoTitle);


_SECTION_BEGIN("Price1");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();

Screenshot 2020-09-12 022605

No, you are not correct.
You can plot with green color.
And it does plot with green color.

14

(If that's the entire code in post #1 then) you have UI setting that causes that. And I know which one it is (but as aside you do not need to use styleBar at all in order to have no connection between periods (Day, Week, Month) anyway).

There are three solutions:

  1. setting different UI setting
  2. or not using styleBar
  3. or using your UI setting but adding an additional line

But for further help you have to validate forum account first.

thanks @fxshrat for you promt response. I am still a bit lost here.

Can you guide me with all the three steps

  1. What UI settings am I use or should I use ?
  2. I picked up with Plot OHLC from some post in the forum- I dont see stylebar in my code
  3. what is additional line I can add?

Thanks in advance and sorry for any silly questions.

@fxshrat - okay, I did a bit of playing around and figured out the UI issue. Can you help understand more the other 2 solutions you suggested. thanks

Screenshot 2020-09-12 032558

It was typo. I meant styleCandle in your code. But it relates to styleBar too.
You do not need styleBar, styleCandle.

In case of styleCandle it is SetBarFillColor() function.
If you add that one then you can keep your original UI setting.


Also this one is way too much code.

_N(DropBox=ParamList("Time","D|W|M"));

if(DropBox=="D")
{
DayH = TimeFrameGetPrice( "H", inDaily,-1 );
DayL = TimeFrameGetPrice( "L", inDaily,-1 );
DayC = TimeFrameGetPrice( "C", inDaily,-1 );
}
else if (DropBox=="W")
{
DayH = TimeFrameGetPrice( "H",inWeekly,-1 );
DayL= TimeFrameGetPrice( "L",inWeekly,-1 );
DayC = TimeFrameGetPrice( "C",inWeekly,-1 );
}

else if (DropBox=="M")
{
DayH = TimeFrameGetPrice( "H",inMonthly,-1 );
DayL= TimeFrameGetPrice( "L",inMonthly,-1 );
DayC = TimeFrameGetPrice( "C",inMonthly,-1 );
}

Instead you just need 4...5 lines.

_N(DropBox=ParamList("Time","inDaily|inWeekly|inMonthly"));

tmfrm = VarGet(DropBox);
DayH = TimeFrameGetPrice( "H",tmfrm,-1 );
DayL= TimeFrameGetPrice( "L",tmfrm,-1 );
DayC = TimeFrameGetPrice( "C",tmfrm,-1 );
1 Like

Here is full code for Camarilla all levels.

_SECTION_BEGIN("Camarilla Pivots");
/// @link https://forum.amibroker.com/t/plot-color-not-changing/21352/6
tmfrm = VarGet(ParamList("Time","inDaily|inWeekly|inMonthly"));
DayH = TimeFrameGetPrice( "H",tmfrm,-1 );
DayL = TimeFrameGetPrice( "L",tmfrm,-1 );
DayC = TimeFrameGetPrice( "C",tmfrm,-1 );

mat = MxFromString("[12;6;4;2]");
range = DayH-DayL;
for ( i = 1; i <= 4; i++ ) {
	adj_range = range * 1.1/mat[i-1][0];
	VarSet("H"+i, DayC + adj_range);
	VarSet("L"+i, DayC - adj_range);
}
H5 = DayH / DayL * DayC;
L5 = 2*DayC - H5;

dn = DateNum();
newday = dn != Ref( dn, -1);
style = styleStaircase | styleDashed | styleNoLabel | styleNoTitle | styleNoRescale;
for ( i = 1; i <= 5; i++ ) {
	_H = VarGet("H"+i); _L = VarGet("L"+i);
	Plot(IIf(newday, Null, _H),"H"+i,colorBrightGreen, style );
	Plot(IIf(newday, Null, _H),"H"+i,colorBrightGreen, style, Null, Null, -1 );
	Plot(IIf(newday, Null, _L),"L"+i,colorRed, style );
	Plot(IIf(newday, Null, _L),"L"+i,colorRed, style, Null, Null, -1 );
}
_SECTION_END();

14

3 Likes

Thank you @fxshrat. What you have done to my code feels like magic :slight_smile: . However, in the interest of learning, I will not use till such time I know every detail of the code you have written. Thank for helping!

You need to understand that candles have MORE than one color.

There is an outline color, (wick) shadow colors and body fill color. That's three colors, not one. The interior of candle (body) is changed via SetBarFillColor() function. Plot() argument changes outline color but only when distinct colors are defined in preferences. Overall, the way how candles look depends also on Preferences settings:

image

thanks @Tomasz- noted. there is lot of information overload for a newbiew here :slight_smile: thanks again

Here is small code update as I forgot to add week and month flags.
Also added ParamStyle.

_SECTION_BEGIN("Camarilla Pivots");
/// @link https://forum.amibroker.com/t/plot-color-not-changing/21352/10
/// by fxshrat@gmail.com
tmfrm = VarGet(ParamList("Pivot TimeFrame","inDaily|inWeekly|inMonthly"));
DayH = TimeFrameGetPrice( "H",tmfrm,-1 );
DayL = TimeFrameGetPrice( "L",tmfrm,-1 );
DayC = TimeFrameGetPrice( "C",tmfrm,-1 );

mat = MxFromString("[12;6;4;2]");
range = DayH-DayL;
for ( i = 1; i <= 4; i++ ) {
	adj_range = range * 1.1/mat[i-1][0];
	VarSet("H"+i, DayC + adj_range);
	VarSet("L"+i, DayC - adj_range);
}
H5 = DayH / DayL * DayC;
L5 = 2*DayC - H5;

eod = DateNum()*(tmfrm==inDaily) +
      DayOfWeek()*(tmfrm==inWeekly) +
      Month()*(tmfrm==inMonthly);
if ( tmfrm == inWeekly )	flag = eod < Ref(eod, -1);
else						flag = eod != Ref(eod, -1);
style = ParamStyle("Pivot Line Style", styleDashed | styleNoLabel | styleNoRescale);
style = style | styleStaircase | styleNoTitle;
for ( i = 1; i <= 5; i++ ) {
	_H = VarGet("H"+i); _L = VarGet("L"+i);
	Plot(IIf(flag, Null, _H),"H"+i,colorBrightGreen, style );
	Plot(IIf(flag, Null, _H),"H"+i,colorBrightGreen, style, Null, Null, -1 );
	Plot(IIf(flag, Null, _L),"L"+i,colorRed, style );
	Plot(IIf(flag, Null, _L),"L"+i,colorRed, style, Null, Null, -1 );
}
_SECTION_END();

8

2 Likes

image

seems to give me this error on the screen. I read about the matrix function you used- wasn't not able to decode what it really does ?

The code runs just fine and does not return error!
MxFromString() is a function implemented in AmiBroker 6.10.
So you need minimum that version to run the code.
Most recent public versions are 6.30 final release and 6.35.1 "beta" release.

Why do you use old AmiBroker version if you are new(bie)? It does not make any sense to me.
Simply install proper version then code will run. Period.

1 Like

ah got it! Yeah my data providers is compatible with 6.0 :frowning: and not higher versions.

What your "data provider" says is plain false. ADK (the programming interface) for data plugins DID NOT change for 10+ years and did NOT change in 6.10, 6.20 or 6.30. When new features are introduced, new versions are backward compatible (to maximum possible extent).

So I call it BS.

3 Likes

@Tomasz thanks for letting me know. Let me call out his BS tomorrow morning!

okay. So, I finally have the 6.35 version and works like a charm!

1 Like

so this code is working, however, I have been struggling to understand how the code works. I need to add a lot of customisation but cant till the time, I get hang of this.

can you point me to some reading material on the structure and functions u have used?

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.