I need AFL coding..

#11
I think in timeframexpand you maybe using default (expandLast) and hence the line will get updated only at end of week or end of month whereas in 5min chart when watching live, the value continously appears to change based on current close.

to match higher TF line same as what you would see live the solution is simply to use expandFirst in timeframeexpand, you will see the live value the same as you would see on the weekly chart
You are right. the line will be updated at the end of the week for the moving average for weekly TF..

End value(Close value) of moving averages of different TFs will appear as horizontal lines in 5 minutes chart..

can u make this afl?
 
Last edited:
#12
Something like this? This is SAR, EMA-High and EMA-Low on 3TF's.....


You want instead of long staircase type lines or curves only simple lines be seen having a continuous value which changes on the underlying (curve/end value)? Simple, it can be done.
can you post the afl of the picture u mentioned ?

I can analyse better with afl if it is ok or not..
 
#13
The AFL contains SAR, EMAHigh and EMALow in multiple timeframes. The AFL is very complex and I am not sharing it as of now.

All I am asking is if you want something looking like this (in the image)? If yes, it can be done.

What one will have to do is plot price-candles in 5min then timeframeset to weekly to get SMA and wilder for the values then restore the time for the same procedure over monthly level. And in the end plot the values using a timeframeexpand with expand last.
My request is much more easier than your afl mentioned in the picture..

I dont want to see curves coming from different time frames..

In 5 Minutes time frame chart , I just want to see horizontal lines(right and left extended) assigned to close value of moving average of different time frames..
 

pratapvb

Well-Known Member
#14
You are right. the line will be updated at the end of the week for the moving average for weekly TF..

End value(Close value) of moving averages of different TFs will appear as horizontal lines in 5 minutes chart..

can u make this afl?
I repeat. You can get what you want using expandfirst in timeframeexpand and style staircase in plot. I am writing this from mobile. If you still not getting it, will write the 3-4 lines required per tf when on computer
 
#15
Fixed code:

Code:
// 1 day = 6hour 15min = 360+15 = 375*1Min candles = 75 5Min candles
// 1 week = 5 days
// 1month = 4 weeks
// 200bars * 4weeks * 5day * 75
SetBarsRequired(200*4*5*75, 0);

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

/*
_SECTION_BEGIN("SMA");
P1 = ParamField("Price field1",3);
Periods1 = Param("Periods1", 20, 2, 300, 1, 10 );
Plot( MA( P1, Periods1 ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
_SECTION_END();

_SECTION_BEGIN("WILDER");
P2 = ParamField("Price field2",3);
Periods2 = Param("Periods2", 200, 2, 300, 1, 10 );
Plot( Wilders( P2, Periods2 ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
_SECTION_END();
*/

// Weekly TF
TimeFrameSet(inWeekly);

_SECTION_BEGIN("SMA Weekly");
Pw = ParamField("Price field weekly",3);
Periodsw = Param("Period weekly", 20, 2, 300, 1, 10 );
SMAw	= MA( Pw, Periodsw );
SMAwe	= TimeFrameExpand(SMAw, inWeekly, expandLast);
Plot( SMAwe, _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );

_SECTION_BEGIN("Wilder's weekly");
Pww = ParamField("Price field wilder weekly",3);
Periodsww = Param("Periods wilder weekly", 200, 2, 300, 1, 10 );
Wilderw	= Wilders( Pww, Periodsww );
Wilderwe	= TimeFrameExpand(Wilderw, inWeekly, expandLast);
Plot( Wilderwe, _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
_SECTION_END();


TimeFrameRestore(); // Restore
TimeFrameSet(inMonthly); // Move to monthly

_SECTION_BEGIN("SMA Monthly");
Pm = ParamField("Price field monthly",3);
Periodsm = Param("Period monthly", 20, 2, 300, 1, 10 );
SMAm	= MA( Pm, Periodsm );
SMAme	= TimeFrameExpand(SMAm, inMonthly, expandLast);
Plot( SMAme, _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

_SECTION_BEGIN("Wilder's Monthly");
Pwm = ParamField("Price field wilder weekly",3);
Periodswm = Param("Periods wilder weekly", 200, 2, 300, 1, 10 );
Wilderm	= Wilders( Pwm, Periodswm );
Wilderme	= TimeFrameExpand(Wilderm, inMonthly, expandLast);
Plot( Wilderme, _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

TimeFrameRestore();
Monthly Wilder might not get plotted. About 16 years of data required for that.
Thank you for your efforts..

I will check out and get back to u as soon as possible..
 

pratapvb

Well-Known Member
#16
this is the code for weekly

horizontal line for each week.....the last segment will update live until new week starts

I do not know whether your asking for wilders 200 was a mistype and that was also supposed to be 20... I did not have enough data for 200 and so have done both with do...you can change the pw if required....

in chart sold line is sma20 and plain wilders20 of weekly on 15min chart (chart can be of any lower tf 5min hourly whatever)

Code:
tfs = inWeekly ;
Clr = colorBlue ;

pe = 20 ;
pw = 20 ;

TimeFrameSet(tfs) ;
sma = MA(C, pe) ;
Wilder = Wilders(C, pw) ;
TimeFrameRestore() ;

smae = TimeFrameExpand(sma, tfs, expandFirst) ;
wildere = TimeFrameExpand(wilder, tfs, expandFirst) ;

Plot(smae, "", Clr, styleStaircase|styleLine|styleDots);
Plot(wildere, "", Clr, styleStaircase|styleLine);
 
#17
Fixed code:

Code:
// 1 day = 6hour 15min = 360+15 = 375*1Min candles = 75 5Min candles
// 1 week = 5 days
// 1month = 4 weeks
// 200bars * 4weeks * 5day * 75
SetBarsRequired(200*4*5*75, 0);

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

/*
_SECTION_BEGIN("SMA");
P1 = ParamField("Price field1",3);
Periods1 = Param("Periods1", 20, 2, 300, 1, 10 );
Plot( MA( P1, Periods1 ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
_SECTION_END();

_SECTION_BEGIN("WILDER");
P2 = ParamField("Price field2",3);
Periods2 = Param("Periods2", 200, 2, 300, 1, 10 );
Plot( Wilders( P2, Periods2 ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
_SECTION_END();
*/

// Weekly TF
TimeFrameSet(inWeekly);

_SECTION_BEGIN("SMA Weekly");
Pw = ParamField("Price field weekly",3);
Periodsw = Param("Period weekly", 20, 2, 300, 1, 10 );
SMAw	= MA( Pw, Periodsw );
SMAwe	= TimeFrameExpand(SMAw, inWeekly, expandLast);
Plot( SMAwe, _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );

_SECTION_BEGIN("Wilder's weekly");
Pww = ParamField("Price field wilder weekly",3);
Periodsww = Param("Periods wilder weekly", 200, 2, 300, 1, 10 );
Wilderw	= Wilders( Pww, Periodsww );
Wilderwe	= TimeFrameExpand(Wilderw, inWeekly, expandLast);
Plot( Wilderwe, _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
_SECTION_END();


TimeFrameRestore(); // Restore
TimeFrameSet(inMonthly); // Move to monthly

_SECTION_BEGIN("SMA Monthly");
Pm = ParamField("Price field monthly",3);
Periodsm = Param("Period monthly", 20, 2, 300, 1, 10 );
SMAm	= MA( Pm, Periodsm );
SMAme	= TimeFrameExpand(SMAm, inMonthly, expandLast);
Plot( SMAme, _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

_SECTION_BEGIN("Wilder's Monthly");
Pwm = ParamField("Price field wilder weekly",3);
Periodswm = Param("Periods wilder weekly", 200, 2, 300, 1, 10 );
Wilderm	= Wilders( Pwm, Periodswm );
Wilderme	= TimeFrameExpand(Wilderm, inMonthly, expandLast);
Plot( Wilderme, _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

TimeFrameRestore();
Monthly Wilder might not get plotted. About 16 years of data required for that.
Hello abhig10;

I checked out but Close price (End of price) for weekly SMA20 shows wrong..
Real SMA20 at weekly time frame is different..
weekly SMA20 calculated in 5 minutes is different..
There is something wrong..
I dont know why..
I dont paste the picture here. You can run your code at your amibroker and you can see the difference..
 
#18
this is the code for weekly

horizontal line for each week.....the last segment will update live until new week starts

I do not know whether your asking for wilders 200 was a mistype and that was also supposed to be 20... I did not have enough data for 200 and so have done both with do...you can change the pw if required....

in chart sold line is sma20 and plain wilders20 of weekly on 15min chart (chart can be of any lower tf 5min hourly whatever)

Code:
tfs = inWeekly ;
Clr = colorBlue ;

pe = 20 ;
pw = 20 ;

TimeFrameSet(tfs) ;
sma = MA(C, pe) ;
Wilder = Wilders(C, pw) ;
TimeFrameRestore() ;

smae = TimeFrameExpand(sma, tfs, expandFirst) ;
wildere = TimeFrameExpand(wilder, tfs, expandFirst) ;

Plot(smae, "", Clr, styleStaircase|styleLine|styleDots);
Plot(wildere, "", Clr, styleStaircase|styleLine);
Hello Pratap;

Thank you for your effort,

Your code shows the true value..

You are right. i dont have enough 5 minutes bars to show monthly time frame..

Daily bars is stored in daily database.. I have two different databases.. 5 minutes database for intraday and Daily database for daily and higher time frames.

Can we read the monthly prices from different database in 5 minutes chart?
 
#19
Hello abhig10;

I checked out but Close price (End of price) for weekly SMA20 shows wrong..
Real SMA20 at weekly time frame is different..
weekly SMA20 calculated in 5 minutes is different..
There is something wrong..
I dont know why..
I dont paste the picture here. You can run your code at your amibroker and you can see the difference..



I replaced the expandLast with expandfirst and it showed the end value right..
I am not good at amibroker coding and i saw the expandfirst command from pratap's code..

And expandfirst fixed the problem..
Whats the difference between expandlast and expandfirst?
 

pratapvb

Well-Known Member
#20
I replaced the expandLast with expandfirst and it showed the end value right..
I am not good at amibroker coding and i saw the expandfirst command from pratap's code..

And expandfirst fixed the problem..
Whats the difference between expandlast and expandfirst?
I have been saying from the beginning that we need to use expandfirst but apparently no one was listening

from ami help
expandLast - the compressed value is expanded starting from last bar within given period (so for example weekly close/high/low is available on Friday's bar)
expandFirst - the compressed value is expanded starting from first bar within given period (so for example weekly open is available from Monday's bar)
 
Last edited:

Similar threads