Tony Crabel's Opening Range Formula

#61
Thanks dryheat..... may be i don't have enough intraday data to plot levels in 15mins charts or any chart lower than 30mins TF.......as i am getting all required levels in 30 mins and hrly charts only.... no matter.. its ok..... regarding Daily charts.. i have seen some time back... some darvos box afl.. which plots this kind of thing in Ami.. but using tht is all together complete different thing.....
Please tell me the market you are trading, along with the time of the market open and market close. If it works for 30 min chart it should also work for the rest so I would like to collect some more information to see why it is not working in your market. Virtually all of my experience is using U.S. market data and the more I learn about other markets the more I will be able to adapt my code to work with multiple markets.

Dry :)
 
#62
opening range afl is working for 30 min chart in india market. afl is not working on 60 min and 5 min chart . india market time is 9.55 to 15.30.
how it will work on 5 min and 60 min timeframe ?
 
#63
opening range afl is working for 30 min chart in india market. afl is not working on 60 min and 5 min chart . india market time is 9.55 to 15.30.
how it will work on 5 min and 60 min timeframe ?
Ok, the India market open is different then U.S. so change the following statement in the code:
TimeOpen = 093000;

To:
TimeOpen = 095500;

Next, the India market close is two hours past the Saudi market and I have already defined a modified statement to work for this.
Change the following statement in the code:
TimeClose = IIf(Interval() == 420, 155500, 6000-(Interval()/60*100)+150000);

To:
TimeClose = IIf(Interval() == 420, 132500, 3000-(Interval()/60*100)+150000);

After making these changes check to see if the other time frames are functional.
Let me know the results.

Dry :)
 

chintan786

Well-Known Member
#64
Please tell me the market you are trading, along with the time of the market open and market close. If it works for 30 min chart it should also work for the rest so I would like to collect some more information to see why it is not working in your market. Virtually all of my experience is using U.S. market data and the more I learn about other markets the more I will be able to adapt my code to work with multiple markets.

Dry :)
thanks dryheat.... I trade in Indian Market.. Marketing timmings are 0955 to 1530 hrs..

thanks for everything

chintan
 

chintan786

Well-Known Member
#66
Very good. Try adjusting your code using the response I posted to milind2754. Once you complete the changes give it try on various time frames and let me know how it works.

Dry :)
wow.... it's working now.... thanks Dryheat... just curious.. are u indian.. if yes.. then whch mkt u trade.

thanks & Regards,

chintan786
 
#67
Hello Chintan

Can you please upload the corrected AFL Code which you are using that will work on 15M timeframe and also a JPG picture of S&P Nifty (in 15 Min) using the same AFL code.
I am also facing the same problems faced by you earlier.

Regards

Saji
 
#68
wow.... it's working now.... thanks Dryheat... just curious.. are u indian.. if yes.. then whch mkt u trade.

thanks & Regards,

chintan786
I am glad it's up and running for you. I am located in the United States. I found this forum when doing a search for knowledge on volume spread analysis. I found very intelligent posts on this forum of various topics. I am trying to give back some helpful knowledge in return for the knowledge I have received here.

At some point in the future I would like to be able to trade multiple markets around the globe. Participation in this forum is helping me learn the details of trading multiple markets.

Take care, and good trading.

Dry :)
 

chintan786

Well-Known Member
#69
Hello Chintan

Can you please upload the corrected AFL Code which you are using that will work on 15M timeframe and also a JPG picture of S&P Nifty (in 15 Min) using the same AFL code.
I am also facing the same problems faced by you earlier.

Regards

Saji
Hi saji.. Nice to see u after a long time hope u r doing fine and Alright...

regarding the changes dry heat told... i able to get the required levels in 5-min charts only and not in 15-minTF... sorry for my part i intially plotted 5-min only and thought all are working.... now wht i done is I have 1 AFL having no changes and it plots 30-Min and another one with having the said changes by dryHeat.. and it plots 5-min charts....

if u want any of the abv then plz let me know.... will do the needful.

Warm Regards,

chintan:)
 

chintan786

Well-Known Member
#70
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();
 

Similar threads