Lines and scales  [SOLVED]

Questions about MultiCharts and user contributed studies.
User avatar
arnie
Posts: 1594
Joined: 11 Feb 2009
Location: Portugal
Has thanked: 481 times
Been thanked: 514 times

Lines and scales

Postby arnie » 07 Jan 2014

Since we cannot send to back trendlines, only lines, I wrote the most basic study to plot some levels on a footprint chart so I can send them to back.

Code: Select all

inputs:
OnHigh (0),
OnLow (0),
PrevHigh (0),
PrevLow (0),
PrevCls (0),
TodayOpen (0);

plot1(OnHigh,"ONhi");
plot2(OnLow,"ONlo");
plot3(PrevHigh,"PREVhi");
plot4(PrevLow,"PREVlo");
plot5(PrevCls,"PREVcls");
plot6(TodayOpen,"OP");
The result is this:

Image

Question: Is it possible to extend these lines to the right?


Now a problem on how the scale is set.
For these lines to be perfectly aligned with prices, we need to set them an the Same as Instrument. No problem here.

The problem, and this does not happen with trendlines, is that when we set them to be the same as the instrument MC assumes that the lines are more important than price bars and end up compressing the bars so the lines be all visible on the chart.
Though on price bars this might not be a big issue, on footprint charts we get the worst possible result.
Compare the chart below with the above.
On the above chart I was forced to manually adjust the scale so I can have the footprint bars with a visible size but on the chart below MC compress the bars so the lowest line could be visible, at 1817.25 which was yesterday's pit low. Now imagine if the low was at 1810. In no way we could see any text on the bars. We would be forced to manually adjust the scale which becomes very annoying after a while.

We need an option that while lines be set as the instrument, the chart should be focused on the price bars and not on the lines.
Basically, lines should act the same way as trendlines.


Image
Attachments
foot02.jpg
(298.66 KiB) Downloaded 881 times
foot01.jpg
(308 KiB) Downloaded 851 times

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Lines and scales

Postby TJ » 07 Jan 2014

::
Question: Is it possible to extend these lines to the right?
::
try this:

Code: Select all

For value1 = 0 to 10
begin
plot1[-value1](OnHigh,"ONhi");
end;

User avatar
arnie
Posts: 1594
Joined: 11 Feb 2009
Location: Portugal
Has thanked: 481 times
Been thanked: 514 times

Re: Lines and scales

Postby arnie » 08 Jan 2014

Many thanks TJ.

SP
Posts: 465
Joined: 06 Feb 2006
Has thanked: 36 times
Been thanked: 286 times

Re: Lines and scales  [SOLVED]

Postby SP » 08 Jan 2014

We need an option that while lines be set as the instrument, the chart should be focused on the price bars and not on the lines.
Basically, lines should act the same way as trendlines.
arnie,

did you uncheck under Format Instrument -> Scaling -> General -> Expand Scale to Indicators ?

User avatar
arnie
Posts: 1594
Joined: 11 Feb 2009
Location: Portugal
Has thanked: 481 times
Been thanked: 514 times

Re: Lines and scales

Postby arnie » 08 Jan 2014

arnie,

did you uncheck under Format Instrument -> Scaling -> General -> Expand Scale to Indicators ?
WOW!

I never noticed this option before.
Shame on me.

Many thanks SP.

User avatar
arnie
Posts: 1594
Joined: 11 Feb 2009
Location: Portugal
Has thanked: 481 times
Been thanked: 514 times

Re: Lines and scales

Postby arnie » 08 Jan 2014

Final result:

Image

Simple and effective.

Code: Select all

inputs:
OnHigh (0),
OnLow (0),
OnColor (rgb(227,168,105)),
PrevHigh (0),
PrevLow (0),
PrevColor (darkcyan),
PrevCls (0),
CloseColor (magenta),
TodayOpen (0),
OpenColor (red),
ShowLabels (false),
LabelFont ("Consolas"),
FontSize (9),
ShiftText (0),
ShiftLinesRight (0);

Variables:
OnHighTXT (0),
OnLowTXT (0),
PrevHighTXT (0),
PrevLowTXT (0),
PrevClsTXT (0),
TodayOpenTXT (0);

if currentbar = 1 then begin
If ShowLabels = true then begin
OnHighTXT = text_new_dt(datetime, OnHigh, "");
text_setfontname(OnHighTXT, LabelFont);
text_setsize(OnHighTXT, FontSize);
text_setcolor(OnHighTXT, OnColor);
text_setstyle(OnHighTXT, 0, 2);
text_lock(OnHighTXT, true);
OnLowTXT = text_new_dt(datetime, OnLow, "");
text_setfontname(OnLowTXT, LabelFont);
text_setsize(OnLowTXT, FontSize);
text_setcolor(OnLowTXT, OnColor);
text_setstyle(OnLowTXT, 0, 2);
text_lock(OnLowTXT, true);
PrevHighTXT = text_new_dt(datetime, PrevHigh, "");
text_setfontname(PrevHighTXT, LabelFont);
text_setsize(PrevHighTXT, FontSize);
text_setcolor(PrevHighTXT, PrevColor);
text_setstyle(PrevHighTXT, 0, 2);
text_lock(PrevHighTXT, true);
PrevLowTXT = text_new_dt(datetime, PrevLow, "");
text_setfontname(PrevLowTXT, LabelFont);
text_setsize(PrevLowTXT, FontSize);
text_setcolor(PrevLowTXT, PrevColor);
text_setstyle(PrevLowTXT, 0, 2);
text_lock(PrevLowTXT, true);
PrevClsTXT = text_new_dt(datetime, PrevCls, "");
text_setfontname(PrevClsTXT, LabelFont);
text_setsize(PrevClsTXT, FontSize);
text_setcolor(PrevClsTXT, CloseColor);
text_setstyle(PrevClsTXT, 0, 2);
text_lock(PrevClsTXT, true);
TodayOpenTXT = text_new_dt(datetime, TodayOpen, "");
text_setfontname(TodayOpenTXT, LabelFont);
text_setsize(TodayOpenTXT, FontSize);
text_setcolor(TodayOpenTXT, OpenColor);
text_setstyle(TodayOpenTXT, 0, 2);
text_lock(TodayOpenTXT, true);
end;
end;

text_setstring(OnHighTXT, spaces(ShiftText) + text(" - OnHi"));
text_setlocation_dt(OnHighTXT, datetime, OnHigh);

text_setstring(OnLowTXT, spaces(ShiftText) + text(" - OnLo"));
text_setlocation_dt(OnLowTXT, datetime, OnLow);

text_setstring(PrevHighTXT, spaces(ShiftText) + text(" - PrevHi"));
text_setlocation_dt(PrevHighTXT, datetime, PrevHigh);

text_setstring(PrevLowTXT, spaces(ShiftText) + text(" - PrevLo"));
text_setlocation_dt(PrevLowTXT, datetime, PrevLow);

text_setstring(PrevClsTXT, spaces(ShiftText) + text(" - PrevCls"));
text_setlocation_dt(PrevClsTXT, datetime, PrevCls);

text_setstring(TodayOpenTXT, spaces(ShiftText) + text(" - TodayOp"));
text_setlocation_dt(TodayOpenTXT, datetime, TodayOpen);

for value1 = 0 to ShiftLinesRight begin
plot1[-value1](OnHigh,"ONhi", OnColor);
plot2[-value1](OnLow,"ONlo", OnColor);
plot3[-value1](PrevHigh,"PREVhi", PrevColor);
plot4[-value1](PrevLow,"PREVlo", PrevColor);
plot5[-value1](PrevCls,"PREVcls", CloseColor);
plot6[-value1](TodayOpen,"TodayOpen", OpenColor);
end;
Attachments
foot_lines.jpg
(504.32 KiB) Downloaded 836 times
Last edited by arnie on 08 Jan 2014, edited 1 time in total.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Lines and scales

Postby TJ » 08 Jan 2014

Arnie: As always, thanks for sharing your hard work.

User avatar
arnie
Posts: 1594
Joined: 11 Feb 2009
Location: Portugal
Has thanked: 481 times
Been thanked: 514 times

Re: Lines and scales

Postby arnie » 08 Jan 2014

Here's something I like to do with labels.

When two prices are identical, I like to plot one label in front of the other for better reading.

Image

Code: Select all

inputs:
OnHigh (0),
OnLow (0),
OnColor (rgb(227,168,105)),
PrevHigh (0),
PrevLow (0),
PrevColor (darkcyan),
PrevCls (0),
CloseColor (magenta),
TodayOpen (0),
OpenColor (red),
ShowLabels (false),
LabelFont ("Consolas"),
FontSize (9),
ShiftText (0),
ShiftLinesRight (0);

Variables:
OnHighTXT (0),
OnLowTXT (0),
PrevHighTXT (0),
PrevLowTXT (0),
PrevClsTXT (0),
TodayOpenTXT (0);

if currentbar = 1 then begin
If ShowLabels = true then begin
OnHighTXT = text_new_dt(datetime, OnHigh, "");
text_setfontname(OnHighTXT, LabelFont);
text_setsize(OnHighTXT, FontSize);
text_setcolor(OnHighTXT, OnColor);
text_setstyle(OnHighTXT, 0, 2);
text_lock(OnHighTXT, true);
OnLowTXT = text_new_dt(datetime, OnLow, "");
text_setfontname(OnLowTXT, LabelFont);
text_setsize(OnLowTXT, FontSize);
text_setcolor(OnLowTXT, OnColor);
text_setstyle(OnLowTXT, 0, 2);
text_lock(OnLowTXT, true);
PrevHighTXT = text_new_dt(datetime, PrevHigh, "");
text_setfontname(PrevHighTXT, LabelFont);
text_setsize(PrevHighTXT, FontSize);
text_setcolor(PrevHighTXT, PrevColor);
text_setstyle(PrevHighTXT, 0, 2);
text_lock(PrevHighTXT, true);
PrevLowTXT = text_new_dt(datetime, PrevLow, "");
text_setfontname(PrevLowTXT, LabelFont);
text_setsize(PrevLowTXT, FontSize);
text_setcolor(PrevLowTXT, PrevColor);
text_setstyle(PrevLowTXT, 0, 2);
text_lock(PrevLowTXT, true);
PrevClsTXT = text_new_dt(datetime, PrevCls, "");
text_setfontname(PrevClsTXT, LabelFont);
text_setsize(PrevClsTXT, FontSize);
text_setcolor(PrevClsTXT, CloseColor);
text_setstyle(PrevClsTXT, 0, 2);
text_lock(PrevClsTXT, true);
TodayOpenTXT = text_new_dt(datetime, TodayOpen, "");
text_setfontname(TodayOpenTXT, LabelFont);
text_setsize(TodayOpenTXT, FontSize);
text_setcolor(TodayOpenTXT, OpenColor);
text_setstyle(TodayOpenTXT, 0, 2);
text_lock(TodayOpenTXT, true);
end;
end;

text_setstring(OnHighTXT, spaces(ShiftText) + text(" - OnHi"));
text_setstring(OnLowTXT, spaces(ShiftText) + text(" - OnLo"));

if (PrevHigh = OnHigh ) or (PrevHigh = OnLow ) then
text_setstring(PrevHighTXT, spaces(ShiftText + 7) + text(" - PrevHi"))
else
text_setstring(PrevHighTXT, spaces(ShiftText) + text(" - PrevHi"));

if (PrevLow = OnHigh ) or (PrevLow = OnLow ) then
text_setstring(PrevLowTXT, spaces(ShiftText + 7) + text(" - PrevLo"))
else
text_setstring(PrevLowTXT, spaces(ShiftText) + text(" - PrevLo"));

if (PrevCls = PrevHigh) or (PrevCls = PrevLow) or (PrevCls = OnHigh ) or (PrevCls = OnLow ) then
text_setstring(PrevClsTXT, spaces(ShiftText + 7) + text(" - PrevCls"))
else
text_setstring(PrevClsTXT, spaces(ShiftText) + text(" - PrevCls"));

if (TodayOpen = PrevHigh) or (TodayOpen = PrevLow) or (TodayOpen = OnHigh ) or (TodayOpen = OnLow ) or (TodayOpen = PrevCls) then
text_setstring(TodayOpenTXT, spaces(ShiftText + 7) + text(" - TodayOp"))
else
text_setstring(TodayOpenTXT, spaces(ShiftText) + text(" - TodayOp"));

text_setlocation_dt(OnHighTXT, datetime, OnHigh);
text_setlocation_dt(OnLowTXT, datetime, OnLow);
text_setlocation_dt(PrevHighTXT, datetime, PrevHigh);
text_setlocation_dt(PrevLowTXT, datetime, PrevLow);
text_setlocation_dt(PrevClsTXT, datetime, PrevCls);
text_setlocation_dt(TodayOpenTXT, datetime, TodayOpen);

for value1 = 0 to ShiftLinesRight begin
plot1[-value1](OnHigh,"ONhi", OnColor);
plot2[-value1](OnLow,"ONlo", OnColor);
plot3[-value1](PrevHigh,"PREVhi", PrevColor);
plot4[-value1](PrevLow,"PREVlo", PrevColor);
plot5[-value1](PrevCls,"PREVcls", CloseColor);
plot6[-value1](TodayOpen,"TodayOpen", OpenColor);
end;
Attachments
foot_lines02.jpg
(111.17 KiB) Downloaded 827 times

User avatar
arnie
Posts: 1594
Joined: 11 Feb 2009
Location: Portugal
Has thanked: 481 times
Been thanked: 514 times

Re: Lines and scales

Postby arnie » 21 Jan 2014

Here's another update.

We now don't need to manually write the prices in the inputs.
Previous day high and low, previous day close, today open and today close are all now plotted automatically.

The only problem is still the overnight high and low.
In this version we still need to write it manually.

I've been testing with two data series but I'm having a couple of problems.
I requested help here viewtopic.php?f=5&t=46014

Here is the update.
Today high and low is commented because I don't need those lines to be on the chart.

Code: Select all

// This plots the previous day high, low, open, and close via lines and not trendlines
// 21-01-2014
// http://www.multicharts.com/discussion/viewtopic.php?f=1&t=45945

// written to be used with footprint charts so we can bring to front the footprint bars so the lines stay behind

Inputs:
ShowLabels (false),
ShiftLabels (0),
ShiftLinesRight (0),
LabelFont ("consolas"),
FontSize (8),
PlotOnHilo (true),
OnColor (rgb(227,168,105)),
OnHigh (0),
OnLow (0),
PlotPrevHiLo (true),
PrevHiloColor (darkcyan),
PlotPrevClose (true),
CloseColor (magenta),
PlotOpen (true),
OpenColor (red),
//PlotHilo (false),
//HiloColor (yellow),
PlotMidpoint (true),
MidpointColor (rgb(255,104,32));

Variables:
DailyHi (-999999),
DailyLo (+999999),
CurrentSess (0),
DailyOp (0),
DailyCl (0),
DailyMid (0),
prevDayHi (0),
prevDayLo (0),
prevDayOp (0),
prevDayCl (0),
OnHighTXT (-1),
OnLowTXT (-1),
PrevHighTXT (-1),
PrevLowTXT (-1),
PrevClsTXT (-1),
TodayOpenTXT (-1),
TodayHighTXT (-1),
TodayLowTXT (-1),
TodayMidTXT (-1);


if CurrentBar = 1 then begin
// Plot values as text
If ShowLabels = true then begin
if PlotOnHilo = true then begin
OnHighTXT = text_new_dt(datetime, OnHigh, "");
text_setfontname(OnHighTXT, LabelFont);
text_setsize(OnHighTXT, FontSize);
text_setcolor(OnHighTXT, OnColor);
text_setstyle(OnHighTXT, 0, 2);
text_lock(OnHighTXT, true);
OnLowTXT = text_new_dt(datetime, OnLow, "");
text_setfontname(OnLowTXT, LabelFont);
text_setsize(OnLowTXT, FontSize);
text_setcolor(OnLowTXT, OnColor);
text_setstyle(OnLowTXT, 0, 2);
text_lock(OnLowTXT, true);
end;
if PlotPrevHiLo = true then begin
PrevHighTXT = text_new_dt(datetime, PrevDayHi, "");
text_setfontname(PrevHighTXT, LabelFont);
text_setsize(PrevHighTXT, FontSize);
text_setcolor(PrevHighTXT, PrevHiloColor);
text_setstyle(PrevHighTXT, 0, 2);
text_lock(PrevHighTXT, true);
PrevLowTXT = text_new_dt(datetime, PrevDayLo, "");
text_setfontname(PrevLowTXT, LabelFont);
text_setsize(PrevLowTXT, FontSize);
text_setcolor(PrevLowTXT, PrevHiloColor);
text_setstyle(PrevLowTXT, 0, 2);
text_lock(PrevLowTXT, true);
end;
if PlotPrevClose = true then begin
PrevClsTXT = text_new_dt(datetime, PrevDayCl, "");
text_setfontname(PrevClsTXT, LabelFont);
text_setsize(PrevClsTXT, FontSize);
text_setcolor(PrevClsTXT, CloseColor);
text_setstyle(PrevClsTXT, 0, 2);
text_lock(PrevClsTXT, true);
end;
if PlotOpen = true then begin
TodayOpenTXT = text_new_dt(datetime, DailyOp, "");
text_setfontname(TodayOpenTXT, LabelFont);
text_setsize(TodayOpenTXT, FontSize);
text_setcolor(TodayOpenTXT, OpenColor);
text_setstyle(TodayOpenTXT, 0, 2);
text_lock(TodayOpenTXT, true);
end;
{if PlotHilo = true then begin
TodayHighTXT = text_new_dt(datetime, DailyHi, "");
text_setfontname(TodayHighTXT, LabelFont);
text_setsize(TodayHighTXT, FontSize);
text_setcolor(TodayHighTXT, HiloColor);
text_setstyle(TodayHighTXT, 0, 2);
text_lock(TodayHighTXT, true);
TodayLowTXT = text_new_dt(datetime, DailyLo, "");
text_setfontname(TodayLowTXT, LabelFont);
text_setsize(TodayLowTXT, FontSize);
text_setcolor(TodayLowTXT, HiloColor);
text_setstyle(TodayLowTXT, 0, 2);
text_lock(TodayLowTXT, true);
end;}
if PlotMidpoint = true then begin
TodayMidTXT = text_new_dt(datetime, DailyMid, "");
text_setfontname(TodayMidTXT, LabelFont);
text_setsize(TodayMidTXT, FontSize);
text_setcolor(TodayMidTXT, MidpointColor);
text_setstyle(TodayMidTXT, 0, 2);
text_lock(TodayMidTXT, true);
end;
end;
end;

//track the current session
CurrentSess = CurrentSession(0) ;

//we have a session change
if CurrentSess <> CurrentSess[1] then
begin
prevDayOp = DailyOp;
prevDayCl = DailyCl;
DailyOp = Open;

if DailyHi <> -999999 then
prevDayHi = DailyHi;
if DailyLo <> +999999 then
prevDayLo = DailyLo;
DailyHi = -999999;
DailyLo = +999999;
end;

DailyCl = Close;

if High > DailyHi then
DailyHi = High;
if Low < DailyLo then
DailyLo = Low;

DailyMid = (DailyHi + DailyLo) * 0.5;

text_setstring(OnHighTXT, spaces(ShiftLabels) + text(" - OnHi"));
text_setstring(OnLowTXT, spaces(ShiftLabels) + text(" - OnLo"));

if (PrevDayHi = OnHigh ) or (PrevDayHi = OnLow ) then
text_setstring(PrevHighTXT, spaces(ShiftLabels + 9) + text(" - PrevHi"))
else
text_setstring(PrevHighTXT, spaces(ShiftLabels) + text(" - PrevHi"));

if (PrevDayLo = OnHigh ) or (PrevDayLo = OnLow ) then
text_setstring(PrevLowTXT, spaces(ShiftLabels + 9) + text(" - PrevLo"))
else
text_setstring(PrevLowTXT, spaces(ShiftLabels) + text(" - PrevLo"));

if (PrevDayCl = PrevDayHi) or (PrevDayCl = PrevDayLo) or (PrevDayCl = OnHigh ) or (PrevDayCl = OnLow ) then
text_setstring(PrevClsTXT, spaces(ShiftLabels + 9) + text(" - PrevCls"))
else
text_setstring(PrevClsTXT, spaces(ShiftLabels) + text(" - PrevCls"));

if (DailyOp = PrevDayHi) or (DailyOp = PrevDayLo) or (DailyOp = OnHigh ) or (DailyOp = OnLow ) or (DailyOp = PrevDayCl) then
text_setstring(TodayOpenTXT, spaces(ShiftLabels + 9) + text(" - Open"))
else
text_setstring(TodayOpenTXT, spaces(ShiftLabels) + text(" - Open"));

if (DailyMid = PrevDayHi) or (DailyMid = PrevDayLo) or (DailyMid = OnHigh ) or (DailyMid = OnLow ) or (DailyMid = PrevDayCl) or (DailyMid = DailyOp) then
text_setstring(TodayMidTXT, spaces(ShiftLabels + 9) + text(" - Mid"))
else
text_setstring(TodayMidTXT, spaces(ShiftLabels) + text(" - Mid"));

text_setlocation_dt(OnHighTXT, datetime, OnHigh);
text_setlocation_dt(OnLowTXT, datetime, OnLow);
text_setlocation_dt(PrevHighTXT, datetime, PrevDayHi);
text_setlocation_dt(PrevLowTXT, datetime, PrevDayLo);
text_setlocation_dt(PrevClsTXT, datetime, PrevDayCl);
text_setlocation_dt(TodayOpenTXT, datetime, DailyOp);
text_setlocation_dt(TodayMidTXT, datetime, DailyMid);
//text_setlocation_dt(TodayHighTXT, datetime, DailyHi);
//text_setlocation_dt(TodayLowTXT, datetime, DailyLo);

for value1 = 0 to ShiftLinesRight begin
if PlotOnHilo = true then begin
if onhigh <> 0 then
plot1[-value1](onhigh,"ONhi", oncolor);
if onlow <> 0 then
plot2[-value1](onlow,"ONlow", oncolor);
end;
if PlotPrevHiLo = true then begin
if prevDayHi <> 0 then
plot3[-value1](PrevDayHi,"PREVhi", prevhilocolor);
if prevDayLo <> 0 then
plot4[-value1](PrevDayLo,"PREVlo", prevhilocolor);
end;
if PlotPrevClose = true then begin
if prevDayCl <> 0 then
plot5[-value1](PrevDayCl,"PREVcls", closecolor);
end;
if PlotOpen = true then begin
if DailyOp <> 0 then
plot6[-value1](DailyOp,"TodayOpen", opencolor);
end;
if PlotMidpoint = true then begin
if DailyMid <> 0 then
plot7[-value1](DailyMid,"TodayMid", midpointcolor);
end;
{if PlotHilo = true then begin
if DailyHi <> 0 then
plot8[-value1](DailyHi,"TodayHi", hilocolor);
if DailyLo <> 0 then
plot9[-value1](DailyLo,"TodayLo", hilocolor);
end;}
end;


Return to “MultiCharts”