Plot Amibroker Line chart of 3 days

I Wanted to Plot Line chart of 3 days one above other like Kitco Silver.

Resason I want to see Same time yesterday what price it was trading and day before yesterday. like that.

I should see anytime frame chart should automatically change to one above other. Max is 1H Min in 1m.

Please help

Link of Kitco chart to look
https://www.kitco.com/charts/livesilver.html

i tried reference it works but when we change to different time frame it doesnt.

This solution is using Ref() with no problems when switching between different time intervals

NDS = New_Day_Signal   = Ref(Day(),0) != Ref(Day(),-1);
YD  = Yesterday 	   = Ref(Close,ValueWhen(NDS,BarIndex(),2)-ValueWhen(NDS,BarIndex(),1));
BY  = Before_Yesterday = Ref(Close,ValueWhen(NDS,BarIndex(),3)-ValueWhen(NDS,BarIndex(),1));

Plot(Close,"Close",colorLightBlue,styleLine);
Plot(YD,"Yesterday Sessions",colorLime,styleLine);
Plot(BY,"Before Yesterday Session",colorRed,styleLine);
4 Likes

@Ravin, in the great majority of cases, for intraday bars, @Sebastian's solution works well.
There is a small inconvenience when you have some shortened session (i.e., when on a particular day - typically before festivities - the trading closes early).

To show it, I artificially created a shortened session: normal sessions in this example are from 08:00 to 22:00; I removed all the quotes after 19:00 on Dec. 21st.

immagine

The lime line (representing "yesterday") in the second yellow box is actually part of the current session (same values of the "Close" - light blue line - at the opening of the "today" session as in the first box).

This happens rarely, but t is possible to overcome it (leaving empty areas in the line plot) with a couple of additions to his code.
I did it verbosely to make it more readable.

NDS = New_Day_Signal   = Ref( Day(), 0 ) != Ref( Day(), -1 );

// YD  = Yesterday 	   = Ref(Close,ValueWhen(NDS,BarIndex(),2)-ValueWhen(NDS,BarIndex(),1));
// BY  = Before_Yesterday = Ref(Close,ValueWhen(NDS,BarIndex(),3)-ValueWhen(NDS,BarIndex(),1));

back1d_bars = ValueWhen( NDS, BarIndex(), 2 ) - ValueWhen( NDS, BarIndex(), 1 );
back1d = Ref( Close, back1d_bars );
back2d_bars = ValueWhen( NDS, BarIndex(), 3 ) - ValueWhen( NDS, BarIndex(), 1 );
back2d = Ref( Close, back2d_bars );

tn = TimeNum();
YD  = Yesterday 	   = IIf( tn == Ref( tn, back1d_bars ), back1d, Null );
BY  = Before_Yesterday = IIf( tn == Ref( tn, back2d_bars ), back2d, Null );

_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Close %g " + "{{VALUES}}", C));

Plot(Close,"Close",colorLightBlue,styleLine);
Plot(YD,"Yesterday Sessions",colorLime,styleLine);
Plot(BY,"Before Yesterday Session",colorRed,styleLine);

immagine

As mentioned, since this is a very infrequent happening, it's probably not worth it!

5 Likes

Thanks this one i liked it

Thanks for the details on festivals i can use this when there is offtime in market during holidays.

Hi Guys, There is problem in solution ( look at kitco link it plots yesterday and Previous day ahead of todays time)

Amibroker should show 24 hrs format and plot yesterdays and before previous day chart ( live market should captured on live not to move charts as and when time passes)

Hi Guys, There is problem in solution ( look at kitco link it plots yesterday and Previous day ahead of todays time)

Amibroker should show 24 hrs format and plot yesterdays and before previous day chart ( live market should captured on live not to move charts as and when time passes).

Excellent remark @beppe :+1: , that is surely worth to be mentioned as i always search for the best in code writing , and if noticed that i would probably correct it , thanks again :hibiscus:

2 Likes

You can instead use plot function , by placing the value of 2nd argument of Ref() function to shift the drawing horizontally
For more detail read this article

Hi , I am not able to understand if you help with settings or code its helpful.

I want previous days line chart should be ploted before hand. and today close price as per market. i have kept 50 blank spaces already in amibroker.

This article from KB explain how to increase number of blank bar , so you can view whole yesterday & before yesterday trading session

Blank bars 50 applied but not plotting of yesterday and before day price charts how to fix it like kitco chart.

Hello
i just remember for Another way to do what you want

@RAVIN look the following


// Plots yesterday day bars ahead of todays time session 
// By Panos  this version contain SparseCompress function

// Subject = "Multiple dates storage and future prodate projection" from old yahoo mails  date 06-Mar-2016


/// load Bars Required   @link https://tinyurl.com/yasghpu3
bi = Barindex();
fvbi = FirstVisibleValue( bi );
qfdb = Status( "quickaflfirstdatabar" );
fdb = qfdb + fvbi;
SetBarsRequired( fdb, 0 );  // Please make sure this "fdb" is not coded in a wrong way
printf(" quickaflfirstdatabar = %g,\t\n Barindex  = %g,\t\n SetBarsBack, = %g\n", qfdb, Bi , fdb );

// Find The New Day and plot a Vertical Line
bi = Barindex();
NewDay = IIf( Interval() < inDaily, Day(), Month() ); 
NewDay = NewDay != Ref( NewDay , -1 ); 
Plot(NewDay, "", colorGrey40, styleHistogram | styleOwnScale|styleNoLabel );
Plot( C, "Price", colorYellow, styleLine ) ;

// Find the start and last BarIndex of previous day

ndb1c= LastValue(ValueWhen(NewDay,C));	printf( "\n Last_C  =\t" + ndb1c );
ndb1=LastValue(ValueWhen(NewDay,bi,1));
ndb2=LastValue(ValueWhen(NewDay,bi,2));
NewDayBars=LastValue(bi)-ndb1;
Xbars1=ndb1-ndb2-NewDayBars;

// previous day Segment 
Segment1 = bi > ndb2 AND bi < ndb1;
x1 = SparseCompress( Segment1, C );
y1 = x1 -  (ValueWhen( bi == ndb2, C ) - ndb1C );  

// Plot the previous day Segment by using xshift of plot Function
Plot( y1, "", colorLightBlue, styleLine | styleNoLabel, 0, 0, Xbars1 );
PlotText( "D1" , BarCount + Xbars1, LastValue( y1 ), colorLightBlue );

Foto of what we see in the chart

Line_chart_of_3_days

7 Likes

Thanks it doesnt work in 5.7 it works in 6+ version but ploted for current day on+ previous day on current period only.

Hi there

The example should be as simple as possible so that the user can understand the code by the first reading of. And this is what I try to do.

If you read the User's Guide on the place where is SparseCompress function, then you will find that the informations are enough to rewrite the code to be compatible with the older version.

Always is nice to upgrade as now we have Matrix and more new function

1 Like

On this forum we only support versions 6.0 and higher How to use this site

Any older version is not supported. 6.0 is the lowest available version. 5.70 is NOT available from our web site.

Keep in mind that you should have legal purchased license to use AmiBroker. Make sure you use registered email address for this forum. In near future we will probably start differentiating user accounts on the forum to show their status.

2 Likes

Thanks it works on 6+ i have checked it and surpass function was not avaliable in old wanted to say it. thanks

Hi, I'm trying to graph the spread between the roc 10 periods of the sp500 and the roc 10 of the shy. I have read links and manual but I don't know how to interpret it. The first calculated the 10 period roc of the spx and shy. Then I don't know how to calculate the ratio. Can you help me?
regards
ROC%20SPREAD

_SECTION_BEGIN("SPREAD ROC");
// FUNCTION ROC
Value = ROC( C, 10 );
//TICKER AND PERIODS ROC
P1 = ParamField( "SP500_IDX" );
periods = Param("10", 15, 1, 200, 1 );
P2 = ParamField( "SHY" );
periods = Param("10", 15, 1, 200, 1 );


//SPREAD ROC 10 PERIODS SP500 AND ROC 10 PERIODS SHY
spread = Foreign( "SP500_IDX", "ROC( C,10)") - Foreign( "SHY", "ROC( C,10)");
Plot( spread, "spread", colorRed);