help on AFL

bandlab2

Well-Known Member
#1
I am looking to develop a system and need some help on AFL.

System Features
--------------

Buy signal will be generated when price goes above (Day Low + filter). Filter is a parameter, it could be something like 0.1 (which means 0.99 times Day Low)

Short signal will be generated when price goes below (Day High - filter). Filter is similar

Take Profit is a fixed percentage (parameter, configurable). Lets say 0.7% of entry price

Stoploss is a fixed percentage (parameter, configurable). Lets say 0.7% of entry price

Trade is successful if hit take profit. Trade is failed if hit SL

If prev trade is failed, then we can enter the trade again on next occurance on either direction. If prev trade is success, then thats it for the day

We can go doing several trades as ling as prev trade is failed. we could have 3 failed trades and 4th one would be a success. the chances of success increase with every failed trade.

so the system is to enter after N failed trades where N is configurable. that means if my N is 3, i will wait for 2 failed trades and take the 3rd trade.

we need Buy/Short arrows for Nth trade. not for all trades. the explorer also will show Nth trade details.

Also show the trade lines (entry, tp, sl) for Nth trade

All this explanation is for a single stock. we could have a basket of stocks in market group

The explorer should show stock name, time, direction (Buy/Short), entry price, TP, SL, Status (success or fail). this is required for only Nth trade.


---------------


I am a newbie to AFL. I have gone thru EXREM function to remove excessive signals. but it will only remove same direction signal. May be i dont know how to use properly. i will have Buy, Sell, Cover, Short variables and should use EXREM or any other way to remember the attemp count (which will match to N) and then give signal. If N is 2, then it should ignore 1st trade if its failed.


------ sample code -----

SetChartBkColor(ParamColor("BackGround Color", colorBlack));

_SECTION_BEGIN("P/L Settings");
PercFilter=Param("Filter Percent",1.0,0,5,0.01);
PerctakeProfit=Param("Take Profit Percent",0.65,0.3,30,0.1);
PercStoploss=Param("SL Small",0.65,0.25,5,0.05);
AttemptCount=Param("Attempt Count",2,1,5,1);

PlotOHLC(Open,High,Low,Close,"",colorWhite,styleCandle);


// calculate day hi, lo

//Convert data to daily
Plot_Range = (TimeNum() >= 95500 AND TimeNum()<= 153500) AND (DateNum()==LastValue(DateNum()));
FH_Range = (TimeNum() >= 095500 AND TimeNum()<= 101459) AND (DateNum()==LastValue(DateNum()));

FH_Prices = High * FH_Range;
FH_Marker = BarsSince(FH_Range>0);

//Find number of bars in 60 minutes
Num_Bars = 3600 / Interval(1);

TimeFrameSet(inDaily);
TOP_ = Open;
PDH_ = Ref(High,-1);
PDL_ = Ref(Low,-1);
PDO_ = Ref(Open,-1);
PDC_ = Ref(Close,-1);
PDM_ = (PDH_+PDL_)/2;
TimeFrameRestore();
//
isAll = True;
isRth = TimeNum() >= 095400 AND TimeNum() <= 101459;
isdRth = TimeNum() >= 095400 AND TimeNum() <= 160000;

aRthL = IIf(isRth, L, 1000000);
aRthH = IIf(isdRth, H, Null);
aRthLd = IIf(isdRth, L, 1000000);

TOP = TimeFrameExpand(TOP_,inDaily,expandFirst);
PDH = TimeFrameExpand(PDH_,inDaily,expandFirst);
PDL = TimeFrameExpand(PDL_,inDaily,expandFirst);
PDO = TimeFrameExpand(PDO_,inDaily,expandFirst);
PDC = TimeFrameExpand(PDC_,inDaily,expandFirst);
PDM = TimeFrameExpand(PDM_,inDaily,expandFirst);
FHH = Ref(HHV(High*FH_Range,Num_Bars),-FH_Marker);
FHL = TimeFrameCompress( aRthL, inDaily, compressLow );
FHL = TimeFrameExpand( FHL, inDaily, expandFirst );
DayH = TimeFrameCompress( aRthH, inDaily, compressHigh );
DayH = TimeFrameExpand( DayH, inDaily, expandFirst );
DayL = TimeFrameCompress( aRthLd, inDaily, compressLow );
DayL = TimeFrameExpand( DayL, inDaily, expandFirst );

Buy = IIf(Cross(C, DayH- (DayH*PercFilter/100)),1,0);
Short = IIf(Cross(C, DayL + (DayH*PercFilter/100)),1,0);


// need to do EXREM and remove excess signals for N trades. to-d0

BuyPrice = ValueWhen(Buy, C);
ShortPrice = ValueWhen(Short, C);

BuyTPPrice = IIf(Buy, (round((BuyPrice+(BuyPrice*(PerctakeProfit/100)))*10))/10, 0);
BuySLPrice = IIf(Buy, (round((BuyPrice-(BuyPrice*(PercTweak/100)))*10))/10, 0);

ShortTPPrice = IIf(Short, (round((ShortPrice-(ShortPrice*(PerctakeProfit/100)))*10))/10, 0);
ShortSLPrice = IIf(Short, (round((ShortPrice+(ShortPrice*(PercTweak/100)))*10))/10, 0);

Cover = ...

// need plot lines for entry, exit, sl

// need explore code
 

Similar threads