Simple Coding Help - No Promise.

Nehal_s143

Well-Known Member
Dear Sir,
I am new to AFL and trying to learn. Pl. any friend can help to correct this AFL.The mistake is starting from // EMA line.
Regards.
nms

_SECTION_BEGIN("EMA3 + EMA15 Cross");

EMA5_LineShow = ParamToggle("EMA3 Line", "Hide|Show",1);
EMA15_LineShow = ParamToggle("EMA15 Line", "Hide|Show",1);
CrossArrow_EMA3EMA15 = ParamToggle("CrossArrow-EMA3+EMA15", "Hide|Show",1);
EMA3LineColor = ParamColor("EMA3 Color", colorRose);
EMA15LineColor = ParamColor("EMA15 Color", colorTeal);
BuyTextColor = ParamColor("Buy Text", colorBrightGreen);
SellTextColor = ParamColor("Sell Text", colorRed);
SellTextBgr = ParamColor("Sell Text Bg", colorYellow);
BuyEMA3EMA15 = ParamColor("Buy Arrow", colorBrightGreen);
SellEMA3EMA15 = ParamColor("Sell Arrow", colorLightYellow);

//EMA Line

if(EMA3EMA15 == 0 || EMA3_LineShow == 0) {
Plot(EMA(Close,3),"EMA3 Line",EMA3LineColor, styleLine);
}


if(EMA3EMA15 == 0 || EMA30_LineShow == 0) {
Plot(EMA(Close,15),"EMA15 Line",EMA15LineColor, styleLine);
}


//CrossArrow_EMA3_EMA15

if(EMA3EMA15 == 0 || CrossArrow_EMA3EMA15 == 0) {

Buy=Cross(EMA(Close,3), EMA(Close,15));
Sell=Cross(EMA(Close,15), EMA(Close,3));

dist = 1.5*ATR(10);

for( i = 0; i < BarCount; i++ )
{
if( Buy ) PlotText( "Buy\n@" + C[ i ], i, L[ i ]-dist, BuyTextColor );
if( Sell ) PlotText( "Sell\n@" + C[ i ], i, H[ i ]+dist, SellTextColor, SellTextBgr );
}

shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes( shape, IIf( Buy, BuyEMA3EMA15, SellEMA3EMA15 ), 0, IIf( Buy, Low, High ), -30 );
GraphXSpace = 10;
}

_SECTION_END();


This seems to be incomplete code, check the original source of code, EMA3EMA15 is not defined in your above code
 

dell

Well-Known Member
what i am doing here , is :
a condition here i do for getting signals within scronize of 15m tf , but when i switch to my trading tf which is 3min , arrows are not coming ...........where i am making mistake ,help plz
or plz give me a rough idea , how to take signals in 3min charts with taking reference from 15m charts , here our motto is
if buy signal is in 15m charts than we take all buy signals of 3m charts and cover them by using 3min charts ........
similarly if sell signal is generated by 15m charts than we take all sell signals of 3m charts and cover them according to 3m charts ........hope i am able to explain things clearly .....

BuyX= condition1;
SellX=condition2;
ShortX= condition3;
CoverX=condition4;

TimeFrameSet(in1Minute*15);
tbuyx=BuyX;
tsellx=SellX;
tshortx=ShortX;
tcoverx=CoverX;
TimeFrameRestore();

ttbuyx=TimeFrameExpand(tbuyx,in1Minute*15,expandFirst);
ttsellx=TimeFrameExpand(tsellx,in1Minute*15,expandFirst);
ttshortx=TimeFrameExpand(tshortx,in1Minute*15,expandFirst);
ttcoverx=TimeFrameExpand(tcoverx,in1Minute*15,expandFirst);

Buy= condition1 AND ttbuyx;
Sell=condition2 ;
Short= condition3 AND ttshortx;
Cover=condition4;

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

PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorGreen, 0,L, Offset=-20);
PlotShapes(IIf(Sell, shapeHollowStar, shapeNone),colorPink, 0,H, Offset=-45);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorRed, 0,H, Offset=-45);
PlotShapes(IIf(Cover, shapeHollowStar, shapeNone),colorLime, 0,L, Offset=-45);
 
Last edited:

pratapvb

Well-Known Member
what i am doing here , is :
a condition here i do for getting signals within scronize of 15m tf , but when i switch to my trading tf which is 3min , arrows are not coming ...........where i am making mistake ,help plz
or plz give me a rough idea , how to take signals in 3min charts with taking reference from 15m charts , here our motto is
if buy signal is in 15m charts than we take all buy signals of 3m charts and cover them by using 3min charts ........
similarly if sell signal is generated by 15m charts than we take all sell signals of 3m charts and cover them according to 3m charts ........hope i am able to explain things clearly .....

BuyX= condition1;
SellX=condition2;
ShortX= condition3;
CoverX=condition4;

TimeFrameSet(in1Minute*15);
tbuyx=BuyX;
tsellx=SellX;
tshortx=ShortX;
tcoverx=CoverX;
TimeFrameRestore();

ttbuyx=TimeFrameExpand(tbuyx,in1Minute*15,expandFirst);
ttsellx=TimeFrameExpand(tsellx,in1Minute*15,expandFirst);
ttshortx=TimeFrameExpand(tshortx,in1Minute*15,expandFirst);
ttcoverx=TimeFrameExpand(tcoverx,in1Minute*15,expandFirst);

Buy= condition1 AND ttbuyx;
Sell=condition2 ;
Short= condition3 AND ttshortx;
Cover=condition4;

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

PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorGreen, 0,L, Offset=-20);
PlotShapes(IIf(Sell, shapeHollowStar, shapeNone),colorPink, 0,H, Offset=-45);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorRed, 0,H, Offset=-45);
PlotShapes(IIf(Cover, shapeHollowStar, shapeNone),colorLime, 0,L, Offset=-45);
without seeing atleast one of the conditions from condition1 to condition4 diff to say.....but in case condition1...4 is dependent on information of 15min TF ....then there will be a problem as you are using conditionx and ttxxxx in the same statement and they would be of array from diff TFs

I know here you have shown it before Timeframeset...but not sure exactly what it is so diff to comment on exact issue
 

amitrandive

Well-Known Member
Code:
EODOpen = TimeFrameGetPrice("O",inDaily,0);
EODLow  = TimeFrameGetPrice("L",inDaily,0);
EODHigh = TimeFrameGetPrice("H",inDaily,0);

percentage = 0.01 * Param("Percentage",5, 1, 10);

Buy  = Abs(EODOpen  - EODLow) <= percentage * EODOpen;
Sell = Abs(EODOpen - EODHigh) <= percentage * EODOpen;

Filter = Buy OR Sell;

AddColumn(IIf(Buy,BuyPrice,Null)  ," open=low "  ,6.2,1.2,colorGreen);
AddColumn(IIf(Sell,SellPrice,Null)," open= high ",6.2,1.2,colorOrange);
mastermind007

This code does not work in realtime, It gives the same values in both the column of open=high and open=low :confused:

 

dell

Well-Known Member
without seeing atleast one of the conditions from condition1 to condition4 diff to say.....but in case condition1...4 is dependent on information of 15min TF ....then there will be a problem as you are using conditionx and ttxxxx in the same statement and they would be of array from diff TFs

I know here you have shown it before Timeframeset...but not sure exactly what it is so diff to comment on exact issue
yes sir , here condition 1-4 are dependent on 15mtf which are further dependent on hourly and all are dependent on daily so overall there are 4 timeframeset function used for a single condition .......

and if we assume ;
condition 1= ma(20,c)>ma(50,c);
condition2=ma(20,c)<ma(50,c);
condition3=ma(20,c)<ma(50,c);
condition4=ma(20,c)>ma(50,c);
than what will be the procedure pratap sir ,for seeing signals of 15m in 3min ?rough idea will also help sir ....
 

pratapvb

Well-Known Member
yes sir , here condition 1-4 are dependent on 15mtf which are further dependent on hourly and all are dependent on daily so overall there are 4 timeframeset function used for a single condition .......

and if we assume ;
condition 1= ma(20,c)>ma(50,c);
condition2=ma(20,c)<ma(50,c);
condition3=ma(20,c)<ma(50,c);
condition4=ma(20,c)>ma(50,c);
than what will be the procedure pratap sir ,for seeing signals of 15m in 3min ?rough idea will also help sir ....
each condition you convert using timeframeexpand to the chart tf....and then comapare
 

XRAY27

Well-Known Member
hi
please make afl for 20EMA high and LOW (red and green cloud in between this two ema's when price is below and above this ema )
 
Last edited:

amitrandive

Well-Known Member
hi
please make afl for 20EMA high and LOW (red and green cloud in between this two ema's when price is below and above this ema )
Taken from net

Code:
_SECTION_BEGIN("Set Chart");
SetChartBkGradientFill(ParamColor("Inner panel upper", colorBlack), ParamColor("Inner panel lower", colorBlack));
Title =EncodeColor(colorYellow)+ "SWING"+ "-- " + EncodeColor(colorRed)+ "MULTIPLE"+ " "+ EncodeColor(colorBrightGreen)+"MOVING AVERAGES WITH ZIGZAG" +"\n" + EncodeColor(colorWhite)+ "CNBONDRE"+ " - " + FullName() + " - " + EncodeColor(colorYellow)+ Interval(2) + EncodeColor(colorYellow) +
" - " +EncodeColor(colorCustom11)+ Date() +" - "+"-" +EncodeColor(colorAqua) +"  Op="+O+" "+"  Hi="+H+" "+"  Lo="+L+" "+"  Cl="+C+" "+  "  Ch= "+ WriteVal( ROC( C, 1 ),1.2)+"%" + "   Vol="+ WriteVal(V)+"\n";
 
 
StyleList= ParamList("Chart Style", "Candle,Bar");
style =IIf(StyleList== "Candle",styleCandle, styleBar=128);
GreenBar = IIf(C > O, True, False);
RedBar = IIf(C < O, True, False);
BarColor = IIf(GreenBar, colorWhite, IIf(RedBar, colorWhite, colorWhite));
PlotOHLC(O, H, L, C, "", BarColor, style );
_SECTION_END();
 
_SECTION_BEGIN("MA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
m=MA( P, Periods );
_SECTION_END();
 
_SECTION_BEGIN("MA2");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
_SECTION_END();
 
_SECTION_BEGIN("EMA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
s= EMA( P, Periods );
_SECTION_END();
 
 
 
PlotText(" Ch= "+WriteVal(ROC(C,1),1.2)+"%",BarCount,LastValue(C),42);
numBars = BarsSince(DateNum()!=Ref(DateNum(),-1))+1;
PlotText(" \n dm = "+WriteVal    ((m-s)/Ref((m-s),-1))      ,BarCount,LastValue(C),42);
 
_SECTION_BEGIN("Fill Color"); 
Cloudswitch = ParamToggle("Fill Color","On,Off"); 
dynamic_color = IIf( m > s, ParamColor("Down Color", colorGreen ), ParamColor("Up Color", colorRed )); 
PlotOHLC( IIf(Cloudswitch,-1e10,m),IIf(Cloudswitch,-1e10,m),IIf(Cloudswitch,-1e10,s),IIf(Cloudswitch,-1e10,m), "", dynamic_color, styleNoLabel | styleCloud ); 
_SECTION_END();
 

Nehal_s143

Well-Known Member
add this below ur code
hbar1 = H ;
hbar2 = Ref(H,-2) ;
lbar1 = L ;
lbar2 = Ref(L,-2) ;
Buy = IIf( hbar1 > hbar2 AND PFC > PFO ,True,False);
Sell = IIf(lbar1 < lbar2 AND PFC < PFO ,True,False);

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

PlotShapes(shapeSmallUpTriangle * Buy, colorGreen, 0, L -10);
PlotShapes(shapeSmallDownTriangle * Sell, colorOrange, 0, H -10);
Sir I am trying to plot line at buy above level and sell below level, but line is getting plotted at zero

using follow code

PFRES = IIf( hbar1 > hbar2 AND PFC > PFO ,True,False);
Plot(PFRES,"",10,1|styleNoRescale); PlotText( "PFRES : "+PFRES+"", BarCount+2, LastValue(PFRES), 10,1);

PFSUP = IIf(lbar1 < lbar2 AND PFC < PFO ,True,False);
Plot(PFSUP,"",10,1|styleNoRescale); PlotText( "PFSUP : "+PFSUP+"", BarCount+2, LastValue(PFSUP), 10,1);

please correct the error

complete afl

_SECTION_BEGIN("Point and Figure1");
//AFL P&F Chart for Amibroker Indicator window. Based on High/low prices.
//Based on code in AB help files
//Reverse is 3 boxes.

SetBarsRequired(100000,100000);

//Size for P&F boxes
boxsize=IIf(C<0.05, 0.001,
IIf(C>=0.05 AND C<0.1, 0.002,
IIf(C>=0.1 AND C<0.5, 0.005,
IIf(C>=0.5 AND C<2, 0.01,
IIf(C>=2 AND C<5, 0.02,
IIf(C>=5 AND C<10, 0.05,
IIf(C>=10 AND C<50, 0.1,
IIf(C>=50 AND C<100, 0.2,
IIf(C>=100 AND C<200, 0.5,
IIf(C>=200 AND C<500, 1,
2 ))))))))));
Box = LastValue(boxsize);
HX = round((H/box)*10)/10;
LX = round((L/box)*10)/10;
RH = floor(HX);
FL = ceil(LX);


// initialize first element
j = 0;

Reverse = 3; // reversal requirement

PFC[j] = FL[0];
PFO[j] = PFC[j] + 1;
down = 1; // By default the first bar is a down bar.
up = 0;
swap = 0;

// perform the loop that produces PF Chart
for( i = 1; i < BarCount; i++ )
{

if( FL <= PFC[j]-1 && down) //continue down
{
PFC[j] = FL;
PFO[j] = PFC[j] + 1;
}
else
{
if( RH >= PFC[j] + Reverse && down) //Change direction to up
{
j++;
swap = 1;
PFC[j] = RH;
PFO[j] = PFC[j]-1;
}
}
if( RH >= PFC[j] + 1 && up) //Continue up
{
PFC[j] = RH;
PFO[j] = PFC[j] - 1;
}
else
{
if( FL <= PFC[j] - Reverse && up) //Change direction to down
{
j++;
PFC[j] = FL;
PFO[j] = PFC[j] + 1;
swap = 1;
}
}
if( swap )
{
swap = 0;
if( up )
{
up = 0;
down = 1;
}
else
{
up = 1;
down = 0;
}
}
}
delta = BarCount - j-1;


PFO = Ref( PFO, -delta );
PFC = Ref( PFC, -delta );

// High-Low range sets the height of the P&F bar
H = IIf(Ref(PFC,-1)>Ref(PFO,-1),Ref(HHV(PFC,1),-1)-1,Max(PFO,PFC))*Box;
L = IIf(Ref(PFC,-1)<Ref(PFO,-1),Ref(LLV(PFC,1),-1)+1,Min(PFO,PFC))*Box;
O =
IIf(Ref(PFC,-1)>Ref(PFO,-1),Ref(HHV(PFC,1),-1)-1,IIf(Ref(PFC,-1)<Ref(PFO,-1),Ref(LLV(PFC,1),-1)+1,PFO))*Box;

// the difference between Open AND Close should be set to box size
// the sign decides if X or O are plotted
C = O + Box * IIf( PFC > PFO, 1,-1);

GraphXSpace = 2;
Title ="" + Name()+ " PF H: " + H+ ", L: " + L+", Box: "+ box
+ ", Reversal: " + reverse;

Plot( C, "P&F Chart Close", IIf( PFC > PFO, colorBlue, colorRed ),styleCandle+styleNoLabel+stylePointAndFigure);

hbar1 = H ;
hbar2 = Ref(H,-2) ;
lbar1 = L ;
lbar2 = Ref(L,-2) ;
Buy = IIf( hbar1 > hbar2 AND PFC > PFO ,True,False);
Sell = IIf(lbar1 < lbar2 AND PFC < PFO ,True,False);

PFRES = IIf( hbar1 > hbar2 AND PFC > PFO ,True,False);
Plot(PFRES,"",10,1|styleNoRescale); PlotText( "PFRES : "+PFRES+"", BarCount+2, LastValue(PFRES), 10,1);

PFSUP = IIf(lbar1 < lbar2 AND PFC < PFO ,True,False);
Plot(PFSUP,"",10,1|styleNoRescale); PlotText( "PFSUP : "+PFSUP+"", BarCount+2, LastValue(PFSUP), 10,1);

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

PlotShapes(shapeSmallUpTriangle * Buy, colorGreen, 0, L -10);
PlotShapes(shapeSmallDownTriangle * Sell, colorOrange, 0, H -10);

GraphXSpace = 5;
dist = 1.5*ATR(20);

for( i = 0; i < BarCount; i++ )
{
if( Buy ) PlotText( "Buy\n@" + C[ i ], i, L[ i ]-dist, colorLime );
if( Sell ) PlotText( "sell\n@" + C[ i ], i, L[ i ]+dist, colorRed );
}



_SECTION_END();


mypf=IIf( PFC > PFO, colorBlue, colorRed );

Plot(6, "", mypf, styleOwnScale| styleArea|styleNoLabel,-0.5,100);
 
Last edited:

XRAY27

Well-Known Member
Taken from net

Code:
_SECTION_BEGIN("Set Chart");
SetChartBkGradientFill(ParamColor("Inner panel upper", colorBlack), ParamColor("Inner panel lower", colorBlack));
Title =EncodeColor(colorYellow)+ "SWING"+ "-- " + EncodeColor(colorRed)+ "MULTIPLE"+ " "+ EncodeColor(colorBrightGreen)+"MOVING AVERAGES WITH ZIGZAG" +"\n" + EncodeColor(colorWhite)+ "CNBONDRE"+ " - " + FullName() + " - " + EncodeColor(colorYellow)+ Interval(2) + EncodeColor(colorYellow) +
" - " +EncodeColor(colorCustom11)+ Date() +" - "+"-" +EncodeColor(colorAqua) +"  Op="+O+" "+"  Hi="+H+" "+"  Lo="+L+" "+"  Cl="+C+" "+  "  Ch= "+ WriteVal( ROC( C, 1 ),1.2)+"%" + "   Vol="+ WriteVal(V)+"\n";
 


 
StyleList= ParamList("Chart Style", "Candle,Bar");
style =IIf(StyleList== "Candle",styleCandle, styleBar=128);
GreenBar = IIf(C > O, True, False);
RedBar = IIf(C < O, True, False);
BarColor = IIf(GreenBar, colorWhite, IIf(RedBar, colorWhite, colorWhite));
PlotOHLC(O, H, L, C, "", BarColor, style );
_SECTION_END();
 
_SECTION_BEGIN("MA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
m=MA( P, Periods );
_SECTION_END();
 
_SECTION_BEGIN("MA2");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
_SECTION_END();
 
_SECTION_BEGIN("EMA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
s= EMA( P, Periods );
_SECTION_END();
 
 
 
PlotText(" Ch= "+WriteVal(ROC(C,1),1.2)+"%",BarCount,LastValue(C),42);
numBars = BarsSince(DateNum()!=Ref(DateNum(),-1))+1;
PlotText(" \n dm = "+WriteVal    ((m-s)/Ref((m-s),-1))      ,BarCount,LastValue(C),42);
 
_SECTION_BEGIN("Fill Color"); 
Cloudswitch = ParamToggle("Fill Color","On,Off"); 
dynamic_color = IIf( m > s, ParamColor("Down Color", colorGreen ), ParamColor("Up Color", colorRed )); 
PlotOHLC( IIf(Cloudswitch,-1e10,m),IIf(Cloudswitch,-1e10,m),IIf(Cloudswitch,-1e10,s),IIf(Cloudswitch,-1e10,m), "", dynamic_color, styleNoLabel | styleCloud ); 
_SECTION_END();
hi
Amitrandive ji
This is not working for my requirement
 

Similar threads