Help required by afl experts Happy_Singh

#1
About the afl

Based on kpl 5 & kpl 20 , Pivots & Candle color ( macd based )

Help required

Back test : Should show 5 & 20 results for buy and sell in backtester

Signals : Arrows should be generated only when 20 Long trend & 5 Small trend are the same.

Pivots : Kindly show only pivots for that particular day ie non repainting mode.

Thanks




The afl

Kindly also set back testers as per ur convince as to test the code effectively.

TimeFrameSet(inDaily);
DayHigh = LastValue(H);
DayLow = LastValue(L);
TimeFrameRestore();

Title = Date() + ", Op=" + Open + ", Hi=" + High + ", Lo=" + Low + ", LTP=" + Close + ", Change= " + SelectedValue( ROC( C, 1 ) ) + "%" + "\n Today`s High=" + DayHigh + ", Today`s Low=" + DayLow + " " ;


_SECTION_BEGIN("Macd Price");

//MACD
r1 = Param( "Impulse Fast avg", 12, 2, 200, 1 );
r2 = Param( "Impulse Slow avg", 26, 2, 200, 1 );
r3 = Param( "Impulse Signal avg", 9, 2, 200, 1 );

ml = MACD(r1, r2);
sl = Signal(r1,r2,r3);

MACUP = sl < ml AND ml > 0;
MACDN = sl > ml AND ml < 0;

SetBarFillColor (IIf(MACUP,colorGreen,IIf(MACDN, colorRed,colorWhite)));

Plot( C, "Price", IIf(MACUP,colorGreen,IIf(MACDN, colorRed,colorWhite)) , styleNoTitle | ParamStyle("Style") |
GetPriceStyle() );
_SECTION_END();

SetTradeDelays(0,0,0,0);
SetOption("CommissionMode",3);
SetOption("CommissionAmount",2.32);
SetOption("FuturesMode",True);
NumContracts=1;
PositionSize=NumContracts*MarginDeposit;
SetOption("MaxOpenPositions",4);

OptimizerSetEngine("cmae");
p1=Optimize("Period 1",5,1,20,1);
p2=Optimize("Period 2",20,10,50,1);

res1=HHV(H,p1);
sup1=LLV(L,p1);
tsl1=IIf(ValueWhen(IIf(C>Ref(res1,-1),1,IIf(C<Ref(sup1,-1),-1,0))!=0,IIf(C>Ref(res1,-1),1,IIf(C<Ref(sup1,-1),-1,0)),1)==1,sup1,res1);
res2=HHV(H,p2);
sup2=LLV(L,p2);
tsl2=IIf(ValueWhen(IIf(C>Ref(res2,-1),1,IIf(C<Ref(sup2,-1),-1,0))!=0,IIf(C>Ref(res2,-1),1,IIf(C<Ref(sup2,-1),-1,0)),1)==1,sup2,res2);

trend=IIf(C>tsl2,1,IIf(C<tsl2,-1,0));

Buy=C>tsl1 AND trend==1;Buy=Ref(Buy,-1);BuyPrice=O;
Sell=C<tsl1;Sell=Ref(Sell,-1);SellPrice=O;
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);

Short=C<tsl1 AND trend==(-1);Short=Ref(Short,-1);ShortPrice=O;
Cover=C>tsl1;Cover=Ref(Cover,-1);CoverPrice=O;
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);

SetChartOptions(0,chartShowArrows|chartShowDates);
SetChartBkColor(colorBlack);
Plot( C, "Close", ParamColor("Color", colorLightGrey ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
Plot(tsl1,"", colorWhite, styleStaircase);
Plot(tsl2,"", colorYellow, styleStaircase);

// ribbon code
Plot( 2, "Ribbon",IIf(C>tsl1,colorGreen,colorRed),styleOwnS cale|styleArea|styleNoLabel, -0.5, 100 );

// ribbon code
Plot( 4, "Ribbon",IIf(C>tsl2,colorWhite,colorBlack),styleOw nScale|styleArea|styleNoLabel, -1.0, 100 );


_SECTION_BEGIN(" My RSI of period 14");
periods = Param( "Periods", 14, 1, 200, 1 );

Bull = Cross(RSI(periods),70);
Bear = Cross(30,RSI(periods));

shape = Bull * shapeUpArrow + Bear * shapeDownArrow;
PlotShapes(shape, IIf( Bull , colorGreen, colorRed ), 0, IIf( Bull , Low, High ) );

_SECTION_END();

_SECTION_BEGIN("pivots mw");
/***************************************/
/*SUPER PIVOT POINTS ver 1.3 day week month
by Avi b a
/***************************************/
/*
SUPER PIVOT POINTS can by used in 2 ways:
if you choose daily, the pivots are calculated from the previous day,
this can be used for daily charts.
the second option is next day for EOD charts.
for all the options available right click on the chart parameters.
to utilize all the program features you need amibroker from version 4.80.1 and above.
enjoy!
*/
/*-----------------data------------------*/
SetChartBkColor(23) ;
k=IIf(ParamList("select type","daily|next day")=="daily",-1,0);
k1=-1;
TimeFrameSet(inDaily);
day_h= LastValue(Ref(H,K));
day_l= LastValue(Ref(L,K));
day_c= LastValue(Ref(C,K));
TimeFrameRestore();

TimeFrameSet(inWeekly);
Week_h= LastValue(Ref(H,K1));
Week_l= LastValue(Ref(L,K1));;
Week_c= LastValue(Ref(C,K1));;
TimeFrameRestore();

TimeFrameSet(inMonthly);
month_h= LastValue(Ref(H,K1));
month_l= LastValue(Ref(L,K1));
month_c= LastValue(Ref(C,K1));
TimeFrameRestore();

/*--------------------------------------*/
// day
DH=Day_h;
DL=Day_L;
DC=Day_C;

// DAY PIVOT Calculation
pd = ( DH+ DL + DC )/3;
sd1 = (2*pd)-DH;
sd2 = pd -(DH - DL);
sd3 = Sd1 - (DH-DL);
sd4 = Sd2 - (DH-DL);
sd5 = Sd3 - (DH-DL);
rd1 = (2*pd)-DL;
rd2 = pd +(DH -DL);
rd3 = rd1 +(DH-DL);
rd4 = rd2 +(DH-DL);
rd5 = rd3 +(DH-DL);

// week
WH=Week_h;
WL=Week_l;
WC=Week_c;

// WEEK PIVOT Calculation
pw = ( WH+ WL + WC )/3;
sw1 = (2*pw)-WH;
sw2 = pw -(WH - WL);
sw3 = Sw1 - (WH-WL);
sw4 = Sw2 - (WH-WL);
rw1 = (2*pw)-WL;
rw2 = pw +(WH -WL);
rw3 = rw1 +(WH-WL);
rw4 = rw2 +(WH-WL);


// month
MH=month_h;
ML=month_l;
MC=month_c;

// MONTH PIVOT Calculation
pm = ( MH+ ML + MC )/3;
sm1 = (2*pm)-MH;
sm2 = pm -(MH - ML);
sm3 = Sm1 - (MH-ML);
rm1 = (2*pm)-ML;
rm2 = pm +(MH -ML);
rm3 = rm1 +(MH-ML);

/*--------------------------------------*/
// PARAMETERS
slide = Param("slide all",33,-1000,1000,1);
slide1 = Param("slide_day",50,0,1000,1);
slide2 = Param("slide_week",70,0,1000,1);
slide3 = Param("slide_month",90,0,1000,1);
slide_Hight = Param("slide_Hight",0,-1000,1000,1);


SHALD = ParamList("daily Pivots", "selected only|all|hide" );
SHALW = ParamList("weekly Pivots", "hide|all|selected only" );
SHALM = ParamList("monthly Pivots", "hide|all|selected only" );

//day
PDP = ParamList("DP", "SHOW|HIDE" );
PDR1 = ParamList("DR1", "SHOW|HIDE" );
PDR2 = ParamList("DR2", "SHOW|HIDE" );
PDR3 = ParamList("DR3", "SHOW|HIDE" );
PDR4 = ParamList("DR4", "HIDE|SHOW" );
PDR5 = ParamList("DR5", "HIDE|SHOW" );

PDS1 = ParamList("DS1", "SHOW|HIDE" );
PDS2 = ParamList("DS2", "SHOW|HIDE" );
PDS3 = ParamList("DS3", "SHOW|HIDE" );
PDS4 = ParamList("DS4", "HIDE|SHOW" );
PDS5 = ParamList("DS5", "HIDE|SHOW" );


//week
PWP = ParamList("WP", "HIDE|SHOW" );
PWR1 = ParamList("WR1", "HIDE|SHOW" );
PWR2 = ParamList("WR2", "HIDE|SHOW" );
PWR3 = ParamList("WR3", "HIDE|SHOW" );
PWR4 = ParamList("WR4", "HIDE|SHOW" );

PWS1 = ParamList("WS1", "HIDE|SHOW" );
PWS2 = ParamList("WS2", "HIDE|SHOW" );
PWS3 = ParamList("WS3", "HIDE|SHOW" );
PWS4 = ParamList("WS4", "HIDE|SHOW" );

//month
PMP = ParamList("MP", "HIDE|SHOW" );
PMR1 = ParamList("MR1", "HIDE|SHOW" );
PMR2 = ParamList("MR2", "HIDE|SHOW" );
PMR3 = ParamList("MR3", "HIDE|SHOW" );

PMS1 = ParamList("MS1", "HIDE|SHOW" );
PMS2 = ParamList("MS2", "HIDE|SHOW" );
PMS3 = ParamList("MS3", "HIDE|SHOW" );
PIVOTPOINTCOLOR=6;
DAILYSUPPORTCOLOR=5;
DayCOLOR =4;
weekCOLOR =9;
monthCOLOR =34;
/*--------------------------------------*/
// LABELS
for( i = 0; i < BarCount; i++ )
{
//day
if(i+slide1== BarCount && (PDP=="SHOW" OR SHALD=="all") && SHALD!="hide") PlotText( "daily Pivot "+pd ,i+slide,pd+slide_Hight ,PIVOTPOINTCOLOR);
if(i+slide1== BarCount && (PDR1=="SHOW" OR SHALD=="all")&& SHALD!="hide") PlotText( "daily R1 "+rd1 ,i+slide,rd1+slide_Hight ,DayCOLOR );
if(i+slide1== BarCount && (PDR2=="SHOW" OR SHALD=="all")&& SHALD!="hide") PlotText( "daily R2 "+rd2 ,i+slide,rd2+slide_Hight ,DayCOLOR );
if(i+slide1== BarCount && (PDR3=="SHOW" OR SHALD=="all")&& SHALD!="hide") PlotText( "daily R3 "+rd3 ,i+slide,rd3+slide_Hight ,DayCOLOR );
if(i+slide1== BarCount && (PDR4=="SHOW" OR SHALD=="all")&& SHALD!="hide") PlotText( "daily R4 "+rd4 ,i+slide,rd4+slide_Hight ,DayCOLOR );
if(i+slide1== BarCount && (PDR5=="SHOW" OR SHALD=="all")&& SHALD!="hide") PlotText( "daily R5 "+rd5 ,i+slide,rd5+slide_Hight ,DayCOLOR );


if(i+slide1== BarCount && (PDS1=="SHOW" OR SHALD=="all")&& SHALD!="hide") PlotText( "daily S1 "+sd1 ,i+slide,sd1+slide_Hight ,DAILYSUPPORTCOLOR);
if(i+slide1== BarCount && (PDS2=="SHOW" OR SHALD=="all")&& SHALD!="hide") PlotText( "daily S2 "+sd2 ,i+slide,sd2+slide_Hight ,DAILYSUPPORTCOLOR );
if(i+slide1== BarCount && (PDS3=="SHOW" OR SHALD=="all")&& SHALD!="hide") PlotText( "daily S3 "+sd3 ,i+slide,sd3+slide_Hight ,DAILYSUPPORTCOLOR );
if(i+slide1== BarCount && (PDS4=="SHOW" OR SHALD=="all")&& SHALD!="hide") PlotText( "daily S4 "+sd4 ,i+slide,sd4+slide_Hight ,DAILYSUPPORTCOLOR );
if(i+slide1== BarCount && (PDS5=="SHOW" OR SHALD=="all")&& SHALD!="hide") PlotText( "daily S5 "+sd5 ,i+slide,sd5+slide_Hight ,DAILYSUPPORTCOLOR );

//week
if(i+slide2== BarCount && (PWP=="SHOW" OR SHALW=="all")&& SHALW!="hide") PlotText( "weekly Pivot "+pw ,i+slide,pw+slide_Hight ,weekCOLOR );
if(i+slide2== BarCount && (PWR1=="SHOW" OR SHALW=="all")&& SHALW!="hide") PlotText( "weekly R1 "+rw1 ,i+slide,rw1+slide_Hight ,weekCOLOR );
if(i+slide2== BarCount && (PWR2=="SHOW" OR SHALW=="all")&& SHALW!="hide") PlotText( "weekly R2 "+rw2 ,i+slide,rw2+slide_Hight ,weekCOLOR );
if(i+slide2== BarCount && (PWR3=="SHOW" OR SHALW=="all")&& SHALW!="hide") PlotText( "weekly R3 "+rw3 ,i+slide,rw3+slide_Hight ,weekCOLOR );
if(i+slide2== BarCount && (PWR4=="SHOW" OR SHALW=="all")&& SHALW!="hide") PlotText( "weekly R4 "+rw4 ,i+slide,rw4+slide_Hight ,weekCOLOR );


if(i+slide2== BarCount && (PWS1=="SHOW" OR SHALW=="all")&& SHALW!="hide") PlotText( "weekly S1 "+sw1 ,i+slide,sw1+slide_Hight ,weekCOLOR );
if(i+slide2== BarCount && (PWS2=="SHOW" OR SHALW=="all")&& SHALW!="hide") PlotText( "weekly S2 "+sw2 ,i+slide,sw2+slide_Hight ,weekCOLOR );
if(i+slide2== BarCount && (PWS3=="SHOW" OR SHALW=="all")&& SHALW!="hide") PlotText( "weekly S3 "+sw3 ,i+slide,sw3+slide_Hight ,weekCOLOR );
if(i+slide2== BarCount && (PWS4=="SHOW" OR SHALW=="all")&& SHALW!="hide") PlotText( "weekly S4 "+sw4 ,i+slide,sw4+slide_Hight ,weekCOLOR );

//month
if(i+slide3== BarCount && (PMP=="SHOW" OR SHALM=="all")&& SHALM!="hide") PlotText( "monthly Pivot "+pm ,i+slide,Pm+slide_Hight ,monthCOLOR );
if(i+slide3== BarCount && (PMR1=="SHOW" OR SHALM=="all")&& SHALM!="hide") PlotText( "monthly R1 "+rm1 ,i+slide,rm1+slide_Hight ,monthCOLOR );
if(i+slide3== BarCount && (PMR2=="SHOW" OR SHALM=="all")&& SHALM!="hide") PlotText( "monthly R2 "+rm2 ,i+slide,rm2+slide_Hight ,monthCOLOR );
if(i+slide3== BarCount && (PMR3=="SHOW" OR SHALM=="all")&& SHALM!="hide") PlotText( "monthly R3 "+rm3 ,i+slide,rm3+slide_Hight ,monthCOLOR );

if(i+slide3== BarCount && (PMS1=="SHOW" OR SHALM=="all")&& SHALM!="hide")PlotText( "monthly S1 "+sm1 ,i+slide,sm1+slide_Hight ,monthCOLOR);
if(i+slide3== BarCount && (PMS2=="SHOW" OR SHALM=="all")&& SHALM!="hide") PlotText( "monthly S2 "+sm2 ,i+slide,sm2+slide_Hight ,monthCOLOR );
if(i+slide3== BarCount && (PMS3=="SHOW" OR SHALM=="all")&& SHALM!="hide") PlotText( "monthly S3 "+sm3 ,i+slide,sm3+slide_Hight ,monthCOLOR );
}
/*--------------------------------------*/
// PLOTS
// style = IIf(ParamList("Chart style", "styleCandle|styleBar")=="styleCandle",64,128) ;
// Plot (C,Date ()+" close",11,style);
//day
if ((PDP=="SHOW" OR SHALD=="all") && SHALD!="hide") Plot (pd,"daily Pivot ",PIVOTPOINTCOLOR,8);
if ((PDR1=="SHOW" OR SHALD=="all") && SHALD!="hide") Plot (rd1,"daily R1 ",DayCOLOR,8);
if ((PDR2=="SHOW" OR SHALD=="all") && SHALD!="hide") Plot (rd2,"daily R2 ",DayCOLOR,8);
if ((PDR3=="SHOW" OR SHALD=="all") && SHALD!="hide") Plot (rd3,"daily R3 ",DayCOLOR,8);
if ((PDR4=="SHOW" OR SHALD=="all") && SHALD!="hide") Plot (rd4,"daily R4 ",DayCOLOR,8);
if ((PDR5=="SHOW" OR SHALD=="all") && SHALD!="hide") Plot (rd5,"daily R5 ",DayCOLOR,8);

if ((PDS1=="SHOW" OR SHALD=="all") && SHALD!="hide") Plot (sd1,"daily S1 ",DAILYSUPPORTCOLOR,8);
if ((PDS2=="SHOW" OR SHALD=="all") && SHALD!="hide") Plot (Sd2,"daily S2 ",DAILYSUPPORTCOLOR,8);
if ((PDS3=="SHOW" OR SHALD=="all") && SHALD!="hide") Plot (Sd3,"daily S3 ",DAILYSUPPORTCOLOR,8);
if ((PDS4=="SHOW" OR SHALD=="all") && SHALD!="hide") Plot (Sd4,"daily S4 ",DAILYSUPPORTCOLOR,8);
if ((PDS5=="SHOW" OR SHALD=="all") && SHALD!="hide") Plot (Sd5,"daily S5 ",DAILYSUPPORTCOLOR,8);


//week
if ((PWP=="SHOW" OR SHALW=="all") && SHALW!="hide") Plot (pW,"weekly Pivot ",weekCOLOR,1);
if ((PWR1=="SHOW" OR SHALW=="all") && SHALW!="hide") Plot (rw1,"weekly R1 ",weekCOLOR,32);
if ((PWR2=="SHOW" OR SHALW=="all") && SHALW!="hide") Plot (rw2,"weekly R2 ",weekCOLOR,32);
if ((PWR3=="SHOW" OR SHALW=="all") && SHALW!="hide") Plot (rw3,"weekly R3 ",weekCOLOR,32);
if ((PWR4=="SHOW" OR SHALW=="all") && SHALW!="hide") Plot (rw4,"weekly R4 ",weekCOLOR,32);


if ((PWS1=="SHOW" OR SHALW=="all") && SHALW!="hide") Plot (sw1,"weekly S1 ",weekCOLOR,32);
if ((PWS2=="SHOW" OR SHALW=="all") && SHALW!="hide") Plot (Sw2,"weekly S2 ",weekCOLOR,32);
if ((PWS3=="SHOW" OR SHALW=="all") && SHALW!="hide") Plot (Sw3,"weekly S3 ",weekCOLOR,32);
if ((PWS4=="SHOW" OR SHALW=="all") && SHALW!="hide") Plot (Sw4,"weekly S4 ",weekCOLOR,32);

//month
if ((PMP=="SHOW" OR SHALM=="all") && SHALM!="hide") Plot (pm,"monthly Pivot",monthCOLOR ,1);
if ((PMR1=="SHOW" OR SHALM=="all") && SHALM!="hide") Plot (rm1,"monthly R1",monthCOLOR ,32);
if ((PMR2=="SHOW" OR SHALM=="all") && SHALM!="hide") Plot (rm2,"monthly R2",monthCOLOR ,32);
if ((PMR3=="SHOW" OR SHALM=="all") && SHALM!="hide") Plot (rm3,"monthly R3",monthCOLOR ,32);

if ((PMS1=="SHOW" OR SHALM=="all") && SHALM!="hide") Plot (sm1,"monthly S1",monthCOLOR ,32);
if ((PMS2=="SHOW" OR SHALM=="all") && SHALM!="hide") Plot (sm2,"monthly S2",monthCOLOR ,32);
if ((PMS3=="SHOW" OR SHALM=="all") && SHALM!="hide") Plot (sm3,"monthly S3",monthCOLOR ,32);
/*--------------------------------------*/
// TEXT
"high = "+H;
"low = "+L;
"close = "+C;
_SECTION_END();
 
#3
Hello friend

It is tough to get so much time to read and understand the 200/500 lines of code that is written by someone else and then offer a solution. However if you can ask specific questions with a sample code, then many can help you. Also there is no need to put any members name in the thread title, there are many members on this forum who are good with Amibroker and also are very helpful.

Cheers

As for you specific query, will try to look at it after the market hours, meanwhile if you can give more details/clarification about highlighted part.

Help required

Back test : Should show 5 & 20 results for buy and sell in backtester
please explain this more

Signals : Arrows should be generated only when 20 Long trend & 5 Small trend are the same.
--- OK ---

Pivots : Kindly show only pivots for that particular day ie non repainting mode.
By nature pivots will repaint,
if the current bar will print a pivot, it depends on future price action



Thanks
:) Happy
 
Last edited:
#5
Back test & Signals : Should show 5 & 20 results for buy and sell in backtester
please explain this more

Ans : Long trend 20 in black dots sar

small trend 5 in grey sar

Signals , arrows & backtest should be shown only when the trend in both the 20 & 5 sar are same.

kindly do it for the below afl.

SetChartBkColor(colorWhite) ;

GraphXSpace = 5;

// Amibroker AFL code by Edward Pottasch, Oct 2012
// Alternative ZIG type function based on the ATR and VSTOP functions
// Added multiple timeframes. Maximum timeframe set to 1440 minutes

x=xx=BarIndex();
tc=ParamList("Display Mode","ZIG|VSTOP|ZIG&VSTOP",1);
disp0=ParamToggle("Display labels","Off|On",1);
disp1=ParamToggle("Display value labels","Off|On",1);
tf=Param("Time Frame (min)",60,1,1440,1);tfrm=in1Minute*tf;
perBull=Param("perBull",20,1,150,1);
perBear=Param("perBear",20,1,150,1);
multBull=Param("multBull",2,0.05,4,0.05);
multBear=Param("multBear",2,0.05,4,0.05);
perc=Param("Percentage Range (S/R lines)",20,0.05,100,0.01);
npiv=Param("N Pivots Used (S/R lines)",1,1,250,1);
disp2=ParamToggle("Display S/R levels","Off|On",0);

TimeFrameSet(tfrm);
function vstop_func(trBull,trBear)
{
trailArray[0]=C[0];
for(i=1;i<BarCount;i++)
{
prev=trailArray[i-1];

if(C>prev AND C[i-1]>prev)
{
trailArray=Max(prev,C-trBull);
}
else if(C<prev AND C[i-1]< prev)
{
trailArray=Min(prev,C+trBear);
}
else if (C>prev)
{
trailArray=C-trBull;
}
else
{
trailArray=C+trBear;
}
}
return trailArray;
}

trBull=multBull*ATR(perBull);
trBear=multBear*ATR(perBear);
trailArray = vstop_func(trBull,trBear);
ts=IIf(trailArray>C,trailArray,Null);
tl=IIf(trailArray<C,trailArray,Null);
TimeFrameRestore();

ts=TimeFrameExpand(ts,tfrm,expandLast);
tl=TimeFrameExpand(tl,tfrm,expandLast);

GraphXSpace = 5;
SetChartOptions(0, chartShowDates);
SetBarFillColor(IIf(C>O,ParamColor("Candle Up Color", colorGreen),IIf(C<=O,ParamColor("Candle Down Color", colorRed),colorDarkGreen)));
Plot(C,"Price",IIf(C>O,ParamColor("Shadow Up Color", colorGreen),IIf(C<=O,ParamColor("Shadow Color", ColorRGB(255,0,0)),colorGreen)),64,0,0,0,0,1);

lll=LLV(L,BarsSince(!IsEmpty(tl)));lll=IIf(ts,lll,Null);llls=lll;
ttt1=IIf((!IsEmpty(ts) AND IsEmpty(Ref(ts,1))) OR BarIndex()==BarCount-1,1,Null);
ttt=ValueWhen(ttt1,lll,0);ttt=IIf(ts,ttt,Null);ttt=IIf(ttt1,Ref(ttt,-1),ttt);
tr=L==ttt;lll=Sum(tr,BarsSince(!IsEmpty(tl)));
qqq=ValueWhen(ttt1,lll,0);qqq=IIf(ts,qqq,Null);qqq=IIf(ttt1,Ref(qqq,-1),qqq);tr=tr AND lll==qqq;
tr=IIf((!IsEmpty(ts) AND IsEmpty(Ref(ts,1)) AND IsEmpty(Ref(ts,-1))),1,tr);//exception
hhh=HHV(H,BarsSince(!IsEmpty(ts)));hhh=IIf(tl,hhh,Null);hhhs=hhh;
ttt1=IIf((!IsEmpty(tl) AND IsEmpty(Ref(tl,1))) OR BarIndex()==BarCount-1,1,Null);
ttt=ValueWhen(ttt1,hhh,0);ttt=IIf(tl,ttt,Null);ttt=IIf(ttt1,Ref(ttt,-1),ttt);
pk=H==ttt;hhh=Sum(pk,BarsSince(!IsEmpty(ts)));
sss=ValueWhen(ttt1,hhh,0);sss=IIf(tl,sss,Null);sss=IIf(ttt1,Ref(sss,-1),sss);pk=pk AND hhh==sss;
pk=IIf((!IsEmpty(tl) AND IsEmpty(Ref(tl,1)) AND IsEmpty(Ref(tl,-1))),1,pk);//exception

px0=ValueWhen(pk,x,0); tx0=ValueWhen(tr,x,0);
px1=ValueWhen(pk,x,1); tx1=ValueWhen(tr,x,1);
px2=ValueWhen(pk,x,2); tx2=ValueWhen(tr,x,2);
ph0=ValueWhen(pk,H,0); tl0=ValueWhen(tr,L,0);
ph1=ValueWhen(pk,H,1); tl1=ValueWhen(tr,L,1);
ph2=ValueWhen(pk,H,2); tl2=ValueWhen(tr,L,2);

minipk=H>=Ref(HHV(H,1),-1) AND Ref(HHV(H,1),1)<H;
minitr=L<=Ref(LLV(L,1),-1) AND Ref(LLV(L,1),1)>L;

switch(tc)
{
case("ZIG"):
aa1=IIf(px0>tx1,(ph0-tl1)/(px0-tx1),0);aa1=IIf(pk,Ref(aa1,-1),aa1);ls1=aa1*(xx-tx1)+tl1;
bb1=IIf(px0>tx1 AND px1<tx1,1,0);bb1=bb1+Ref(bb1,-1);bb1=IIf(bb1,1,0);ls1=IIf(bb1,ls1,Null);
Plot(ls1,"",colorBlue,styleLine,0,0,0,2,3);
aa1=IIf(tx0>px1,(tl0-ph1)/(tx0-px1),0);aa1=IIf(tr,Ref(aa1,-1),aa1);ls1=aa1*(xx-px1)+ph1;
bb1=IIf(tx0>px1 AND tx1<px1,1,0);bb1=bb1+Ref(bb1,-1);bb1=IIf(bb1,1,0);ls1=IIf(bb1,ls1,Null);
Plot(ls1,"",colorOrange,styleLine,0,0,0,2,3);
break;
case("VSTOP"):
Plot(ts,"\ntrailShort",colorRed,styleLine,0,0,0,1,1);
Plot(llls,"",colorRed,styleDashed,0,0,0,1,1);
Plot(tl,"\ntrailLong",colorGreen,styleLine,0,0,0,1,1);
Plot(hhhs,"",colorGreen,styleDashed,0,0,0,1,1);
break;
case("ZIG&VSTOP"):
aa1=IIf(px0>tx1,(ph0-tl1)/(px0-tx1),0);aa1=IIf(pk,Ref(aa1,-1),aa1);ls1=aa1*(xx-tx1)+tl1;
bb1=IIf(px0>tx1 AND px1<tx1,1,0);bb1=bb1+Ref(bb1,-1);bb1=IIf(bb1,1,0);ls1=IIf(bb1,ls1,Null);
Plot(ls1,"",colorBlue,styleLine,0,0,0,2,3);
aa1=IIf(tx0>px1,(tl0-ph1)/(tx0-px1),0);aa1=IIf(tr,Ref(aa1,-1),aa1);ls1=aa1*(xx-px1)+ph1;
bb1=IIf(tx0>px1 AND tx1<px1,1,0);bb1=bb1+Ref(bb1,-1);bb1=IIf(bb1,1,0);ls1=IIf(bb1,ls1,Null);
Plot(ls1,"",colorOrange,styleLine,0,0,0,2,3);
Plot(ts,"\ntrailShort",colorRed,styleLine,0,0,0,1,1);
Plot(llls,"",colorRed,styleDashed,0,0,0,1,1);
Plot(tl,"\ntrailLong",colorGreen,styleLine,0,0,0,1,1);
Plot(hhhs,"",colorGreen,styleDashed,0,0,0,1,1);
break;
}

PlotShapes(shapeSmallCircle*tr,colorGreen,0,L,-10);
PlotShapes(shapeSmallCircle*pk,colorRed,0,H,10);

qq=Interval()/60;
if(qq < 60){tf=" min";tt=qq;}
else if(qq >= 60 AND qq < 1440){tf=" hrs";tt=qq/60;}
else if(qq >= 1440){tf=" days";tt=(qq/60)/24;}
qq=Max(tfrm/60,Interval()/60);
if(qq < 60){tfa=" min";tta=qq;}
else if(qq >= 60 AND qq < 1440){tfa=" hrs";tta=qq/60;}
else if(qq >= 1440){tfa=" days";tta=(qq/60)/24;}

Title = Name() +
"\nChart TF: " + tt + tf +
"\nZig TF: " + tta + tfa;

dxhm=14;dxlm=10;dxh=0;dxl=0;dyhm=5;dylm=3;dyh=18;dyl=29;hm=30;lm=30;
dyl2=42;dylm2=16;dyhm2=18;dyh2=31;
function GetVisibleBarCount()
{
lvb=Status("lastvisiblebar");
fvb=Status("firstvisiblebar");
return Min(lvb-fvb,BarCount-fvb);
}
function GfxConvertPixelsToBarX(Pixels)
{
lvb=Status("lastvisiblebar");
fvb=Status("firstvisiblebar");
pxchartleft=Status("pxchartleft");
pxchartwidth=Status("pxchartwidth");
fac=pxchartwidth/Pixels;
bar=(lvb-fvb)/fac;
return bar;
}
function GfxConvertPixelToValueY(Pixels)
{
local Miny,Maxy,pxchartbottom,pxchartheight;
Miny=Status("axisminy");
Maxy=Status("axismaxy");
pxchartbottom=Status("pxchartbottom");
pxchartheight=Status("pxchartheight");
fac=pxchartheight/Pixels;
Value=(Maxy-Miny)/fac;
return Value;
}

ll=tr AND tl1<tl2;
hl=tr AND tl1>tl2;
hh=pk AND ph1>ph2;
lh=pk AND ph1<ph2;
dt=pk AND ph1==ph2;
db=tr AND tl1==tl2;

miny=Status("axisminy");
maxy=Status("axismaxy");
AllVisibleBars=GetVisibleBarCount();
fvb=Status("firstvisiblebar");
LowMargin=Miny+GfxConvertPixelToValueY(lm);
HighMargin=Maxy-GfxConvertPixelToValueY(hm);
dyllm=GfxConvertPixelToValueY(dylm);
dyhhm=GfxConvertPixelToValueY(dyhm);
dyll=GfxConvertPixelToValueY(dyl);
dyhh=GfxConvertPixelToValueY(dyh);
dxllm=GfxConvertPixelsToBarX(dxlm);
dxhhm=GfxConvertPixelsToBarX(dxhm);
dxll=GfxConvertPixelsToBarX(dxl);
dxhh=GfxConvertPixelsToBarX(dxh);

dyllm2=GfxConvertPixelToValueY(dylm2);
dyll2=GfxConvertPixelToValueY(dyl2);
dyhhm2=GfxConvertPixelToValueY(dyhm2);
dyhh2=GfxConvertPixelToValueY(dyh2);

if(disp0)
{
for(i=0;i<AllVisibleBars;i++)
{
// HH,HL etc. labels
if(ll[i+fvb] AND L[i+fvb]>LowMargin) PlotText("LL",i+fvb+dxll,L[i+fvb]-dyll,colorWhite,colorDefault);
if(ll[i+fvb] AND L[i+fvb]<=LowMargin) PlotText("LL",i+fvb+dxll+dxllm,L[i+fvb]-dyllm,colorWhite,colorDefault);
if(hl[i+fvb] AND L[i+fvb]>LowMargin) PlotText("HL",i+fvb+dxll,L[i+fvb]-dyll,colorWhite,colorDefault);
if(hl[i+fvb] AND L[i+fvb]<=LowMargin) PlotText("HL",i+fvb+dxll+dxllm,L[i+fvb]-dyllm,colorWhite,colorDefault);
if(db[i+fvb] AND L[i+fvb]>LowMargin) PlotText("DB",i+fvb+dxll,L[i+fvb]-dyll,colorWhite,colorDefault);
if(db[i+fvb] AND L[i+fvb]<=LowMargin) PlotText("DB",i+fvb+dxll+dxllm,L[i+fvb]-dyllm,colorWhite,colorDefault);
if(hh[i+fvb] AND H[i+fvb]<HighMargin) PlotText("HH",i+fvb+dxhh,H[i+fvb]+dyhh,colorWhite,colorDefault);
if(hh[i+fvb] AND H[i+fvb]>=HighMargin) PlotText("HH",i+fvb+dxhh+dxhhm,H[i+fvb]+dyhhm,colorWhite,colorDefault);
if(lh[i+fvb] AND H[i+fvb]<HighMargin) PlotText("LH",i+fvb+dxhh,H[i+fvb]+dyhh,colorWhite,colorDefault);
if(lh[i+fvb] AND H[i+fvb]>=HighMargin) PlotText("LH",i+fvb+dxhh+dxhhm,H[i+fvb]+dyhhm,colorWhite,colorDefault);
if(dt[i+fvb] AND H[i+fvb]<HighMargin) PlotText("DT",i+fvb+dxhh,H[i+fvb]+dyhh,colorWhite,colorDefault);
if(dt[i+fvb] AND H[i+fvb]>=HighMargin) PlotText("DT",i+fvb+dxhh+dxhhm,H[i+fvb]+dyhhm,colorWhite,colorDefault);
}
}
if(disp1)
{
for(i=0;i<AllVisibleBars;i++)
{
// value labels at HH,HL etc.
if(ll[i+fvb] AND L[i+fvb]>LowMargin) PlotText(""+L[i+fvb],i+fvb+dxll,L[i+fvb]-dyll2,colorWhite,colorDefault);
if(ll[i+fvb] AND L[i+fvb]<=LowMargin) PlotText(""+L[i+fvb],i+fvb+dxll+dxllm,L[i+fvb]-dyllm2,colorWhite,colorDefault);
if(hl[i+fvb] AND L[i+fvb]>LowMargin) PlotText(""+L[i+fvb],i+fvb+dxll,L[i+fvb]-dyll2,colorWhite,colorDefault);
if(hl[i+fvb] AND L[i+fvb]<=LowMargin) PlotText(""+L[i+fvb],i+fvb+dxll+dxllm,L[i+fvb]-dyllm2,colorWhite,colorDefault);
if(db[i+fvb] AND L[i+fvb]>LowMargin) PlotText(""+L[i+fvb],i+fvb+dxll,L[i+fvb]-dyll2,colorWhite,colorDefault);
if(db[i+fvb] AND L[i+fvb]<=LowMargin) PlotText(""+L[i+fvb],i+fvb+dxll+dxllm,L[i+fvb]-dyllm2,colorWhite,colorDefault);
if(hh[i+fvb] AND H[i+fvb]<HighMargin) PlotText(""+H[i+fvb],i+fvb+dxhh,H[i+fvb]+dyhh2,colorWhite,colorDefault);
if(hh[i+fvb] AND H[i+fvb]>=HighMargin) PlotText(""+H[i+fvb],i+fvb+dxhh+dxhhm,H[i+fvb]+dyhhm2,colorWhite,colorDefault);
if(lh[i+fvb] AND H[i+fvb]<HighMargin) PlotText(""+H[i+fvb],i+fvb+dxhh,H[i+fvb]+dyhh2,colorWhite,colorDefault);
if(lh[i+fvb] AND H[i+fvb]>=HighMargin) PlotText(""+H[i+fvb],i+fvb+dxhh+dxhhm,H[i+fvb]+dyhhm2,colorWhite,colorDefault);
if(dt[i+fvb] AND H[i+fvb]<HighMargin) PlotText(""+H[i+fvb],i+fvb+dxhh,H[i+fvb]+dyhh2,colorWhite,colorDefault);
if(dt[i+fvb] AND H[i+fvb]>=HighMargin) PlotText(""+H[i+fvb],i+fvb+dxhh+dxhhm,H[i+fvb]+dyhhm2,colorWhite,colorDefault);
}
}
if(disp2)
{
miny=LastVisibleValue(C)-LastVisibleValue(C)/100*perc;
maxy=LastVisibleValue(C)+LastVisibleValue(C)/100*perc;
for (i=1;i<=npiv;i++)
{
rr=ValueWhen(pk,H,i);
rr=IIf(rr>maxy OR rr<miny,Null,rr);
ss=ValueWhen(tr,L,i);
ss=IIf(ss>maxy OR ss<miny,Null,ss);
Plot(rr,"",colorBlue,styleNoLine|styleDots,0,0,0,-1);
Plot(ss,"",colorRed,styleNoLine|styleDots,0,0,0,-1);
}
}

_SECTION_BEGIN("");
dH1= TimeFrameGetPrice("H",inDaily,-1);
dL1= TimeFrameGetPrice("L",inDaily,-1);
yrng=(dH1-dL1);
rrp=Optimize("room%",Param("room%",0.2,0.3),1,0.2, 0.3);
room=(yrng*rrp)/100;

today=Day()==LastValue(Day());

Plot(IIf(today,dh1+room,Null),"",colorGreen, styleDashed,8);
Plot(IIf(today,dl1-room,Null),"",colorRed,styleDashed,8);

Buy = room > dH1;
Sell = room < dL1;
Filter = (dH1 > 0) OR (dL1 > 0);

SetOption("NoDefaultColumns", True);
AddColumn(DateTime(), "DATE", formatDateTime,colorDefault, colorDefault, 80);
AddTextColumn(Name(), "SYMBOL", 77);

AddColumn(IIf(dH1, 48 + dH1, 32), "BUY", formatChar, colorYellow, IIf(dH1, colorLightBlue, colorDefault));
AddColumn(IIf(dL1, 48 + dL1, 32), "SELL", formatChar, colorYellow, IIf(dL1, colorBlue, colorDefault));

_SECTION_END();




//Copyright Kamalesh Langote. Email:[email protected] Visit http://www.vfmdirect.com/kplswing for latest code and updates
//Save indicator as "kplswing.afl" in C: program files > Amibroker > Formulas > Custom folder and then double click indicator.
//The indicator will now load in a seperate pane/window
//Default value of N is 20. You can change this via the Parameters dialog box



_SECTION_BEGIN("KPL Swing");
no=Param( "Swing", 20, 1, 100 );

res=HHV(H,no);
sup=LLV(L,no);
avd=IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0));
avn=ValueWhen(avd!=0,avd,1);
tsl=IIf(avn==1,sup,res);

// line code
Plot(tsl, _DEFAULT_NAME(), colorBlack,styleDots,styleThick,styleStaircase);

// ribbon code
Plot( 2, "Ribbon",IIf(C>tsl,colorGreen,colorRed),styleOwnScale|styleArea|styleNoLabel, -1.25, 100 );

// arrows code
Buy=Cross(C,Ref(res,-1));
Sell=Cross(Ref(sup,-1),C);
shape=Buy*shapeUpTriangle + Sell*shapeDownTriangle;
PlotShapes(shape,colorBlack,0,IIf(Buy,Low,High));

_SECTION_END();

//AFL by Kamalesh Langote. Email:[email protected]
no=Param( "Swing", 5, 1, 55 );
tsl_col=ParamColor( "Color", colorCycle );

res=HHV(H,no);
sup=LLV(L,no);
avd=IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0));
avn=ValueWhen(avd!=0,avd,1);
tsl=IIf(avn==1,sup,res);
Buy=Cross(C,tsl) ;
Sell= Cross(tsl,C) ;
// arrows code
Buy=Cross(C,Ref(res,-1));
Sell=Cross(Ref(sup,-1),C);
shape=Buy*shapeUpArrow + Sell*shapeDownArrow;
PlotShapes(shape,colorWhite,0,IIf(Buy,Low,High));
// line code
Plot(tsl, _DEFAULT_NAME(), colorGrey50,styleDashed|styleStaircase);
shape=Buy*shapeHollowUpArrow + Sell*shapeHollowDownArrow;
PlotShapes(shape,colorGrey50,0,IIf(Buy,Low,High));

// ribbon code
Plot( 1, "Ribbon",IIf(C>tsl,colorBlue,colorRed),styleOwnScale|styleArea|styleNoLabel, -2.25, 50 );


_SECTION_BEGIN("Fibo for all bars");

TimeFrameSet( in15Minute*26 );
DH=Ref(H,-1);
DL=Ref(L,-1);
DC=Ref(C,-1);


pd = ( DH+ DL + DC )/3;
sd1 = (2*pd)-DH;
sd2 = pd -(DH - DL);
sd3 = Sd1 - (DH-DL);
rd1 = (2*pd)-DL;
rd2 = pd +(DH -DL);
rd3 = rd1 +(DH-DL);



TimeFrameRestore();


Title = EncodeColor(colorBlack)+ "KPL 5 - 20 Cross" + " - " + Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorBlack) +
" - " + Date() +" - "+"Op-"+O+" "+"Hi-"+H+" "+"Lo-"+L+" "+ "Cl-"+C+" "
+ WriteIf(C > pd, EncodeColor(colorGreen)+"stay long",EncodeColor(colorRed)+"stay SHORT") + "\n"
+ "Vol= "+ WriteVal(V) +WriteIf ( V > MA(V,26) ,EncodeColor(colorGreen)+" UP "+ (V/MA(V,26))*100 + " %", EncodeColor(colorRed)+" DOWN "+ (V/MA(V,26))*100 + " %")
+ EncodeColor(colorGreen)+ "\n R3 : "+ EncodeColor(colorGreen)+RD3
+ EncodeColor(colorGreen)+ "\n R2 : "+ EncodeColor(colorGreen)+RD2
+ EncodeColor(colorGreen)+ "\n R1 : "+ EncodeColor(colorGreen)+RD1
+ EncodeColor(colorBlue)+ "\n Pivot : "+ EncodeColor(colorBlue)+pd
+ EncodeColor(colorRed)+ "\n S1 : "+ EncodeColor(colorRed)+SD1
+ EncodeColor(colorRed)+ "\n S2 : "+ EncodeColor(colorRed)+SD2
+ EncodeColor(colorRed)+ "\n S3 : "+ EncodeColor(colorRed)+SD3
;

//Unlike floor pivots,we also call them classic pivots, there is no pivot but 8 levels in Camarilla eq.
PTF = ParamList("Time Frame",List = "Hourly,4 Hour,Daily,Weekly",2);
TF = IIf(PTF == "Hourly",inHourly, IIf(PTF == "4 Hour",inHourly*4, IIf(PTF == "Daily",inDaily,
IIf(PTF == "Weekly",inWeekly,0))));
Today = LastValue(Day());
Ho =TimeFrameGetPrice( "H", tf, -1, expandFirst) ;
Lo = TimeFrameGetPrice( "L", tf, -1, expandFirst) ;
Co = TimeFrameGetPrice( "C", tf, -1, expandFirst) ;

Range=Ho-Lo;

H4=Co+1.1* RANGE/2 ;
H3=Co+1.1*RANGE/4;
H2=Co+1.1*RANGE/6;
H1=Co+1.1* RANGE/12;

L1=Co-1.1*RANGE/12;
L2=Co-1.1*RANGE/6;
L3=Co-1.1*RANGE/4;
L4=Co-1.1*RANGE/2;

//I use 2 more levels to take care of gap-ups AND gap downs-


//Plot(IIf(Today == Day(), H5, Null),"", colorDarkGreen,styleDots|styleNoLabel|styleNoRescale );
Plot(IIf(Today == Day(), H4, Null),"", colorGreen,styleThick|styleNoLabel|styleNoRescale );
Plot(IIf(Today == Day(), H3, Null),"", colorRed,styleThick|styleNoLabel|styleNoRescale );
//Plot(IIf(Today == Day(), H2, Null),"", colorLime,styleDashed|styleNoLabel|styleNoRescale );
//Plot(IIf(Today == Day(), H1, Null),"", colorOrange,styleLine|styleNoLabel|styleNoRescale );

//Plot(IIf(Today == Day(), L1, Null),"", colorRed,styleLine|styleNoLabel|styleNoRescale );
//Plot(IIf(Today == Day(), L2, Null),"", colorLightOrange,styleDashed|styleNoLabel|styleNoRescale );
Plot(IIf(Today == Day(), L3, Null),"", colorGreen,styleThick|styleNoLabel|styleNoRescale );
Plot(IIf(Today == Day(), L4, Null),"", colorRed,styleThick|styleNoLabel|styleNoRescale );
//Plot(IIf(Today == Day(), L5, Null),"", colorDarkRed,styleDots|styleNoLabel|styleNoRescale );

//Plot(IIf(Today == Day(), HO, Null),"yH",7,8+16);

//Plot(IIf(Today == Day(), LO, Null),"yL",7,8+16);
C11=ParamColor("Text col",colorTan );
numbars = LastValue(Cum(Status("barvisible")));
fraction= IIf(StrRight(Name(),3) == "", 3.2, 3.2);
hts = Param ("Text Shift", -50,-100,100,10);

//PlotText("Y'high = " + WriteVal(Ho,fraction),
//LastValue(BarIndex())-(numbars/hts+30),LastValue (Ho,1) , 7);
//PlotText("Y'low = " + WriteVal(lO,fraction),
//LastValue(BarIndex())-(numbars/hts+30),LastValue (lO,1) , 7);


//PlotText("H4 = " + WriteVal(h4,fraction),
//LastValue(BarIndex())-(numbars/hts),LastValue (h4,1) , C11);
//PlotText("H3 = " + WriteVal(h3,fraction),
//LastValue(BarIndex())-(numbars/hts),LastValue (h3,1) , C11);
//PlotText("H2 = " + WriteVal(H2,fraction),
//LastValue(BarIndex())-(numbars/hts),LastValue (H2,1) , C11);
//PlotText("H1 = " + WriteVal(H1,fraction),
//LastValue(BarIndex())-(numbars/hts),LastValue (H1,1) , C11);

//PlotText("L4 = " + WriteVal(l4,fraction),
//LastValue(BarIndex())-(numbars/hts),LastValue (l4,1) , C11);
//PlotText("L3 = " + WriteVal(l3,fraction),
//LastValue(BarIndex())-(numbars/hts),LastValue (l3,1) ,C11);
//PlotText("L2 = " + WriteVal(L2,fraction),
//LastValue(BarIndex())-(numbars/hts),LastValue (L2,1) , C11);
//PlotText("L1 = " + WriteVal(L1,fraction),
//LastValue(BarIndex())-(numbars/hts),LastValue (L1,1) , C11);


_SECTION_END();



_____________________________________
 

vishal7176

Well-Known Member
#6
@ happy sigh and all senior

i am new to amibroker .

i have got afl from pratap sir , thread butt i dont know how to use it . even i dont know ...where in amibroker save it .

how to copy paste from traderji to amibroker .....

can you help me regarding this ...plsss ..

i am totally new about AFL , i DONT know
how to save it and where to save it ......in which folder save afl and ....how to open it .......can you guide me sir .....

plsss

thaank you sir
 

Similar threads

Broker Special Offers

Intraday Higher Leverage

Save up to 90% in brokerage and get higher leverage for intraday trades.

Name:Phone:
Email:City:
State:
Are you a day trader?