usetf = ParamToggle("Use TF", "No|Yes", 1) ;
// Author: Pratap Balakrishnan
// Copyright: All rights reserved. Not to be circulated or shared or posted on websites without the author's written permission.
// email id: [email protected]
alloff = ParamToggle("All off", "No|Yes", 0) ;
tf = Param("TF", 3, 1, 100000, 1);
Periods = Param("Periods", 13, 2, 1000, 1, 10 );
isema = ParamToggle("MA Type", "MA|EMA", 1) ;
MAstyle = ParamStyle("MA Style", styleThick) ;
Clrma = ParamColor( "Color Up", colorBlue);
isexpandLast = ParamToggle("Expand Mode", "First|Last", 1);
expandmode = expandFirst ;
if (isexpandLast)
expandmode = expandLast ;
if (NOT alloff)
{
if (usetf)
{
tfs = tf *in1Minute ;
TimeFrameSet(tfs) ;
}
else
tfs = Interval() ;
Refp = ParamField("Price", 3);
if (isema)
MAhtf = EMA(Refp, Periods) ;
else
MAhtf = MA(Refp, Periods) ;
if (usetf)
MAhtfe = TimeFrameExpand(MAhtf, tfs, expandmode ) ;
else
MAhtfe = MAhtf ;
str = NumToStr(tf, 1.0)+"Min"+"-P"+NumToStr(Periods, 1.0) ;
Clr = Clrma ;
if (usetf)
Clre = TimeFrameExpand(Clr, tfs, expandmode ) ;
else
Clre = Clr ;
if (usetf)
TimeFrameRestore() ;
RefMAhtfe = MAhtfe ;
RefClre = Clre ;
Plot( RefMAhtfe, str, RefClre, MAstyle|styleNoLabel|styleNoRescale);
}
TimeFrameSet(in15Minute);
EMA15minute = EMA(C,20);
TimeFrameRestore();
Plot(TimeFrameExpand(EMA15minute, in15Minute, mode=expandFirst), "15minTF-20ema", ParamColor( "EMA15", colorTan), ParamStyle( "EMA15 Style", styleLine|styleDashed|styleNoRescale));
TimeFrameSet(30*in1Minute);
EMA30minute = EMA(C,20);
TimeFrameRestore();
Plot(TimeFrameExpand(EMA30minute, 30*in1Minute, mode=expandFirst), "30minTF-20ema", ParamColor( "EMA30", colorSkyblue), ParamStyle( "EMA30 Style", styleLine|styleDashed|styleNoRescale));
usetf = ParamToggle("Use TF", "No|Yes", 1) ;
// Author: Pratap Balakrishnan
// Copyright: All rights reserved. Not to be circulated or shared or posted on websites without the author's written permission.
// email id: [email protected]
alloff = ParamToggle("All off", "No|Yes", 0) ;
tf = Param("TF", 3, 1, 100000, 1);
Periods = Param("Periods", 13, 2, 1000, 1, 10 );
isema = ParamToggle("MA Type", "MA|EMA", 1) ;
MAstyle = ParamStyle("MA Style", styleThick) ;
Clrma = ParamColor( "Color Up", colorBlue);
isexpandLast = ParamToggle("Expand Mode", "First|Last", 1);
expandmode = expandFirst ;
if (isexpandLast)
expandmode = expandLast ;
if (NOT alloff)
{
if (usetf)
{
tfs = tf *in1Minute ;
TimeFrameSet(tfs) ;
}
else
tfs = Interval() ;
Refp = ParamField("Price", 3);
if (isema)
MAhtf = EMA(Refp, Periods) ;
else
MAhtf = MA(Refp, Periods) ;
if (usetf)
MAhtfe = TimeFrameExpand(MAhtf, tfs, expandmode ) ;
else
MAhtfe = MAhtf ;
str = NumToStr(tf, 1.0)+"Min"+"-P"+NumToStr(Periods, 1.0) ;
Clr = Clrma ;
if (usetf)
Clre = TimeFrameExpand(Clr, tfs, expandmode ) ;
else
Clre = Clr ;
if (usetf)
TimeFrameRestore() ;
RefMAhtfe = MAhtfe ;
RefClre = Clre ;
Plot( RefMAhtfe, str, RefClre, MAstyle|styleNoLabel|styleNoRescale);
}
function ParamOptimize( pname, defaultval, minv, maxv, step )
{
return Optimize( pname,
Param( pname, defaultval, minv, maxv, step ),
minv, maxv, step );
}
_SECTION_BEGIN("Augubhai's ORB System v1.1");
//--Intraday time frame
TimeFrameSet(in5Minute); //If reseting, check formula for TimeFrameInMinutes
TimeFrameInMinutes = 5;
//--Define all params
EntryBufferPct = ParamOptimize("Entry Buffer %", 0, 0, 2, 0.1);
SLPct = ParamOptimize("SL %", 1.4, 0.1, 10, 0.1);
TargetPct = ParamOptimize("Target %", 0, 0, 20, 0.5);
MaxTarget = 100;
TargetPct = IIf(TargetPct == 0, MaxTarget, TargetPct);
EntryTimeStart = ParamOptimize("Entry Time Start (Minutes)", 5, 5, 120, 5);
EntryBarStart = floor(EntryTimeStart/TimeFrameInMinutes) - 1;
EntryTimeEnd = ParamOptimize("Entry Time End (Minutes)", 25, 10, 180, 5);
EntryBarEnd = floor(EntryTimeEnd/TimeFrameInMinutes) - 1;
EntryBarEnd = IIf(EntryBarEnd < EntryBarStart, EntryBarStart, EntryBarEnd);
//--Plot Price Candle Chart
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", colorBlack, styleNoTitle | GetPriceStyle() );
//--New Day & Time. End Day & Time . End Day & Time is null till end of day 1
NewDay = (Day()!= Ref(Day(), -1)) OR BarIndex() == 0;
printf("\n NewDay : " + NewDay );
EndDay = (Day()!= Ref(Day(), 1));
printf("\n EndDay : " + EndDay );
FirstBarTime = ValueWhen(NewDay,TimeNum(),1);
EndTime = ValueWhen(EndDay,TimeNum(),1);
SquareOffTime = EndTime;
//--Calculate ORB, and SL
HighestOfDay = HighestSince(NewDay,H,1);
LowestOfDay = LowestSince(NewDay,L,1);
BarsSinceNewDay = BarsSince(NewDay);
ORBH = ValueWhen(BarsSinceNewDay<=EntryBarStart,HighestOfDay ,1) * (1 + (EntryBufferPct/100));
ORBL = ValueWhen(BarsSinceNewDay<=EntryBarStart,LowestOfDay ,1) * (1 - (EntryBufferPct/100));
ORBHSL = ORBH * (1-(SLPct/100));
//ORBHSL = ORBL;
ORBLSL = ORBL * (1+(SLPct/100));
//ORBLSL = ORBH;
ORBHTarget = ORBH * (1+(TargetPct/100));
ORBLTarget = ORBL * (1-(TargetPct/100));
//--Find Buy, Sell, Short & Cover Signals
BuySignal = (H >= ORBH) AND (BarsSinceNewDay > EntryBarStart);
printf("\nBuySignal : " + BuySignal );
ShortSignal = (L <= ORBL) AND (BarsSinceNewDay > EntryBarStart) ;
printf("\nShortSignal : " + ShortSignal );
BarsSinceLastBuySignal = (BarsSince(Ref(BuySignal,-1)) + 1);
BarsSinceLastShortSignal = (BarsSince(Ref(ShortSignal,-1)) + 1);
BarsSinceLastEntrySignal = Min(BarsSinceLastBuySignal, BarsSinceLastShortSignal);
BothEntrySignalsNull = IsNull(BarsSinceLastBuySignal) AND IsNull(BarsSinceLastShortSignal); //true for start of Day 1
printf("\n\nBarsSinceNewDay : " + BarsSinceNewDay );
printf("\n BarsSinceLastEntrySignal : " + BarsSinceLastEntrySignal);
Buy = (H >= ORBH) AND (BarsSinceNewDay > EntryBarStart) AND (BarsSinceNewDay <= EntryBarEnd) AND ((BarsSinceNewDay < BarsSinceLastEntrySignal) OR BothEntrySignalsNull );
Sell = (L <= ORBHSL) OR (H >= ORBHTarget) OR (TimeNum() > SquareOffTime-1) AND (BarsSinceNewDay > BarsSinceLastBuySignal);
Short = (L <= ORBL) AND (BarsSinceNewDay > EntryBarStart) AND (BarsSinceNewDay <= EntryBarEnd) AND ((BarsSinceNewDay < BarsSinceLastEntrySignal) OR BothEntrySignalsNull );
Cover = (H >= ORBLSL) OR (L <= ORBLTarget) OR (TimeNum() > SquareOffTime-1) AND (BarsSinceNewDay > BarsSinceLastShortSignal);
printf("\nBuy : " + Buy );
printf("\nSell : " + Sell );
printf("\nShort : " + Short );
printf("\nCover : " + Cover );
//--Handle if ORB broken both sides on same bar
//--And remove duplicate Sell & Cover signals, since ExRem did not work as needed when Buy & Sell on same bar
orbBothSides = IIf(Buy AND Short, 1, 0);
Buy = IIf(orbBothSides AND C <= O, 0, Buy);
Short = IIf(orbBothSides AND C > O, 0, Short);
Sell = IIf(orbBothSides AND C > O AND (L <= ORBHSL), 1, Sell);
Sell = IIf((BarsSince(Buy) < (BarsSince(Ref(Sell,-1))+1)) OR (BarsSince(Buy) AND IsNull(BarsSince(Ref(Sell,-1)))),Sell,0);
Cover = IIf(orbBothSides AND C <= O AND (H >= ORBLSL), 1, Cover);
Cover = IIf((BarsSince(Short) < (BarsSince(Ref(Cover,-1))+1)) OR (BarsSince(Short) AND IsNull(BarsSince(Ref(Cover,-1)))),Cover,0);
printf("\n\norbBothSides : " + orbBothSides);
printf("\nBuy : " + Buy );
printf("\nSell : " + Sell );
printf("\nShort : " + Short );
printf("\nCover : " + Cover );
//--Special Condition for 18 & 19 May 2009 for the Indian Market
Buy =IIf(DateNum()==1090518 OR (DateNum()==1090519 AND NewDay),0,Buy );
Sell =IIf(DateNum()==1090518 OR (DateNum()==1090519 AND NewDay),0,Sell );
Short =IIf(DateNum()==1090518 OR (DateNum()==1090519 AND NewDay),0,Short );
Cover =IIf(DateNum()==1090518 OR (DateNum()==1090519 AND NewDay),0,Cover );
//--Set prices
BuyPrice = IIf(Buy, ORBH, Null);
SellPrice = IIf(Sell, IIf(H >= ORBHTarget, ORBHTarget, Max(ORBHSL, L)), Null);
ShortPrice = IIf(Short, ORBL, Null);
CoverPrice = IIf(Cover, IIf(L <= ORBLTarget, ORBLTarget, Min(ORBLSL, H)), Null);
//--Plot ORB, and SL
Plot(ORBHSL,"",colorRed,styleDashed);
Plot(ORBLSL,"",colorRed,styleDashed);
Plot(IIf(TargetPct == MaxTarget, Null, ORBHTarget),"",colorGreen,styleDashed);
Plot(IIf(TargetPct == MaxTarget, Null, ORBLTarget),"",colorGreen,styleDashed);
PlotOHLC( ORBL, ORBH, ORBL, ORBH, "", colorYellow, styleCloud);
//--Plot Signals
shape1 = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes( shape1, IIf( Buy, colorGreen, colorGreen), 0, IIf( Buy, Low, High ) );
shape2 = Cover * shapeUpArrow + Short * shapeDownArrow;
PlotShapes( shape2, IIf( Cover, colorRed, colorRed), 0, IIf( Cover, Low, High ) );
GraphXSpace = 5;
//--Restore time frame
TimeFrameRestore();
_SECTION_END();
function ParamOptimize( pname, defaultval, minv, maxv, step )
{
return Optimize( pname,
Param( pname, defaultval, minv, maxv, step ),
minv, maxv, step );
}
_SECTION_BEGIN("Augubhai's ORB System v1.1");
//--Intraday time frame
TimeFrameSet(in5Minute); //If reseting, check formula for TimeFrameInMinutes
TimeFrameInMinutes = 5;
//--Define all params
EntryBufferPct = ParamOptimize("Entry Buffer %", 0, 0, 2, 0.1);
SLPct = ParamOptimize("SL %", 1.4, 0.1, 10, 0.1);
TargetPct = ParamOptimize("Target %", 0, 0, 20, 0.5);
MaxTarget = 100;
TargetPct = IIf(TargetPct == 0, MaxTarget, TargetPct);
EntryTimeStart = ParamOptimize("Entry Time Start (Minutes)", 5, 5, 120, 5);
EntryBarStart = floor(EntryTimeStart/TimeFrameInMinutes) - 1;
EntryTimeEnd = ParamOptimize("Entry Time End (Minutes)", 25, 10, 180, 5);
EntryBarEnd = floor(EntryTimeEnd/TimeFrameInMinutes) - 1;
EntryBarEnd = IIf(EntryBarEnd < EntryBarStart, EntryBarStart, EntryBarEnd);
//--Plot Price Candle Chart
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", colorBlack, styleNoTitle | GetPriceStyle() );
//--New Day & Time. End Day & Time . End Day & Time is null till end of day 1
NewDay = (Day()!= Ref(Day(), -1)) OR BarIndex() == 0;
printf("\n NewDay : " + NewDay );
EndDay = (Day()!= Ref(Day(), 1));
printf("\n EndDay : " + EndDay );
FirstBarTime = ValueWhen(NewDay,TimeNum(),1);
EndTime = ValueWhen(EndDay,TimeNum(),1);
SquareOffTime = EndTime;
//--Calculate ORB, and SL
HighestOfDay = HighestSince(NewDay,H,1);
LowestOfDay = LowestSince(NewDay,L,1);
BarsSinceNewDay = BarsSince(NewDay);
ORBH = ValueWhen(BarsSinceNewDay<=EntryBarStart,HighestOfDay ,1) * (1 + (EntryBufferPct/100));
ORBL = ValueWhen(BarsSinceNewDay<=EntryBarStart,LowestOfDay ,1) * (1 - (EntryBufferPct/100));
ORBHSL = ORBH * (1-(SLPct/100));
//ORBHSL = ORBL;
ORBLSL = ORBL * (1+(SLPct/100));
//ORBLSL = ORBH;
ORBHTarget = ORBH * (1+(TargetPct/100));
ORBLTarget = ORBL * (1-(TargetPct/100));
//--Find Buy, Sell, Short & Cover Signals
BuySignal = (H >= ORBH) AND (BarsSinceNewDay > EntryBarStart);
printf("\nBuySignal : " + BuySignal );
ShortSignal = (L <= ORBL) AND (BarsSinceNewDay > EntryBarStart) ;
printf("\nShortSignal : " + ShortSignal );
BarsSinceLastBuySignal = (BarsSince(Ref(BuySignal,-1)) + 1);
BarsSinceLastShortSignal = (BarsSince(Ref(ShortSignal,-1)) + 1);
BarsSinceLastEntrySignal = Min(BarsSinceLastBuySignal, BarsSinceLastShortSignal);
BothEntrySignalsNull = IsNull(BarsSinceLastBuySignal) AND IsNull(BarsSinceLastShortSignal); //true for start of Day 1
printf("\n\nBarsSinceNewDay : " + BarsSinceNewDay );
printf("\n BarsSinceLastEntrySignal : " + BarsSinceLastEntrySignal);
Buy = (H >= ORBH) AND (BarsSinceNewDay > EntryBarStart) AND (BarsSinceNewDay <= EntryBarEnd) AND ((BarsSinceNewDay < BarsSinceLastEntrySignal) OR BothEntrySignalsNull );
Sell = (L <= ORBHSL) OR (H >= ORBHTarget) OR (TimeNum() > SquareOffTime-1) AND (BarsSinceNewDay > BarsSinceLastBuySignal);
Short = (L <= ORBL) AND (BarsSinceNewDay > EntryBarStart) AND (BarsSinceNewDay <= EntryBarEnd) AND ((BarsSinceNewDay < BarsSinceLastEntrySignal) OR BothEntrySignalsNull );
Cover = (H >= ORBLSL) OR (L <= ORBLTarget) OR (TimeNum() > SquareOffTime-1) AND (BarsSinceNewDay > BarsSinceLastShortSignal);
printf("\nBuy : " + Buy );
printf("\nSell : " + Sell );
printf("\nShort : " + Short );
printf("\nCover : " + Cover );
//--Handle if ORB broken both sides on same bar
//--And remove duplicate Sell & Cover signals, since ExRem did not work as needed when Buy & Sell on same bar
orbBothSides = IIf(Buy AND Short, 1, 0);
Buy = IIf(orbBothSides AND C <= O, 0, Buy);
Short = IIf(orbBothSides AND C > O, 0, Short);
Sell = IIf(orbBothSides AND C > O AND (L <= ORBHSL), 1, Sell);
Sell = IIf((BarsSince(Buy) < (BarsSince(Ref(Sell,-1))+1)) OR (BarsSince(Buy) AND IsNull(BarsSince(Ref(Sell,-1)))),Sell,0);
Cover = IIf(orbBothSides AND C <= O AND (H >= ORBLSL), 1, Cover);
Cover = IIf((BarsSince(Short) < (BarsSince(Ref(Cover,-1))+1)) OR (BarsSince(Short) AND IsNull(BarsSince(Ref(Cover,-1)))),Cover,0);
printf("\n\norbBothSides : " + orbBothSides);
printf("\nBuy : " + Buy );
printf("\nSell : " + Sell );
printf("\nShort : " + Short );
printf("\nCover : " + Cover );
//--Special Condition for 18 & 19 May 2009 for the Indian Market
Buy =IIf(DateNum()==1090518 OR (DateNum()==1090519 AND NewDay),0,Buy );
Sell =IIf(DateNum()==1090518 OR (DateNum()==1090519 AND NewDay),0,Sell );
Short =IIf(DateNum()==1090518 OR (DateNum()==1090519 AND NewDay),0,Short );
Cover =IIf(DateNum()==1090518 OR (DateNum()==1090519 AND NewDay),0,Cover );
//--Set prices
BuyPrice = IIf(Buy, ORBH, Null);
SellPrice = IIf(Sell, IIf(H >= ORBHTarget, ORBHTarget, Max(ORBHSL, L)), Null);
ShortPrice = IIf(Short, ORBL, Null);
CoverPrice = IIf(Cover, IIf(L <= ORBLTarget, ORBLTarget, Min(ORBLSL, H)), Null);
//--Plot ORB, and SL
Plot(ORBHSL,"",colorRed,styleDashed);
Plot(ORBLSL,"",colorRed,styleDashed);
Plot(IIf(TargetPct == MaxTarget, Null, ORBHTarget),"",colorGreen,styleDashed);
Plot(IIf(TargetPct == MaxTarget, Null, ORBLTarget),"",colorGreen,styleDashed);
PlotOHLC( ORBL, ORBH, ORBL, ORBH, "", colorYellow, styleCloud);
//--Plot Signals
shape1 = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes( shape1, IIf( Buy, colorGreen, colorGreen), 0, IIf( Buy, Low, High ) );
shape2 = Cover * shapeUpArrow + Short * shapeDownArrow;
PlotShapes( shape2, IIf( Cover, colorRed, colorRed), 0, IIf( Cover, Low, High ) );
GraphXSpace = 5;
//--Restore time frame
TimeFrameRestore();
_SECTION_END();
SetPositionSize(1,4);
ApplyStop(0,2,10); //Ajust points for Stop Loss (3rd parameter)
ApplyStop(1,2,10); //Ajust points for Profit Stop (3rd parameter)
usetf = ParamToggle("Use TF", "No|Yes", 1) ;
// Author: Pratap Balakrishnan
// Copyright: All rights reserved. Not to be circulated or shared or posted on websites without the author's written permission.
// email id: [email protected]
alloff = ParamToggle("All off", "No|Yes", 0) ;
tf = Param("TF", 3, 1, 100000, 1);
Periods = Param("Periods", 13, 2, 1000, 1, 10 );
isema = ParamToggle("MA Type", "MA|EMA", 1) ;
MAstyle = ParamStyle("MA Style", styleThick) ;
Clrma = ParamColor( "Color Up", colorBlue);
isexpandLast = ParamToggle("Expand Mode", "First|Last", 1);
expandmode = expandFirst ;
if (isexpandLast)
expandmode = expandLast ;
if (NOT alloff)
{
if (usetf)
{
tfs = tf *in1Minute ;
TimeFrameSet(tfs) ;
}
else
tfs = Interval() ;
Refp = ParamField("Price", 3);
if (isema)
MAhtf = EMA(Refp, Periods) ;
else
MAhtf = MA(Refp, Periods) ;
if (usetf)
MAhtfe = TimeFrameExpand(MAhtf, tfs, expandmode ) ;
else
MAhtfe = MAhtf ;
str = NumToStr(tf, 1.0)+"Min"+"-P"+NumToStr(Periods, 1.0) ;
Clr = Clrma ;
if (usetf)
Clre = TimeFrameExpand(Clr, tfs, expandmode ) ;
else
Clre = Clr ;
if (usetf)
TimeFrameRestore() ;
RefMAhtfe = MAhtfe ;
RefClre = Clre ;
Plot( RefMAhtfe, str, RefClre, MAstyle|styleNoLabel|styleNoRescale);
}