Professional Documents
Culture Documents
New Text Document
New Text Document
com
// ORB Based Trading system with Stoploss and Target
_SECTION_BEGIN("ORB ");
SetPositionSize(1*RoundLotSize,spsShares);
mins = Param("Breakout(mins)",15,1,60,1);
orbh = ValueWhen(newday,TimeFrameGetPrice("H",in1Minute*mins,0))+buffer;
orbl = ValueWhen(newday,TimeFrameGetPrice("L",in1Minute*mins,0))-buffer;
//removing the values of ORBH and ORBL until the breakoutmeasuretime is reached
orbh = IIf(TimeNum()<starttime,Null,orbh); //redefining the ORBH value
orbl = IIf(TimeNum()<starttime,Null,orbl); //redefining the ORBL value
Plot(orbh,"ORBH",colorYellow,styleThick);
Plot(orbl,"ORBL",colorYellow,styleThick);
//Initialization
Buy =0;
Sell = 0;
Short = 0;
Cover = 0;
longstoplevel = Null;
longtargetlevel = Null;
shortstoplevel = Null;
shorttargetlevel = Null;
orbcondlong = IsNull(Ref(orbh,-1)) AND orbh>0 AND Open < orbh AND High > orbh;
orbcondshort = IsNull(Ref(orbl,-1)) AND orbl>0 AND Open > orbl AND low < orbl;
if(mode=="DISABLED")
{
//Entry Logic
Buy = (Cross(High,orbh) OR orbcondlong) AND TimeNum()>=starttime AND
TimeNum()<=endtime;
Sell = Cross(orbl,Low) OR TimeNum()>=sqofftime;
Short = (Cross(orbl,Low) OR orbcondshort) AND TimeNum()>=starttime AND
TimeNum()<=endtime;
Cover = Cross(High,orbh) OR TimeNum()>=sqofftime;
BuyPrice = ValueWhen(Buy,orbh);
SellPrice = ValueWhen(Sell,IIf(Cross(orbl,Low),orbl,Close));
ShortPrice = ValueWhen(Short,orbl);
CoverPrice = ValueWhen(Cover,IIf(Cross(High,orbh),orbh,Close));
buycontinue = Flip(Buy,Sell);
shortcontinue = Flip(Short,Cover);
if(mode=="POINTS")
{
//Trading Logic with Stop and Target (points)
//Entry Logic
Buy = (Cross(High,orbh) OR orbcondlong) AND TimeNum()>=starttime AND
TimeNum()<=endtime;
iSell = Cross(orbl,Low) OR TimeNum()>=sqofftime;
Short = (Cross(orbl,Low) OR orbcondshort) AND TimeNum()>=starttime AND
TimeNum()<=endtime;
iCover = Cross(High,orbh) OR TimeNum()>=sqofftime;
Short = ExRem(Short,Cover);
Cover = ExRem(Cover,Short);
IIf(Cross(High,longtargetlevel),longtargetlevel,null)));
IIf(Cross(shorttargetlevel,Low),shorttargetlevel,null)));
buycontinue = Flip(Buy,Sell);
shortcontinue = Flip(Short,Cover);
Plot(IIf(buycontinue,longstoplevel,Null),"BuyStop Level",colorRed,styleDashed);
Plot(IIf(buycontinue,longtargetlevel,Null),"BuyTarget
Level",colorgreen,styleDashed);
Plot(IIf(shortcontinue,shortstoplevel,Null),"ShortStop
Level",colorRed,styleDashed);
Plot(IIf(shortcontinue,shorttargetlevel,Null),"ShortTarget
Level",colorgreen,styleDashed);
if(mode=="PERCENTAGE")
{
//Trading Logic with Stop and Target (Percentage)
//Entry Logic
Buy = (Cross(High,orbh) OR orbcondlong) AND TimeNum()>=starttime AND
TimeNum()<=endtime;
iSell = Cross(orbl,Low) OR TimeNum()>=sqofftime;
Short = (Cross(orbl,Low) OR orbcondshort) AND TimeNum()>=starttime AND
TimeNum()<=endtime;
iCover = Cross(High,orbh) OR TimeNum()>=sqofftime;
Short = ExRem(Short,Cover);
Cover = ExRem(Cover,Short);
IIf(Cross(High,longtargetlevel),longtargetlevel,null)));
IIf(Cross(shorttargetlevel,Low),shorttargetlevel,null)));
buycontinue = Flip(Buy,Sell);
shortcontinue = Flip(Short,Cover);
Plot(IIf(buycontinue,longstoplevel,Null),"BuyStop Level",colorRed,styleDashed);
Plot(IIf(buycontinue,longtargetlevel,Null),"BuyTarget
Level",colorgreen,styleDashed);
Plot(IIf(shortcontinue,shortstoplevel,Null),"ShortStop
Level",colorRed,styleDashed);
Plot(IIf(shortcontinue,shorttargetlevel,Null),"ShortTarget
Level",colorgreen,styleDashed);
}
_SECTION_END();
_SECTION_BEGIN("Trading Signal");
_SECTION_END();
_SECTION_BEGIN("Price");
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", ParamColor("Color", colorDefault ), styleNoTitle |
ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();
//Dashboard Controls.
_SECTION_BEGIN("Trading Dashboard");
GfxSelectPen(colorWhite);
GfxSelectSolidBrush(SelectedValue(color));
//GfxRoundRect(20,height-150,320,height-30,15,15);
GfxGradientRect(20,height-150,320,height-30,SelectedValue(color),colorBlack);
_SECTION_END();