Created
March 4, 2018 07:20
-
-
Save marketcalls/3e2eed1cd0206598e9b1c7b9841b6c39 to your computer and use it in GitHub Desktop.
Onetimeframing Against Initial Balance – Intraday Trading Strategy Amibroker AFL Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_SECTION_BEGIN("Price"); | |
//Coded by Rajandran R - Founder Marketcalls.in and Co-founder Traderscafe.in (Co-working Space for Active Traders in Bangalore) | |
//Coded on 4th Dec 2017 | |
//Concept Adopted from Market Profile | |
/* | |
Buy - When Initial Balance direction is up (First Three Bars turns green) and price starts one timeframing down (consecutive 4 or 5 bars (30min) making consecutive lower high then look for a potential target towards the test of day high. | |
Short - When Initial Balance direction is down (First three bars turns red) and price starts one timeframing up (consecutive 4 or 5 bars (30min) making consecutive higher lows then look for a potential target towards the test of day low. | |
Amibroker AFL Code to implement the rules. However the trading system implmented in Amibroker is semi systematic as mostly stoploss is decided based on market profile charts (mostly adopting structural stops rather than a conventional stops). | |
What are the other stop loss rules can be praticed : One can adopt ATR based stops. However trailing stops might not work towards the trading strategy | |
*/ | |
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 ) ) )); | |
marketstarttime = 091500; | |
IBendtime = 101500; | |
tradestarttime = 124500; | |
tradeendtime = 144500; | |
sqofftime = 144500; | |
SetPositionSize(1,spsShares); | |
IBup = Null; | |
IBdn= Null; | |
newday = Day() != Ref(Day(),-1); | |
DayOpen = TimeFrameGetPrice("O",inDaily); | |
DayHigh = TimeFrameGetPrice("H",inDaily); | |
DayLow = TimeFrameGetPrice("L",inDaily); | |
ORBH = IIf(TimeNum() < IBendtime, Null ,ValueWhen(TimeNum() == IBendtime,HighestSince(newday and TimeNum() < IBendtime,H))); | |
ORBL = IIf(TimeNum() < IBendtime, Null, ValueWhen(TimeNum() == IBendtime,LowestSince(newday and TimeNum() < IBendtime,L))); | |
color = IIf(ORBH - DayOpen > DayOpen - ORBL, colorGreen,IIf(ORBH - DayOpen < DayOpen - ORBL, colorRed,colorGrey40)); | |
IBup = TimeNum() > 101500 AND ORBH - DayOpen > DayOpen - ORBL; | |
IBdn = TimeNum() > 101500 AND ORBH - DayOpen < DayOpen - ORBL; | |
OTbuy = Ref(H,-4)>= Ref(H,-3) AND Ref(H,-3)>= Ref(H,-2) AND Ref(H,-2)>= Ref(H,-1); | |
OTsell = Ref(L,-4)<= Ref(L,-3) AND Ref(L,-3)<= Ref(L,-2) AND Ref(L,-2)<= Ref(L,-1); | |
SetTradeDelays(0,0,0,0); | |
Buy = IBup AND OTbuy AND TimeNum() >= tradestarttime AND TimeNum() <=tradeendtime; | |
BuyTarget = HighestSince(newday,H); | |
Sell = TimeNum() >= sqofftime OR Cross(H,Ref(BuyTarget,-1)); | |
Short = IBdn AND OTsell AND TimeNum() >= tradestarttime AND TimeNum() <=tradeendtime; | |
ShortTarget = LowestSince(newday,L); | |
Cover = TimeNum() >= sqofftime OR Cross(Ref(ShortTarget,-1),L); | |
Buy = ExRem(Buy,Sell); | |
Sell = ExRem(Sell,Buy); | |
Short = ExRem(Short,Cover); | |
Cover = ExRem(Cover,Short); | |
BuyPrice = Open; | |
SellPrice = Open; | |
SellPrice = open; | |
CoverPrice = open; | |
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40); | |
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50); | |
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45); | |
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=40); | |
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50); | |
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45); | |
PlotShapes(IIf(Sell,shapeStar,Null),colorGreen); | |
PlotShapes(IIf(Cover,shapeStar,Null),colorred); | |
Plot( C, "Close", IIf(newday OR Ref(newday,-1) OR Ref(newday,-2), Ref(color,2),IIf((Ref(OTbuy,1) OR Ref(OTbuy,2) OR Ref(OTbuy,3) OR Ref(OTbuy,4)) AND TimeNum() >= 104500 AND TimeNum() <=150000,colorBlue, IIf((Ref(OTsell,1) OR Ref(OTsell,2) OR Ref(OTsell,3) OR Ref(OTsell,4)) AND TimeNum() >= 104500 AND TimeNum() <=150000,colorYellow,colorGrey40))) , styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); | |
Plot(ORBH,"ORBH",colorBlue); | |
Plot(ORBL,"ORBL",colorred); | |
_SECTION_END(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment