[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] fouction to get H/L/C for previous periods



PureBytes Links

Trading Reference Links

this function gets the H/L/C for the previous day, month, year, hour.
data is returned in the vars ppHigh, ppLow, ppClose
Arguments are the period D,M,Y,H and how many periods back.
returns 1 if there were enough bars in the range...


// walt schwarz (aka Hairy_mug) 8/5/2003

function prevPeriodStats(period,periodsBack)
{
global PpHigh;
global PpLow;
global PpClose;

if(period=="D" OR period== "d")
{
tItem=DateNum();
}
else if (period=="M" OR period=="m")
{
tItem=Month();
}
else if (period=="Y" OR period== "y")
{
tItem=Year();
}
else if (period=="H" OR period== "h")
{
tItem=Hour();
}

sel=tItem!=Ref(tItem,-1);
tgtS=LastValue(ValueWhen(sel,BarIndex(),periodsBack+1));
tgtE=LastValue(ValueWhen(sel,BarIndex(),periodsBack));
ppHigh = ValueWhen( BarIndex()== tgtE, 
HHV( MA(High,3),tgtE-ValueWhen (BarIndex()== tgtS ,tgtS)) );
ppLow = ValueWhen( BarIndex()== tgtE, 
LLV(MA(Low,3),tgtE-ValueWhen (BarIndex()== tgtS ,tgtS)) );
ppClose=ValueWhen(BarIndex()== tgtE,C);
return tgtE>tgtS; // were there enough bars for a range?
}

//
// example: the HLC for the previous day
//

res=prevPeriodStats("d",1);
Plot(C,"c",colorBlue);
Plot(ppHigh,"pdh",colorRed);
Plot(PpLow,"pdl",colorBlack);
Plot(ppClose,"pdc",colorGold);





------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for Your HP, Epson, Canon or Lexmark
Printer at Myinks.com. Free s/h on orders $50 or more to the US & Canada. http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/sO0ANB/LIdGAA/ySSFAA/GHeqlB/TM
---------------------------------------------------------------------~->

Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx 
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/