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

[amibroker] Slight problem with this script - I'm Stumped



PureBytes Links

Trading Reference Links

Hi all,

I plan on using this script to test breakout trading systems and it 
just about works the way I want it to. But....

What I'm trying to do is determine swing highs and lows of "nth" 
degree. Which means that if I select a n=2 degree Swing High/Low 
setup the swing high (SH), for instance, must have two lower (or 
equal) highs both on the left and on the right of it. So I don't 
know until two days after the SH occured that it actually was an SH.

In this script I've colored the bars green and dark red. The greens 
represent the SL's and the dark red's the SH's. I also plotted an 
envelope (pink and light blue) of the latest SH's and SL's that are 
known at the time of each bar.

My problem is that for certain selections of 'n' and certain stocks 
several bars near the last set of bars get colored when the script 
shouldn't even know if they are SH's or SL's. To see what I mean try 
plotting AMD with n=3.

Can anyone tell me why these colors are occuring? Better yet, can 
you offer a solution? 

Thanks.

-ace


// --------------------------------------------------
// ---------------- Start AFL Script ----------------
// --------------------------------------------------
// Plotting Swing Highs and Lows
// --------------------------------------------------
// Degree of SH/SL set
n=3;
// --------------------------------------------------
// Peak and Trough points (SH's and SL's)
pk=Ref(HHV(H,2*n+1)==Ref(H,-n),n);
tr=Ref(LLV(L,2*n+1)==Ref(L,-n),n);
// --------------------------------------------------
// SH and SL envelope values
sh1=IIf(pk,H,Null);
sh=Ref(HighestSince(pk,sh1,1),-n-1);
sl1=IIf(tr,L,Null);
sl=Ref(HighestSince(tr,sl1,1),-n-1);
// --------------------------------------------------
// Plotting
Plot( Close, "OHLC", IIf(pk,colorDarkRed,IIf
(tr,colorGreen,colorBlack)), 132);
Plot( sh, "SH", colorPink, styleLine);
Plot( sl, "SL", colorLightBlue, styleLine);
GraphXSpace=5;




------------------------ 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/mOAaAA/3exGAA/qnsNAA/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/