Simple Coding Help - No Promise.

extremist

Well-Known Member
it works !!!!

thanks for the prompt response.

i want to change parameters so please insert param function in afl .


regards
SetChartOptions(0,chartShowArrows|chartShowDates);
Brick = Param( "Brick Size", 3, 0.01, 10, 0.01 );//3
reverse =Param( "Reverse ", 2.1, 0, 10, 0.01 );//2.1

// Convert the closing price to rising and falling rounded bricks
CF = ceil(H/Brick);
CR = floor(L/Brick);

// initialize first element
j = 0;
RKC[j] = CF[0];
RKO[j] = CF[0] + 1;

down[j] = 1; // By default the first bar is a down bar.
up[j] = 0;

// Loop to produce the Renko values in number of bricks

for( i=1; i<BarCount-1; i++ )
{
if( CF <= RKC[j] - 1 && down[j] ) // Continue down
{
num = RKC[j] - CF;
for( x=1; x<=num; x++ )
{
j++;
up[j] = 0;
down[j] = 1;
RKC[j] = RKC[j-1] - 1;
RKO[j] = RKC[j] + 1;
}
}
else
{
if( CR >= RKC[j] + Reverse && down[j] ) // Change down to up
{
num = CR - RKC[j];
j++;
up[j] = 1;
down[j] = 0;
RKC[j] = RKC[j-1] + 2;
RKO[j] = RKC[j] - 1;
for( x=2; x<=num; x++ )
{
j++;
up[j] = 1;
down[j] = 0;
RKC[j] = RKC[j-1] + 1;
RKO[j] = RKC[j] - 1;
}
}
else
{
if( CR >= RKC[j] + 1 && up[j] ) // Continue Up
{
num = CR - RKC[j];
for( x=1; x<=num; x++ )
{
j++;
Up[j] = 1;
Down[j] = 0;
RKC[j] = RKC[j-1] + 1;
RKO[j] = RKC[j] - 1;
}
}
else
{
if( CF <= RKC[j] - Reverse && up[j] ) // Change up to down
{
num = RKC[j] - CF;
j++;
Up[j] = 0;
Down[j] = 1;
RKC[j] = RKC[j-1] - 2;
RKO[j] = RKC[j] + 1;
for( x=2; x<=num; x++ )
{
j++;
up[j] = 0;
down[j] = 1;
RKC[j] = RKC[j-1] - 1;
RKO[j] = RKC[j] + 1;
}
}
}
}
}
}


// move the chart to right end of chart space, ie last brick on last bar position
delta = BarCount-1 - j;

RKC = Ref( RKC, -delta );
RKO = Ref( RKO, -delta );

Up = Ref( Up, -delta );
Down = Ref( Down, -delta );

/*
rC = RKC * Brick;// + (Up-down)*Brick/2;
rO = RC - (Up-down)*Brick;
rH = Max(rC,rO);
rL = Min(rC,rO);
*/


C = RKC * Brick;// + (Up-down)*Brick/2;
O = C - (Up-down)*Brick;
H = Max(C,O);
L = Min(C,O);

PlotOHLC(O,H,L,C, "", ParamColor( "Renko Color", colorBlack ),ParamStyle("Renko Style",styleCandle,maskAll));


_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} \n Op=> %g, \n Cl=> %g \n", O, C ) );

// plot chart
//PlotOHLC( rO, rH, rL, rC, "Renko Price " , colorBlack, styleCandle);
if( ParamToggle("Plot Sig", "No|Yes", 0))
{Buy=Up;
Sell=Down;
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);

PlotShapes(shapeUpArrow*Buy,colorGreen, 0, L );
PlotShapes(shapeDownArrow*Sell,colorRed, 0, H );
}

_SECTION_END();
 
thanks extremist and amitrandive for your prompt help .

renko and range bars dont work properly in amibroker.

eg in 500r range bar yesterday's low for sbi is shown at 2487.25 where as sbi yesterday's low is 2474 .

even in renko bars there is much more issue .

range bars which are an inbuilt functionality in amibroker but still it has issues. '

ps -- i am using data from invest bulls and their data is quiet good .
 
please add alert and pop up to code

_SECTION_BEGIN("185%");
// ********************************************
// INDICATOR :DIVERGENCE
// DATE :07-30-04
// PROGRAMMER :M.Lauronen
// COPYRIGHTS :public Domain
// ********************************************

// --------------------------------------------
// Recommended AmiBroker indicator settings:
// Level 0
// Percent
// Middle
// Scaling: Custom 0 - 100
// --------------------------------------------

// Adjust the following parameters to suit your needs
// Adjust the following parameters to suit your needs

//period = Param("% change",0.4,0.1,25,0.1);
//period = 5;
uplimit=2;
uplimit=IIf(Interval()==in15Minute,4,IIf(Interval()==inHourly,8,
IIf(Interval()==inDaily,12,uplimit)));
i=uplimit;
globalTitile=" ";
BuyCond =ShortCond=False;
divergenceCount=0;
highCount=0.0;

for(;i>=0.2;){
numChg = i ;
i=i-0.1;
// --------------------------------------------
// Divergence for LONG
// --------------------------------------------

trendMom = RSI(5);

periods = 5;
Ksmooth = 3;
trendStoch=StochK( periods , Ksmooth);

bull=High - EMA(Close,13);
bear=Low - EMA(Close,13);
bb=bull+bear;


Hist=MACD(12,26)-Signal(12,26,9);

FI = (Close - Ref(Close, -1)) * V;


trendZig = Zig(L, numChg);


f = trendZig > Ref(trendZig, -1) AND Ref(trendZig, -1) < Ref(trendZig, -2);

p1 = ValueWhen(f, Ref(trendZig, -1), 1);
p2 = ValueWhen(f, Ref(trendZig, -1), 2);
r1 = ValueWhen(f, Ref(trendMom,-1), 1);
r2 = ValueWhen(f, Ref(trendMom,-1), 2);
stockUp1= ValueWhen(f, Ref(trendStoch,-1), 1);
stockUp2= ValueWhen(f, Ref(trendStoch,-1), 2);
bbUP1= ValueWhen(f, Ref(bb,-1), 1);
bbUP2= ValueWhen(f, Ref(bb,-1), 2);
HistUP1= ValueWhen(f, Ref(Hist,-1), 1);
HistUP2= ValueWhen(f, Ref(Hist,-1), 2);
FIUP1= ValueWhen(f, Ref(FI,-1), 1);
FIUP2= ValueWhen(f, Ref(FI,-1), 2);


f = r1 > r2 AND p1 < p2;
fStoch=stockUp1 > stockUp2 AND p1 < p2;
fbb=bbUP1> bbUP2 AND p1 < p2;
HistUP=HistUP1> HistUP2 AND p1 < p2;
FIUP= FIUP1 > FIUP2 AND p1 < p2;

sigRSI = f AND NOT Ref(f, -1) AND trendMom > Ref(trendMom, -1);
sigStockUp = fStoch AND NOT Ref(fStoch, -1) AND trendStoch > Ref(trendStoch, -1);
sigbbUp = fbb AND NOT Ref(fbb, -1) AND bb> Ref(bb, -1);
HistSigUP = HistUP AND NOT Ref(HistUP , -1) AND Hist> Ref(Hist, -1);
FISigUP = FIUP AND NOT Ref(FIUP, -1) AND FI> Ref(FI, -1);

//_N(str = "(" + period + ")");
///Plot(trendMom, "RSI" + str, colorWhite);
Plot(trendZig, "zig", colorYellow,styleOwnScale);
Plot(sigRSI* 100, "RsiSigUp", colorGreen, styleHistogram + styleThick + styleNoLabel);
Plot(sigStockUp* 100, "StockSigUp", colorGreen, styleHistogram + styleThick + styleNoLabel);
Plot(sigbbUp* 100, "bbUp", colorGreen, styleHistogram + styleThick + styleNoLabel);
Plot(HistSigUP * 100, "MACDUp", colorGreen, styleHistogram + styleThick + styleNoLabel);
Plot(FISigUP * 100, "FIUP", colorGreen, styleHistogram + styleThick + styleNoLabel);



// --------------------------------------------
// Divergence for SHORT
// --------------------------------------------

trendZig2 = Zig(H, numChg);

f = trendZig2 < Ref(trendZig2, -1) AND Ref(trendZig2, -1) > Ref(trendZig2, -2);

p1 = ValueWhen(f, Ref(trendZig2, -1), 1);
p2 = ValueWhen(f, Ref(trendZig2, -1), 2);
r1 = ValueWhen(f, Ref(trendMom,-1), 1);
r2 = ValueWhen(f, Ref(trendMom,-1), 2);
stockDown1= ValueWhen(f, Ref(trendStoch,-1), 1);
stockDown2= ValueWhen(f, Ref(trendStoch,-1), 2);
bbDown1= ValueWhen(f, Ref(bb,-1), 1);
bbDown2= ValueWhen(f, Ref(bb,-1), 2);
HistDown1= ValueWhen(f, Ref(Hist,-1), 1);
HistDown2= ValueWhen(f, Ref(Hist,-1), 2);
FIDown1= ValueWhen(f, Ref(FI,-1), 1);
FIDown2= ValueWhen(f, Ref(FI,-1), 2);



f = r1 < r2 AND p1 > p2;
fStoch=stockDown1 < stockDown2 AND p1 > p2;
fbb=bbDown1 < bbDown2 AND p1 > p2;
HistDown=HistDown1< HistDown2 AND p1 > p2;
FIDown= FIDown1 < FIDown2 AND p1 > p2;

sigRSIDown = f AND NOT Ref(f, -1) AND trendMom < Ref(trendMom, -1);
sigStock = fStoch AND NOT Ref(fStoch, -1) AND trendStoch < Ref(trendStoch, -1);
sigbbDown = fbb AND NOT Ref(fbb, -1) AND bb < Ref(bb, -1);
HistSigDown = HistDown AND NOT Ref(HistDown , -1) AND Hist< Ref(Hist, -1);
FISigDown = FIDown AND NOT Ref(FIDown, -1) AND FI< Ref(FI, -1);

//_N(str = "(" + period + ")");
Plot(sigRSIDown* 100, "rsiSigDown", colorRed, styleHistogram + styleThick + styleNoLabel);
Plot(sigStock* 100, "StockSigDown", colorRed, styleHistogram + styleThick + styleNoLabel);
Plot(sigbbDown* 100, "bbDown", colorRed, styleHistogram + styleThick + styleNoLabel);
Plot(HistSigDown * 100, "MAcdDown", colorRed, styleHistogram + styleThick + styleNoLabel);
Plot(FISigDown* 100, "FIDown", colorRed, styleHistogram + styleThick + styleNoLabel);


divergenceCount+=IIf(sigRSI,1,0) + IIf(FISigUP,1,0)+
IIf(sigStockUp ,1,0)+ IIf(sigbbUp ,1,0)+ IIf(HistSigUp ,1,0);

divergenceCount+=IIf(sigRSIDown ,1,0) + IIf(sigStock ,1,0)+
IIf(sigbbDown ,1,0)+ IIf(HistSigDown ,1,0)+ IIf(FISigDown,1,0);



BuyCondTmp=sigRSI OR sigStockUp OR sigbbUp OR HistSigUp OR FISigUP;
ShortCondTmp=sigRSIDown OR sigStock OR sigbbDown OR HistSigDown OR FISigDown;
highCount+=IIf(BuyCondTmp OR ShortCondTmp,numChg,0.0);

BuyCond = BuyCond OR BuyCondTmp ;
BuyCond=BuyCond AND (highCount>10);
ShortCond= ShortCond OR ShortCondTmp;
ShortCond=ShortCond AND (highCount>10);



globalTitile+=WriteIf(BuyCondTmp OR ShortCondTmp ,""+i,"")+

WriteIf(sigRSI,"rsiup ","")+WriteIf(sigStockUp,"stochup ","")+WriteIf(sigbbUp,"bbup ","")
+WriteIf(HistSigUP ,"macdup ","")+ WriteIf(FISigUP,"FIUP ","")



+WriteIf(sigRSIDown ,"rsiDown ","")+WriteIf(sigStock ,"stochDown ","")+WriteIf(sigbbDown,"bbDown ","")
+WriteIf(HistSigDown ,"macdDown ","")+ WriteIf(FISigDown,"FIDown ","")
+ WriteIf(BuyCondTmp OR ShortCondTmp ,"\n","");






} //for

Title=globalTitile;



FirstTradeTime = 091500; // Earliest time to take a trade
LastTradeTime = 151500; // Latest time to take new trades
ExitAllPositionsTime = 151500;
//change = Param("% change",0.1,0.1,25,0.1);
z = Zig(Close, 0.8 );

Buy=(BuyCond ) ;//AND (TimeNum() >= FirstTradeTime AND TimeNum() <= LastTradeTime );
Sell = IIf(z < Ref(z, -1), 1, 0) ;// OR TimeNum() > ExitAllPositionsTime;
Short=(ShortCond ) ;//AND (TimeNum() >= FirstTradeTime AND TimeNum() <= LastTradeTime );
Cover = IIf(z > Ref(z, -1), 1, 0) ;//OR TimeNum() > ExitAllPositionsTime;

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


Filter=BuyCond OR ShortCond;
//Filter=Filter AND (TimeNum()>091500 AND TimeNum()<100000);


AddColumn(BuyCond,"DiverBuy");
AddColumn(ShortCond,"DiverSell");
AddColumn(divergenceCount,"no of diver");
AddColumn(highCount,"high");
//AddTextColumn(globalTitile,"indicators");
//AddColumn(StrLen(globalTitile),"StrLen",1);
if( ParamTrigger("Display Popup Window", "Press here" ) )
{
PopupWindow("Current time is: " + Now(),"Alert", 2, 640*mtRandom(), 480*mtRandom());
}AlertIf( Buy , "SOUND C:\\Windows\\Media\\chimes.wav", "Audio alert", 2 );
AlertIf( Sell , "SOUND C:\\Windows\\Media\\alert.wav", "Audio alert", 2 );




_SECTION_END();
 
pls add in this one code too alert and pop up

_SECTION_BEGIN("ADX");
range = Param("Periods", 14, 2, 200, 1 );
Plot( ADX(range), _DEFAULT_NAME(), ParamColor( "ADX color", colorBlue ), ParamStyle("ADX style", styleThick ) );
Plot( PDI(range), "+DI", ParamColor( "+DI color", colorGreen ), ParamStyle("+DI style") );
Plot( MDI(range), "-DI", ParamColor( "-DI color", colorRed ), ParamStyle("-DI style") );
_SECTION_END();


_SECTION_BEGIN("MACD");
r1 = Param( "Fast avg", 10, 2, 200, 1 );
r2 = Param( "Slow avg", 15, 2, 200, 1 );
r3 = Param( "Signal avg", 1, 1, 200, 1 );
Plot( ml = MACD(r1, r2), StrFormat(_SECTION_NAME()+"(%g,%g)", r1, r2), ParamColor("MACD color", colorRed ), ParamStyle("MACD style") );
Plot( sl = Signal(r1,r2,r3), "Signal" + _PARAM_VALUES(), ParamColor("Signal color", colorBlue ), ParamStyle("Signal style") );
Plot( ml-sl, "MACD Histogram", ParamColor("Histogram color", colorDefault ), styleNoTitle | ParamStyle("Histogram style", styleHistogram | styleNoLabel, maskHistogram ) );
Plot(0, "", colorBlue, 1);
Plot(0.25, "", colorLightGrey, styleLine | styleNoLabel);
Plot(-0.25, "", colorLightGrey, styleLine | styleNoLabel);
SetGradientFill( colorGreen, colorRed, 0, GetChartBkColor() );
Plot(ml, "Sterngth" + _PARAM_VALUES(), colorDefault, styleLine | styleGradient );
_SECTION_END();

_SECTION_BEGIN("RSI Divergence");
//------------------------------------------------------------------------------
//
// Formula Name: RSI Divergence
// Level: medium
// Flags: indicator
// Formula URL:
// Details URL:
//
//------------------------------------------------------------------------------
//
// + scanner
//
//------------------------------------------------------------------------------

/*---------------------------------------------------
RSI Divergence
--------------------------------------------------------*/

GraphXSpace=7;
n=Param("% Reverse ",20,0,100,1);

Buy=Sell=0;
Var = Zig(RSI(), n);
t= Trough(RSI(), n, 1);
p= Peak(RSI(), n, 1);
x[0] =Var[0];
price[0] = C[0];
j=0;

// bearish divergence
for ( i=0; i<BarCount; i++)
{
if(Var == p)
{

j++;
x[j] =Var;
price[j] =C;
if(x[j] <x[j-1] && price[j-1]< price[j])
Sell =1;
}
}

// bullish divergence
for ( i=0; i<BarCount; i++)
{
if(Var == t)
{
j++;
x[j] =Var;
price[j] =C;
if(x[j] >x[j-1] && price[j]<price[j-1])
Buy =1;
}
}

Plot(Var, "", 29);
PlotShapes ( IIf(Sell, shapeSmallCircle, shapeNone), colorRed, 0 , Var,2);
PlotShapes( IIf(Buy, shapeCircle, shapeNone), colorBrightGreen, 0, Var,2);

Title ="RSI Divergence" ;
_SECTION_END();

_SECTION_BEGIN("RSIa");
P = ParamField( "Price field" );
periods = Param("Periods", 14, 1, 200, 1 );
Plot( RSIa( P, periods), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
AlertIf( Buy , "SOUND C:\\Windows\\Media\\chimes.wav", "Audio alert", 2 );
AlertIf( Sell , "SOUND C:\\Windows\\Media\\alert.wav", "Audio alert", 2 );
_SECTION_END();
 
sir,

I require the AFL code for the below condition.

1. I want values of the HIGH and LOW of the bar at the time of 9.30 am.
2. Draw horizontal line at 9.30 AM bar high and low.

Please help.
 

amsin21

Well-Known Member
I am looking for help to code the below criteria. Aiming to keep the chart screen less clutter.

Defaults

Up candle = Green
Down candle = Red
EMA 3 = Teal
EMA 15 = DarkOrange
Cross candle = Cyan

EMA parameters should be able to toggle (hidden) from the screen itself.

Criteria

1) EMA3 cross EMA15
2) When ever cross happens, cross candle color changes

Experts please.

Regards
 

Nehal_s143

Well-Known Member
I am looking for help to code the below criteria. Aiming to keep the chart screen less clutter.

Defaults

Up candle = Green
Down candle = Red
EMA 3 = Teal
EMA 15 = DarkOrange
Cross candle = Cyan

EMA parameters should be able to toggle (hidden) from the screen itself.

Criteria

1) EMA3 cross EMA15
2) When ever cross happens, cross candle color changes

Experts please.

Regards

Code:
ea = EMA (C,3);
eb = EMA (C,15);
SetBarFillColor( IIf( ea > eb, colorGreen, colorRed ) );
Plot( C, "Price", IIf( ea > eb, colorGreen, colorRed ), styleCandle );
Plot( ea, "ema3", colorTeal, styleThick ); 
Plot( ea, "ema3", colorDarkOrange, styleThick ); 



Buy = ea > eb ;
Sell = ea < eb;

PlotShapes(Buy*shapeUpArrow,colorblue,0,L,-33);
PlotShapes(Sell*shapeDownArrow,colorRed,0,L,-33);
 

amsin21

Well-Known Member
Code:
ea = EMA (C,3);
eb = EMA (C,15);
SetBarFillColor( IIf( ea > eb, colorGreen, colorRed ) );
Plot( C, "Price", IIf( ea > eb, colorGreen, colorRed ), styleCandle );
Plot( ea, "ema3", colorTeal, styleThick ); 
Plot( ea, "ema3", colorDarkOrange, styleThick ); 



Buy = ea > eb ;
Sell = ea < eb;

PlotShapes(Buy*shapeUpArrow,colorblue,0,L,-33);
PlotShapes(Sell*shapeDownArrow,colorRed,0,L,-33);
Thanks Nehal for the AFL. As said I want the color change of the candle instead of plotting the up/down arrows. Also the parameters (like show/hide EMAs, incase reqd) should be able to change from the screen. This takes away the need of EMAs and arrows off the chart, keeping it simple.
 

yasu222

Active Member
I require the AFL code for the below condition.

1. I want values of the HIGH and LOW of the bar at the time of 9.30 am.
2. Draw horizontal line at 9.30 AM bar high and low.

Please help.
 

Similar threads