Doubt with AFL Code

#1
Dear Community,

I'm very new to amibroker and to afl code as well. I was trying to write an afl code to plot horizontal lines of yesterday's close and today's open for today. I used the following code, though the plot of horizontal line is seen the data is incorrect. Requesting someone to please help me with this.

DayOpen=TimeFrameGetPrice("O",inDaily);
PreDayClose=TimeFrameGetPrice("C", inDaily, -1);

I've used the above code to get the values but the result value displayed is incorrect.

Code:
_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() ); 
DayOpen=TimeFrameGetPrice("O",inDaily);
PreDayClose=TimeFrameGetPrice("C", inDaily, -1);
Plot(PreDayClose,"PreClose",colorWhite);
Plot(DayOpen,"OpenPrice",colorRose);
_SECTION_END();

_SECTION_BEGIN("Price Interpretation");
movshort = ParamField("Short Time MA", 8 );
movmed = ParamField("Mid Time MA", 9 );
movlong = ParamField("Long Time MA", 10 );
btop = ParamField("BBTop", 11 );
bbot = ParamField("BBBottom", 12 );
if( Status("action") == actionCommentary )
{
width = btop - bbot;
lslop = LinRegSlope( C, 30 ) + 100;
lslo = LLV( lslop, 90 );
lshi = HHV( lslop, 90 );
lswidth = lshi - lslo;
trend = 100*( lslop - lslo )/lswidth;

mawidth = MA( width, 100 );
relwidth = 100*(width - mawidth)/mawidth;

_N( tname = Name()+"("+FullName()+")" );

printf("Price and moving averages:\n");
printf( tname + " has closed " + WriteIf( C > movshort, "above" , "below" ) + " its Short time moving average. ");

printf("\nShort time moving average is currently " + WriteIf( movshort > movmed, "above", "below") + " mid-time, AND " + WriteIf( movshort > movlong, "above", "below" ) + " long time moving averages.");

printf("\nThe relationship between price and moving averages is: "+
WriteIf( C > movshort AND movshort > movmed, "bullish",
WriteIf( C < movshort AND movshort < movmed, "bearish", "neutral" ) ) + " in short-term, and "+
WriteIf( movshort > movmed AND movmed > movlong , "bullish",
WriteIf( movshort < movmed AND movmed < movlong, "bearish", "neutral" ) ) + " in mid-long term. ");

printf("\n\nBollinger Bands:\n");
printf(tname+ " has closed " + 
WriteIf( C < bbot, "below the lower band by " +
WriteVal( 100 *( bbot-C )/ width, 1.1 ) + "%%. " +
WriteIf( trend < 30, " This combined with the steep downtrend can suggest that the downward trend in prices has a good chance of continuing.  However, a short-term pull-back inside the bands is likely.",
WriteIf( trend > 30 AND trend < 70, "Although prices have broken the lower band and a downside breakout is possible, the most likely scenario for "+tname+" is to continue within current trading range.", "" ) ), "" ) +

WriteIf( C > btop, "above the upper band by " +
WriteVal( 100 *( C- btop )/ width, 1.1 ) + "%%. " +
WriteIf( trend > 70, " This combined with the steep uptrend suggests that the upward trend in prices has a good chance of continuing.  However, a short-term pull-back inside the bands is likely.",
WriteIf( trend > 30 AND trend < 70, "Although prices have broken the upper band and a upside breakout is possible, the most likely scenario for "+tname+" is to continue within current trading range.", "" ) ), "" ) +

WriteIf( C < btop AND ( ( btop - C ) / width ) < 0.5, 
"below upper band by " +
WriteVal( 100 *( btop - C )/ width, 1.1 ) + "%%. ", 
WriteIf( C < btop AND C > bbot , "above bottom band by " +
WriteVal( 100 *( C - bbot )/ width, 1.1 ) + "%%. ", "" ) ));

printf("\n"+
WriteIf( ( trend > 30 AND trend < 70 AND ( C > btop OR C < bbot ) ) AND abs(relwidth) > 40,
		 "This picture becomes somewhat unclear due to the fact that Bollinger Bands are  currently",
		 "Bollinger Bands are " )+	  
WriteVal( abs( relwidth ), 1.1 ) + "%% " +
WriteIf( relwidth > 0, "wider" , "narrower" ) +
" than normal.");

printf("\n");

printf(
WriteIf( abs( relwidth ) < 40, "The current width of the bands (alone) does not suggest anything conclusive about the future volatility or movement of prices.","")+
WriteIf( relwidth < -40, "The narrow width of the bands suggests low volatility as compared to " + tname + "'s normal range.  Therefore, the probability of volatility increasing with a sharp price move has increased for the near-term. "+
"The bands have been in this narrow range for " + WriteVal(BarsSince(Cross(-40,relwidth)),1.0) + " bars. The probability of a significant price move increases the longer the bands remain in this narrow range." ,"")+
WriteIf( relwidth > 40, "The large width of the bands suggest high volatility as compared to " + tname + "'s normal range.  Therefore, the probability of volatility decreasing and prices entering (or remaining in) a trading range has increased for the near-term. "+
"The bands have been in this wide range for  " + WriteVal(BarsSince(Cross(relwidth,40)),1.0) + " bars.The probability of prices consolidating into a less volatile trading range increases the longer the bands remain in this wide range." ,""));

printf("\n\nThis commentary is not a recommendation to buy or sell. Use at your own risk.");
}
_SECTION_END();
I've used the default afl code (_price.afl) and added these lines to it. Not sure if it is correct.

Thanks in advance.
 

amitrandive

Well-Known Member
#2
Code:
DayOpen = TimeFrameGetPrice( "O", inDaily, 0 );
Plot( DayOpen, "Day Open", Colorblack, stylethick );
D1C = TimeFrameGetPrice( "C", inDaily, -1 );
Plot( D1C, "Yesterday Day Close", Colorwhite, stylethick );
 
#3
Thank you for the reply Amit. I tried using the same and I'm getting the following result, please check the attached image. I've used the aflcode on BankBaroda.

The actual
Close and Open result is 149.55 and 150 respectively. But I'm getting a different result in the aflcode.

Thanks in advance
 

Attachments

amitrandive

Well-Known Member
#4
Thank you for the reply Amit. I tried using the same and I'm getting the following result, please check the attached image. I've used the aflcode on BankBaroda.

The actual
Close and Open result is 149.55 and 150 respectively. But I'm getting a different result in the aflcode.

Thanks in advance
AFL is correct and is displaying correct.

Check if your quote editor matches with the data shown in Chart.
maybe issue with data.

Moneycontrol shows BOB open=149.8 and Yesterday close as 149.7
NSE site shows as BOB open=149.5 and Yesterday close as 149.55
 

mastermind007

Well-Known Member
#5
Thank you for the reply Amit. I tried using the same and I'm getting the following result, please check the attached image. I've used the aflcode on BankBaroda.

The actual
Close and Open result is 149.55 and 150 respectively. But I'm getting a different result in the aflcode.

Thanks in advance
Values plotted by amibroker are correct in accordance to your own database but your database in itself is not configured correctly. You can not see candles when plotting a tick chart.
 
#6
Thank you mastermind for the reply. can you share a sample how the candles look like when plotting a tick chart. I can share my database settings with you. Can you please help me.

Thanks,
 

vijkris

Learner and Follower
#8
Thanks for the reply Amit. I didn't understand what does the above sentence mean.. I'm not sure what is a quote editor.

Thanks
:lol: its like " i m driving a car but i don know how to switch on headlights" !!!

you r supposed to know the basics of any software/equipment before attempting to use it. :)
it is present right in front of u in the toolbars.
pls read user manual and become familiar with the software.
 

mastermind007

Well-Known Member
#9
Thank you mastermind for the reply. can you share a sample how the candles look like when plotting a tick chart. I can share my database settings with you. Can you please help me.

Thanks,
In a tick chart, at every quote, values of O H L and C will be same and therefore if you plot candles (or bars), they will appear completely flat (no head, no body, no tail)

Usually it is better to plot a line chart
 

Similar threads