just tried my half knowledge and it is working..but now it is only working for 15-min only no 30-mins and 5-mins..
here is the afl..
/*
Code created by Pete Hahn, Phoneix Arizona, USA Updated 5/31/09
Notice: Then contents of this code are intended to be purely
educational in nature. Trade at your own risk. Nothing in this
code is intended to guarantee profits or losses of any size.
Past results are not indicative of future performance. Consult
your registered financial planner before applying any of these
techniques to your live trading account.
Inquiries may be sent to:
[email protected]
*/
_SECTION_BEGIN("Price");
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
SetChartBkColor(ParamColor("Panel color ",colorLightBlue));
_SECTION_END();
_SECTION_BEGIN("Speed Lines");
P20 = 20;
Plot( EMA( C, P20 ), "Spd20" ,colorBlack, styleLine | styleThick );
P18 = 18;
Plot( EMA( C, P18 ), "Spd18" ,colorCustom9, styleLine | styleThick );
P50 = 50;
Plot( MA( C, P50 ), "Spd 50" , colorBlue,styleDashed | styleThick);
P200 = 200;
Plot( MA( C, P200 ), "Spd 200" , colorRed, ParamStyle("Style") );
Prd3HLC = Param("HLC 3 Prds", 3, 3, 10, 1);
Plot(MA((H + L + C)/3, Prd3HLC), "HLC 3MA", colorBlue, styleLine | styleThick);
Prd5HLC = Param("HLC 5 Prds", 5, 3, 10, 1);
Plot(MA((H + L + C)/3, Prd5HLC), "HLC 5MA", colorCustom12, styleLine | styleThick);
_SECTION_END();
_SECTION_BEGIN("Open Range Break Out");
//required settings:
TimeOpen = 094500;
//it is required here to calculate the time stamp of the market Close based on the
//chart Interval. There are limits to it's ability to adjust to different time
//intervals AND you should be aware of this. ONLY 3, 5, 7, 10, 15, AND 30 Minute
//intervals are supported here.
TimeClose = IIf(Interval() == 420, 15000, 6000-(Interval()/60*100)+150000);
//Determine the value of the market open. Initial setting is for
//9:30 AM to match US Market Open. Adjust as need for your market
MrktOpen = ValueWhen(TimeNum() == TimeOpen , Open);
//Determine the highest high for each day's trading.
//Adjust time as needed for your market.
DlyHigh = HighestSince(TimeNum() == TimeOpen , High);
//Take a snapshot value of the day's high at the time of market
//close. Intial setting is 4:00 pm to match US Market Close.
//Adjust as needed for your market.
DlyHighest = ValueWhen(TimeNum() == TimeClose , DlyHigh);
//Do the same for the lowest value of the trading day.
//Adjust time as needed for your market.
DlyLow = LowestSince(TimeNum() == TimeOpen , Low);
DlyLowest = ValueWhen(TimeNum() == TimeClose , DlyLow);
//determine the market closing price
DlyClose = ValueWhen(TimeNum() == TimeClose , C);
//Now calculate the min range value using Open, Low and High
//variables calculated above
RngMin = Min(DlyHighest - MrktOpen, MrktOpen - DlyLowest);
//Compres this to a daily time frame in order to capture
//the final value of the Range Min for each trading day
DlyRngMin = TimeFrameCompress(RngMin, inDaily, compressLast);
//Use the compressed variable to calculate a 10 day average
RngMinAvg = MA(DlyRngMin , 10);
//uncompress the daily variable so that it can be used in
//calcuating the long and short break out levels for each day
RngMinAvg = TimeFrameExpand(RngMinAvg, inDaily);
//caclculate the max range value using the opn, low and high
//variables
RngMax = Max(DlyHighest - MrktOpen, MrktOpen - DlyLowest);
//compress this to a daily time frame in order to capture
//the final value of the range max for each trading day
DlyRngMax = TimeFrameCompress(RngMax, inDaily, compressLast);
//use the compressed variable to calculate a 10 day average
RngMaxAvg = MA(DlyRngMax, 10);
//uncompress the daily variable so that it can be used in
//calculating the profit target for opening range breakouts
RngMaxAvg = TimeFrameExpand(RngMaxAvg, inDaily);
//Use the values calculated above to determine the opening
//range break outs. Notice the Range Min has been shifted so
//that is reads the previous day's value and this is used against
//the current day's open to determine the break out levels
BreakOutLong = MrktOpen + Ref(RngMinAvg, -1);
BreakOutShort = MrktOpen - Ref(RngMinAvg, -1);
//now use the average max range to calculate a profit target
//for each day's opening range break out
ProfitLong = MrktOpen + Ref(RngMaxAvg, -1);
ProfitShort = MrktOpen - Ref(RngMaxAvg, -1);
TitleBreakOuts = EncodeColor(colorBrightGreen) +"Today's Breakout Levels:" +"\n"
+"Long Target: " +ProfitLong + "\n"
+"Breakout Long: " +breakOutLong +"\n"
+"Today's Open: " +MrktOpen +"\n"
+"Breakout Short: " +breakOutShort +"\n"
+"Short Target: " +ProfitShort +"\n";
//Set parameter default to NO for diplaying values which
//are used to determine core metrics
PlotOHL = ParamToggle("Plot O,H,L", "YES|NO", 1);
//Set parameter default to YES for displaying the final
//results of the break out calculations.
PlotBreak = ParamToggle("Plot Breakout", "YES|NO", 0);
//Plot values per the parameter toggle settings.
if(PlotOHL == 0)
{
Plot(MrktOpen, "Daily Open", colorBlack, styleLine);
Plot(DlyHigh , "Daily High", colorGreen, styleDashed);
Plot(DlyLow , "Daily Low", colorRed, styleDashed);
Plot(DlyHighest , "Daily Highest", colorGreen, styleDots);
Plot(DlyLowest , "Daily Lowest", colorRed, styleDots);
}
_SECTION_END();
_SECTION_BEGIN("Toby Crabel Patterns");
TitleHeader = EncodeColor(colorYellow) +"Yesterday's Price Patterns" +"\n";
TitleSwing = EncodeColor(colorLavender) +"2 Day Swing Trend" + "\n";
//compress daily high and low for use in calculations
DlyC = TimeFrameCompress(DlyClose , inDaily, compressLast);
DlyH = TimeFrameCompress(DlyHighest, inDaily, compressLast);
DlyL = TimeFrameCompress(DlyLowest, inDaily, compressLast);
DlyO = TimeFrameCompress(MrktOpen, inDaily, compressLast);
//use compressed daily high and low to expand day's 2-5
PrevO = TimeFrameExpand(DlyO, inDaily);//day 2 open
PrevO2 = TimeFrameExpand(Ref(DlyO, -1), inDaily);//day 3 open
CurH = TimeFrameExpand(DlyH, inDaily);//day 2 high
PrevH = TimeFrameExpand(Ref(DlyH,-1), inDaily);//day 3 high
PrevH2 = TimeFrameExpand(Ref(DlyH,-2), inDaily);//day 4 high
PrevH3 = TimeFrameExpand(Ref(DlyH,-3), inDaily);//day 5 high
CurL = TimeFrameExpand(DlyL, inDaily);//day 2 low
PrevL = TimeFrameExpand(Ref(DlyL,-1), inDaily);//day 3 low
PrevL2 = TimeFrameExpand(Ref(DlyL,-2), inDaily);//day 4 low
PrevL3 = TimeFrameExpand(Ref(DlyL,-3), inDaily);//day 5 low
PrevC = TimeFrameExpand(DlyC, inDaily);//day 2 close
PrevC2 = TimeFrameExpand(Ref(DlyC,-1), inDaily);//day 3 close
//code the NR
NR = (CurH - CurL) < (PrevH - PrevL);
//code and plot the ID
ID = (CurL > PrevL ) AND (CurH < PrevH );
TitleID = EncodeColor(colorWhite) + WriteIf(ID, " ID Day" +"\n", "");
//code and plot the NR4
DlyNR4 = (LLV(DlyH-DlyL,4) == (DlyH-DlyL));
NR4 = TimeFrameExpand(DlyNR4, inDaily);
TitleNR4 = EncodeColor(colorWhite) + WriteIf(Ref(NR4,-1), " NR4 Day"+"\n", "");
//code and plot the NR7
DlyNR7 = (LLV(DlyH-DlyL,7) == (DlyH-DlyL));
NR7 = TimeFrameExpand(DlyNR7, inDaily);
TitleNR7 = EncodeColor(colorWhite) + WriteIf(Ref(NR7,-1), " NR7 Day"+"\n", "");
//code and plot the pivot top
PivotTop = CurL < PrevL AND CurH < PrevH AND
PrevL < PrevL2 AND PrevH < PrevH2 AND
PrevH2 > PrevH3 AND PrevL2 > PrevL3 ;
DlyPvtTopBars = TimeFrameCompress(BarsSince(PivotTop), inDaily, compressLast);
BarsLstPvtTop = TimeFrameExpand(DlyPvtTopBars, inDaily);
//code and plot the pivot bottom
PivotBottom = CurH > PrevH AND CurL > PrevL AND
PrevH > PrevH2 AND PrevL > PrevL2 AND
PrevL2 < PrevL3 AND PrevH2 < PrevH3 ;
DlyPvtBotBars = TimeFrameCompress(BarsSince(PivotBottom), inDaily, compressLast);
BarsLstPvtBot = TimeFrameExpand(DlyPvtBotBars , inDaily);
TitleSwingTrend = WriteIf(BarsLstPvtTop > BarsLstPvtBot, " Swing UP" +"\n", " Swing DWN" +"\n");
//calculate the 2 day range
DlyTwoDayRng = HHV(DlyH ,2) - LLV(DlyL ,2);
TwoDayRng = TimeFrameExpand(DlyTwoDayRng, inDaily);
//determine lowest 2 day range in previous 20 days
DlyTwoBarNR = LLV(DlyTwoDayRng , 20) == DlyTwoDayRng ;
TwoBarNR = TimeFrameExpand(DlyTwoBarNR, inDaily);
TitleTwoBarNR = WriteIf(Ref(TwoBarNR, -1), " 2DayNR" +"\n", "");
//calculate the 3 day range
DlyThreeDayRng = HHV(DlyH ,3) - LLV(DlyL ,3);
ThreeDayRng = TimeFrameExpand(DlyThreeDayRng, inDaily);
//determine lowest 3 day range in previous 20 days
DlyThreeBarNR = LLV(DlyThreeDayRng , 20) == DlyThreeDayRng ;
ThreeBarNR = TimeFrameExpand(DlyThreeBarNR, inDaily);
TitleThreeBarNR = WriteIf(Ref(ThreeBarNR, -1), " 3DayNR" +"\n", "");
//code and plot the hooks
BullHook = NR AND PrevO > PrevH2 AND PrevC < PrevC2 ;
TitleBullHook = WriteIf(BullHook, " BullHook" +"\n", "");
BearHook = NR AND PrevO < PrevL2 AND PrevC > PrevC2;
TitleBearHook = WriteIf(BearHook, " BearHook" +"\n", "");
//determine if previous day closed up or down
CloseUP = PrevO < PrevC;
TitleUPDWN = WriteIf(PrevO < PrevC, " UP Day" +"\n", " DWN Day" +"\n");
GapDayUP = PrevO > PrevH2 ;
GapDayDWN = PrevO < PrevL2;
TitleGapDay = WriteIf(GapDayUP,
WriteIf(CloseUP, " Gap UP and closed UP" +"\n", " Gap UP and closed DWN" +"\n"),
WriteIf(GapDayDWN,
WriteIf(CloseUP, " Gap DWN and closed UP" +"\n", " Gap DWN and closed DWN" +"\n"),""));
_SECTION_END();
_SECTION_BEGIN("Daily Pivots");
//Determine the value of the market close. Initial setting is for
//4:00 PM to match US Market Open. Adjust as need for your market
MrktClose = ValueWhen(TimeNum() == TimeClose , Close);
Range = DlyHighest - DlyLowest;
PP = (DlyHighest + DlyLowest + MrktClose)/3;
PP = round(PP * 4) / 4;
R1 = (2 * PP) - DlyLowest;
S1 = (2 * PP) - DlyHighest;
R2 = PP + Range;
S2 = PP - Range;
R3 = R2 + Range;
S3 = S2 - Range;
R4 = R3 + Range;
S4 = S3 - Range;
PPSR1 = ParamToggle("PP,S1/R1", "YES|NO", 0);
S2R2 = ParamToggle("S2,R2", "YES|NO", 1);
S3R3 = ParamToggle("S3,R3", "YES|NO", 1);
S4R4 = ParamToggle("S4,R4", "YES|NO", 1);
TitlePivots = EncodeColor(colorBlack) +"Today's Daily Pivots" +"\n"
+"R1: " +R1 +"\n" +"PP: " +PP +"\n" +"S1: " +S1 +"\n";
if(PPSR1 == 0)
{
Plot(R1, "Dly R1", colorBlue, styleLine | styleThick | styleNoRescale);
Plot(PP, "Dly Pivot", colorCustom12, styleLine | styleThick | styleNoRescale);
Plot(S1, "Dly S1", colorBlue, styleLine | styleThick | styleNoRescale);
}
if(S2R2 == 0)
{
Plot(R2, "Dly R2", colorBlue, styleLine | styleNoRescale);
Plot(S2, "Dly S2", colorBlue, styleLine | styleNoRescale);
}
if(S3R3 == 0)
{
Plot(R3, "Dly R3", colorBlue, styleDashed | styleThick | styleNoRescale);
Plot(S3, "Dly S3", colorBlue, styleDashed | styleThick | styleNoRescale);
}
if(S4R4 == 0)
{
Plot(R4, "Dly R4", colorBlue, styleDashed | styleNoRescale);
Plot(S4, "Dly S4", colorBlue, styleDashed | styleNoRescale);
}
_SECTION_END();
if(PlotBreak == 0)
{
Plot(MrktOpen, "Daily Open", colorBlack, styleLine | styleNoRescale);
Plot(BreakOutLong , "Break Out Long", colorGreen, styleLine | styleNoRescale);
Plot(BreakOutShort , "Break Out Short", colorRed, styleLine | styleNoRescale);
Plot(ProfitLong, "Long Target", colorGold, styleDots | styleThick | styleNoRescale);
Plot(ProfitShort, "Short Target", colorGold, styleDots | styleThick | styleNoRescale);
PlotOHLC(MrktOpen, breakOutLong, MrktOpen, MrktOpen, "", colorPaleGreen, styleCloud | styleNoRescale | styleNoLabel);
PlotOHLC(MrktOpen, MrktOpen, BreakOutShort , MrktOpen, "", colorRose, styleCloud | styleNoRescale | styleNoLabel);
}
RibbonColor = IIf(TimeNum() >= TimeOpen AND TimeNum() <= TimeClose , colorGreen, colorRed);
Plot( 2, "ribbon",RibbonColor,styleOwnScale|styleArea|styleNoLabel, -1, 100 );
_SECTION_BEGIN("Title");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) ", O, H, L, C,
SelectedValue( ROC( C, 1 ) ) )+"\n" +TitleBreakOuts +TitlePivots +TitleSwing +TitleSwingTrend +TitleHeader
+TitleID +TitleNR4 +TitleNR7 +TitleTwoBarNR +TitleThreeBarNR +TitleBullHook +TitleBearHook
+WriteIf(TitleGapDay == "", TitleUPDWN, "") +TitleGapDay );
_SECTION_END();
_SECTION_BEGIN("Volume");
Plot( Volume, _DEFAULT_NAME(), ParamColor("Color", colorBlueGrey ), ParamStyle( "Style", styleHistogram | styleOwnScale | styleThick, maskHistogram ), 2 );
_SECTION_END();