Simple Coding Help - No Promise.

mastermind007

Well-Known Member
Hi,

I am not very proud of calling myself a techie after trying to get this for whole of yesterday. Any help is appreciated.

I am using this on intraday data. And set the range to 1 recent day

Objective: Want to run this at 10 am to find if the first half hour is a Full Green Candle or Full Black Candle.

Filter = DateNum() > 1140101;

_SECTION_BEGIN( "Open Drive1" );


TimeFrameSet( 2*in15Minute );

Lo = TimeFrameGetPrice( "L", 2*in15Minute, -1 );
Hi = TimeFrameGetPrice( "H", 2*in15Minute,-1 );
Ope = TimeFrameGetPrice( "0", 2*in15Minute,-1 );
Clo = TimeFrameGetPrice( "C", 2*in15Minute, -1 );


Buy = ( ( Clo > Ope ) AND ( ( Clo - Ope ) / ( .001 + Hi - Lo ) > .8 ) );

Sell = ( ( Ope > Clo ) AND ( ( Ope - Clo ) / ( .001 + Hi - Lo ) > .8 ) );

AddColumn( Ope, "Open" );
AddColumn( Clo, "Close");
AddColumn( Hi, "High");
AddColumn( lo, "Low");

TimeFrameRestore();

_SECTION_END();


The values which I am getting is all crap. For ex: For Apollo Tyres, following are values which it has printed. Looks like it is taking Daily Values

Open =107.85 (No idea where it came from)
Close =107.85 (30th Jan Close)
High= 108.3 (30th Jan High)
Low=104.5 (30th Jan Low)
Whats Full Green? Whats Full Black? 50% green and 50% candle maine to aaj tak dekhi nahi

You are getting garbage value in Ope because you have typed zero instead of letter O in third TimeFrameGetPrice function...
 
Sir ji,

I meant real body candle with little or no shadow. I have corrected the zero issue. That leaves me with the main issue. Why Lo = TimeFrameGetPrice( "L", 2*in15Minute, -1 ); is not giving low price in previous half hour candle. Instead it is giving me low price of previous day candle.

Thanks
 

amitrandive

Well-Known Member
Dear All

Below is a smooth Stochastic AFl.I have added the buy sell arrows but they do not work.:confused:

Please advise

Code:
_SECTION_BEGIN("StochasticsSmooth");
grid_day = IIf(Day()!=Ref(Day(),-1),1,0);  
Plot(grid_day,"",colorDarkGrey,styleHistogram|styleDashed|styleNoLabel|styleOwnScale);
 
SetChartOptions(0,chartShowArrows|chartShowDates);
d1=StochK(18, 9);//, 18) ;
d2=StochD(18,9,3);//, 20);
qw=WMA(d1, 1); wq=WMA(d2, 1);
ww=WMA(qw, 2); ee=WMA(wq, 2);
p1=WMA(ww, 3); p2=WMA(ee, 3);
Plot(p1, "price", colorGreen,styleThick);
Plot(p2, "price", colorRed,styleThick);
 
Overbought = 80 ;
Oversold =20 ;
Center = 50 ;

 
Plot(Overbought, "",colorRed,styleThick) ;
Plot(Oversold, "",colorGreen,styleThick) ;
Plot(Center, "",colorBlue, styleDashed,styleThick) ;
Buy=Cross(p1, p2) ;
Sell=Cross(p2, p1);
PlotShapes(IIf( Sell, shapeDownArrow , shapeNone), colorRed,0, Offset=Null) ;
PlotShapes(IIf( Buy, shapeUpArrow , shapeNone), colorBlue,0, Offset=Null) ;
Cover=Buy; Short=Sell;
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);


BuyPrice=ValueWhen(Buy, C);
SellPrice=ValueWhen(Sell, C);

Filter=Buy OR Sell ;
 
 
                SetOption("NoDefaultColumns", True);
                AddTextColumn(Name(), "Symbol", 77, colorDefault, colorDefault, 120);
                AddColumn(DateTime(), "Trigger Date", formatDateTime);
 
 
 
                AddColumn(IIf(Buy, 66, 83), "Signal", formatChar, colorYellow, IIf(Buy, colorGreen, colorRed));
               AddColumn(IIf(Buy, BuyPrice, SellPrice),  "Entry", 6.2);
 AddColumn(LastValue(C), "C. M. P.", 6.2);

 
_SECTION_END();
 

Nehal_s143

Well-Known Member
hi

is it possible to use time frame expand on Point and Figure afl ?

I want to use 15 min P&F ribbon on 5 min chart for better confirmation in range bound market

_SECTION_BEGIN("Point and Figure");
//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);
_SECTION_END();


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

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

pratapvb

Well-Known Member
hi

is it possible to use time frame expand on Point and Figure afl ?

I want to use 15 min P&F ribbon on 5 min chart for better confirmation in range bound market

_SECTION_BEGIN("Point and Figure");
//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);
_SECTION_END();


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

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


P&F is time frame independent....it is only based on moves....so the lower TF you create it the better it will be I think
 

amitrandive

Well-Known Member
Dear All

Below is a smooth Stochastic AFl.I have added the buy sell arrows but they do not work.:confused:

Please advise

Code:
_SECTION_BEGIN("StochasticsSmooth");
grid_day = IIf(Day()!=Ref(Day(),-1),1,0);  
Plot(grid_day,"",colorDarkGrey,styleHistogram|styleDashed|styleNoLabel|styleOwnScale);
 
SetChartOptions(0,chartShowArrows|chartShowDates);
d1=StochK(18, 9);//, 18) ;
d2=StochD(18,9,3);//, 20);
qw=WMA(d1, 1); wq=WMA(d2, 1);
ww=WMA(qw, 2); ee=WMA(wq, 2);
p1=WMA(ww, 3); p2=WMA(ee, 3);
Plot(p1, "price", colorGreen,styleThick);
Plot(p2, "price", colorRed,styleThick);
 
Overbought = 80 ;
Oversold =20 ;
Center = 50 ;

 
Plot(Overbought, "",colorRed,styleThick) ;
Plot(Oversold, "",colorGreen,styleThick) ;
Plot(Center, "",colorBlue, styleDashed,styleThick) ;
Buy=Cross(p1, p2) ;
Sell=Cross(p2, p1);
PlotShapes(IIf( Sell, shapeDownArrow , shapeNone), colorRed,0, Offset=Null) ;
PlotShapes(IIf( Buy, shapeUpArrow , shapeNone), colorBlue,0, Offset=Null) ;
Cover=Buy; Short=Sell;
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);


BuyPrice=ValueWhen(Buy, C);
SellPrice=ValueWhen(Sell, C);

Filter=Buy OR Sell ;
 
 
                SetOption("NoDefaultColumns", True);
                AddTextColumn(Name(), "Symbol", 77, colorDefault, colorDefault, 120);
                AddColumn(DateTime(), "Trigger Date", formatDateTime);
 
 
 
                AddColumn(IIf(Buy, 66, 83), "Signal", formatChar, colorYellow, IIf(Buy, colorGreen, colorRed));
               AddColumn(IIf(Buy, BuyPrice, SellPrice),  "Entry", 6.2);
 AddColumn(LastValue(C), "C. M. P.", 6.2);

 
_SECTION_END();
Pratap Sir

Please help with this.
 

Nehal_s143

Well-Known Member
P&F is time frame independent....it is only based on moves....so the lower TF you create it the better it will be I think
Sir is it possible to plot sell arrow below recent 2 low of red O and plot buy above recent 2 high of blue X in above P&F afl

Please see below Nifty1 5 min chart

 
Sir is it possible to plot sell arrow below recent 2 low of red O and plot buy above recent 2 high of blue X in above P&F afl

Please see below Nifty1 5 min chart

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);
 
Last edited:

Gaur_Krishna

Well-Known Member
Hi Pratap Sir & Happy ji,

Came across a system using Keltner Bands (periods 15, width-2 & price field -Close) & EMA 8 (Input-Close). This is at 10 min TF for intraday charts.

In this cross-over system, buy signal with up arrow is to be generated if EMA crosses lower band from down-side to up and sell signal with Down arrow to be generated if EMA crosses top band line from above. How to write AFL for this? Can we include sound when the signal is generated?

This is not a real system but just a CASE STUDY.

Thanks & Regards,
Gaur_Krishna
 
Last edited:

nms

Active 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();
 

Similar threads