Afl writers pls help

jsb2012

Active Member
#1
I WANT THE FOLLOWING CONDITION IN AFL : ONLY THE HI AND LO OF THE FIRST CANDLE SHOULD B MARKED FOR THE WHOLE DAY. PLS HELP ME WRITE THE CODE FOR THAT. I TRIED THE FOLLOWING BUT IT KEEPS CHANGING EVERY HOUR : DayH = TimeFrameGetPrice("H2", inHourly, -1); DayH = LastValue (DayH,1);// yesterdays high
DayL = TimeFrameGetPrice("L2", inHourly, -1); DayL = LastValue (DayL,1); // yesterdays low
SENIORS PLS HELP
 

srichakra

Active Member
#2
Try this and see if it helps. It is Open Range breakout code that I picked up from one of the threads in this forum. I am unable to give credit or link to the original post.Normally i paste the URL of the source in the first line of the code for future ref,but in this case it is missing.

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");

//--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);
ORBH = ValueWhen(NewDay,HighestOfDay ,1) * (1 + (EntryBufferPct/100));
ORBL = ValueWhen(NewDay,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
BarsSinceNewDay = BarsSince(NewDay);
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
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();
 

jsb2012

Active Member
#3
Thanks but i want code only to plot the first candle hi and lo (whether it is hrly,daily,weekly,etc) and nothing else. Pls
 
#7
helo my seniors and afl experts I have also a problem regarding afl..
I want 1 simple afl with reminder in amibrocker for only bullish and bearish engulfing pattern ..only this 2 candle sticks...nd also reconfirm this pattern with just next third candle condition which means 3rd candle also close previous candle high when bullish engulfing and vice versa..plz help me all as soon as possible


thanks in advance
 

muinali

Well-Known Member
#9
and how to plot line mark for previos day closing in same afl
 

muinali

Well-Known Member
#10
Hln=ValueWhen(TimeNum() == 091500,HHV(H,1));
Lln=ValueWhen(TimeNum() == 091500,LLV(L,1));
Cl = ValueWhen(TimeNum() == 092900,C);

Plot(Cl,"\n9:29 close :",colorWhite,styleDashed);
Plot(Hln,"\nH 1 :",colorBrightGreen,styleDashed);
Plot(Lln,"\nL 1 :",colorRed,styleDashed);
and how to plot line or dash mark for previos day high/low/closing in same afl
 
Last edited:

Similar threads