AFL coding help needed

srichakra

Active Member
#1
Hi AFL experts,

I use the following nbar AFL which will print an arrow on candles that have a close above last 4 bars .I need help to change the colour of the bars to green when the TRENDUP is printed and all subsequent bars to be green until the TRENdown occurs when candles will turn RED until the signal changes.

n= Param("No. of Bars",4,2,8,1);
TrendUp = C > Ref(HHV(H,n),-1);
TrendDn = C < Ref(LLV(L,n),-1);
TrendUp = ExRem(TrendUp,TrendDn);
TrendDn = ExRem(TrendDn,TrendUp);
PlotShapes(TrendUp*shapeUpArrow,colorGreen);
PlotShapes(TrendDn*shapeDownArrow,colorRed);

Buy= TrendUp;
Sell = TrendDn;
Short=TrendDn;
Cover= TrendUp;

My experience with Amibroker is only few weeks and could not solve this requirement. I greatly appreciate your effort and thank you in advance. I am experimenting by combining with other signals and hence looking for this solution.
 

sr114

Well-Known Member
#2
Hi AFL experts,

I use the following nbar AFL which will print an arrow on candles that have a close above last 4 bars .I need help to change the colour of the bars to green when the TRENDUP is printed and all subsequent bars to be green until the TRENdown occurs when candles will turn RED until the signal changes.

n= Param("No. of Bars",4,2,8,1);
TrendUp = C > Ref(HHV(H,n),-1);
TrendDn = C < Ref(LLV(L,n),-1);
TrendUp = ExRem(TrendUp,TrendDn);
TrendDn = ExRem(TrendDn,TrendUp);
PlotShapes(TrendUp*shapeUpArrow,colorGreen);
PlotShapes(TrendDn*shapeDownArrow,colorRed);

Buy= TrendUp;
Sell = TrendDn;
Short=TrendDn;
Cover= TrendUp;

My experience with Amibroker is only few weeks and could not solve this requirement. I greatly appreciate your effort and thank you in advance. I am experimenting by combining with other signals and hence looking for this solution.
use this
HTML:
  n= Param("No. of Bars",4,2,8,1);
 TrendUp = C > Ref(HHV(H,n),-1);
 TrendDn = C < Ref(LLV(L,n),-1);
 TrendUp = ExRem(TrendUp,TrendDn);
 TrendDn = ExRem(TrendDn,TrendUp);

 Buy= TrendUp;
 Sell = TrendDn;
 Short=TrendDn;
 Cover= TrendUp;

 PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), colorGreen, layer = 0,yposition = Low, offset = -20);
 PlotShapes( IIf( Sell, shapeDownArrow, shapeNone ), colorRed, layer = 0, yposition = High, offset = -20); 

 TrendUp = Flip(TrendUp,TrendDn);
 TrendDn = Flip(TrendDn,TrendUp);

 Plot(C,"CLose",IIf(trendup,colorGreen,colorRed),64);
rgds
subroto
 
Last edited:

Val8

New Member
#3
Hello sr114,

I have no trouble doing the daily/weekly with multiTimeframe afl. However I have trouble tweaking the trendlines like you did...

Would you give me more hints?
 

sr114

Well-Known Member
#4
Hello sr114,

I have no trouble doing the daily/weekly with multiTimeframe afl. However I have trouble tweaking the trendlines like you did...

Would you give me more hints?
Val

can u elaborate a bit more - what u want to do with the trenlines?

rgds
subroto
 

Val8

New Member
#5


This is the one. I have trouble plotting the red and green trendlines like you did.

I understand it's from 2 afl's

Val
 

sr114

Well-Known Member
#7


This is the one. I have trouble plotting the red and green trendlines like you did.

I understand it's from 2 afl's

Val
the trendline to be plotted are coded - u only have to define the color ( ED had done it in the code)

rgds
subroto
 
#9
hi subrotojee
one request.

I saw the trendup and trenddown green and red candles with buy sell arrows. it is good.
I need one extra code line.If you can find time,please add it to the code
what is needed
when a green arrow for buy comes up,a stopline to be plotted at low of that entry bar minus 3 units.
when a red sell arrow appears,a stopline need to be plotted at high of the shortsignal bar +3


can you please help with these two lines!

the code I haVE IS HERE

HTML:
//trendup or down based on n bar hhv or llv BY SUBROTO
 n= Param("No. of Bars",4,2,8,1);
 TrendUp = C > Ref(HHV(H,n),-1);
 TrendDn = C < Ref(LLV(L,n),-1);
 TrendUp = ExRem(TrendUp,TrendDn);
 TrendDn = ExRem(TrendDn,TrendUp);

 Buy= TrendUp;
 Sell = TrendDn;
 Short=TrendDn;
 Cover= TrendUp;

 PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), colorGreen, layer = 0,yposition = Low, offset = -20);
 PlotShapes( IIf( Sell, shapeDownArrow, shapeNone ), colorRed, layer = 0, yposition = High, offset = -20); 

 TrendUp = Flip(TrendUp,TrendDn);
 TrendDn = Flip(TrendDn,TrendUp);
 dynacolor=IIf(trendup,colorGreen,colorRed);
 SetBarFillColor(dynacolor);
 Plot(C,"CLose",IIf(trendup,colorGreen,colorRed),64);
Plot(Trendup,"Trendup",colorBlue,styleOwnScale,styleDashed);
Plot(TrendDn,"TrendDn",colorCustom12,styleOwnScale,styleDashed);
best regards
ford
 
#10
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
SetBarsRequired(sbrAll,sbrAll);
SetBarFillColor(IIf(C>O,ParamColor("Candle Up Color", colorBrightGreen),IIf(C<=O,ParamColor("Candle Down Color", colorRed),colorLightGrey)));
Plot(C,"Price",IIf(C>O,ParamColor("Shadow Up Color", colorBlack),IIf(C<=O,ParamColor("Shadow Down Color", colorBlack),colorLightGrey)),64,0,0,0,0);
SetChartBkColor(ParamColor("Panel Color ",colorLightGrey));
SetChartBkGradientFill(ParamColor("Upper Chart",colorLightGrey),ParamColor("Lower Chart",colorLightGrey));

grid_day = IIf(Day()!=Ref(Day(),-1),1,0);
Plot(grid_day,"",colorWhite,styleHistogram|styleDots|styleNoLabel|styleOwnScale);


_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("Price Color", colorBlack ), styleNoTitle | ParamStyle("Price Style") | GetPriceStyle() );


_SECTION_END();

SetChartBkColor( ParamColor( "Outer panel",colorWhite) );
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxx

_SECTION_BEGIN("trend");


Length = Param("Length",20,1,100,1);

Change = Close - Ref(Close, -1);
PlusChange = IIf(Change > 0, Change, 0);
MinusChange = IIf(Change < 0, -Change, 0);

EnableScript("jscript");
<%
PlusChange=VBArray(AFL("PlusChange")).toArray();
MinusChange=VBArray(AFL("MinusChange")).toArray();

/*Make two new arrays*/
var PlusCF=new Array ();
var MinusCF=new Array();

/*fill array "PlusCF"*/
for (i=0; i<PlusChange.length; i++ )
{
if ( PlusChange==0 ) { PlusCF=0; }
else { PlusCF=PlusChange+PlusCF[i-1]; }
}

/*Fill array "MinusCF*/
for (i=0; i<MinusChange.length; i++ )
{
if ( MinusChange==0 ) { MinusCF=0; }
else { MinusCF=MinusChange+MinusCF[i-1]; }
}

/*Convert to AFL variables*/
AFL("PlusCF")=PlusCF;
AFL("MinusCF")=MinusCF;
%>

PlusTCF = Sum(PlusChange-MinusCF,Length);
MinusTCF = Sum(MinusChange-PlusCF,Length);

//Plot(PlusTCF, "+TFC("+Length+")", colorGreen);
//Plot(MinusTCF, "-TFC("+Length+")", colorRed);
//PlotGrid(0, colorLightGrey);

Buy=PlusTCF>0;
Sell=MinusTCF>0;
Short=Sell;
Cover=Buy;

/*This is optional*/
ApplyStop(2,1,Optimize("Stop Loss",12,1,15,1),1);

Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Cover=ExRem(Cover,Short);
Short=ExRem(Short,Cover);

for( i = 0; i < BarCount; i++ )
{

if( Buy >= 0 )
{
PlotText( "Buy\n@" + C[ i ], i, colorGreen,colorYellow );
}
if( Sell >= 0 )
{
PlotText( "Sell\n@" + C[ i ], i, colorRed, colorYellow );
}

}

_SECTION_END();



pls any help to plot the buy and sell arrows
 

Similar threads