Simple Coding Help - No Promise.

VJAY

Well-Known Member
Dear Pratap,
is it possible to make sound alert when triangle appears in chart?if possible please help :)

PlotShapes( IIf(Down AND (ValidLow OR ZeroValid),shapeSmallUpTriangle,0) ,colorBlue, 0, L,-12);
PlotShapes( IIf(Up AND (ValidHigh OR ZeroValid),shapeSmallDownTriangle,0) ,colorOrange, 0, H,-12);

complete afl here ...http://www.traderji.com/futures/91950-day-trading-futures-202.html#post951325
Dear Pratap/Happyji,
This post missed or avoided ?:confused:

One more request....
I have 315 afl ...i want to show in text on header or else where the figure of 3EMA as per open price of the scrip...EMA valuse changes fast after market open so i cant see that fig ...hope i explained it correct :)...please give me the code....
 

Nehal_s143

Well-Known Member
Sir also try this to find/detect range bound market,

Code:
_SECTION_BEGIN("Rangebound Indicator");
Viscosity = Param("Viscosity",7);
sedimentation = Param("Sedimentation",50);
thresold_level = Param("Threshold_level",1.1);
Lag_supressor = ParamToggle("lag_supressor","No|Yes",1);

function smma(a, period)
{
	i = k = ssum = 0;
	pos = period - 1;
	if(pos < 0)
		pos = 0;
	buf = 0;
	while(pos < BarCount)
	{
		if(pos == period - 1)
		{
			for(i = 0, k = pos;i < period;i++, k--)
			{
				ssum += a[k];
				buf[k] = 0;
			}
		}
		else
			ssum = buf[pos - 1] * (period - 1) + a[pos];
		buf[pos] = ssum / period;
		pos++;
	}
	return buf;
}

function interpolate(arr)
{
	n = BarCount;
	i = 0;nb = 0; ne = 0;t = 0;
	while(i < n)
	{
		while(i < n AND arr[i] == 0)
			i++;
		nb = i;
		i++;
		while(i < n AND arr[i] == 0)
			i++;
		if(i >= n)
			break;
		ne = i;
		t = LineArray(nb, arr[nb], ne, arr[ne]);
		for(i = nb + 1; i < ne; i++)
			arr[i] = t[i];
	}
	return arr;
}

gd96=0.5;
gda116=g104=g112=g108=0;
ATR20=MA(Nz(Max(H,Ref(C,-1))-Min(L,Ref(C,-1))),Viscosity);

ATR21=MA(Nz(Max(H,Ref(C,-1))-Min(L,Ref(C,-1))),sedimentation);

function mstddev(price, period)
{
	ret=0;
	dma=WMA(price,period);
	for(i=period;i<BarCount;i++)
	{
		damount=0;	
		for(j=0;j<period;j++)
		{
			daprice=price[i-j];
			damount+=(daprice-dma[i])*(daprice-dma[i]);
		}
		ret[i]=sqrt(damount/period);
	}

	return ret;
}

stddev1=mstddev((H+L+C)/3,Viscosity);

stddev2=mstddev((H+L+C)/3,sedimentation);
for(Li16=3;Li16<BarCount;Li16++)
{
	Ld28=Nz(gda116[Li16-1]);
	Ld36=Nz(gda116[Li16-3]);
	if(Lag_supressor)
		Ld0=ATR20[Li16]/ATR21[Li16]+gd96*(Ld28-Ld36);
	else
		Ld0=ATR20[Li16]/ATR21[Li16];
	Ld52=stddev1[Li16]/stddev2[Li16];
	//if(Li16>BarCount-5)
	//	_TRACE(NumToStr(ATR20[Li16],1.5));
	Ld60=thresold_level;
	Ld60-=Ld52;
	if(Ld0>Ld60)
	{
		g112[Li16]=Ld0;
		g108[Li16]=Ld0;	
		if(Li16==BarCount-1)
			_N(Title = "Rangebound Signal: TRADE  /  ATR= " + ATR20[Li16] + "    values:");
	}
	else
	{
		g112[Li16]=Ld0;
		g108[Li16]=0;
if(Li16==BarCount-1)
			_N(Title = "Rangebound Signal: DO NOT trade  /  ATR= " + ATR20[Li16] + "    values:");
	}
	gda116[Li16]=Ld0;
	g104[Li16]=Ld60;
	
}

g108=interpolate(g108);
i=BarCount-1;
while(g108[i]==0)
{
g108[i]=Null;
i--;
}
Plot(g104, "l1",colorGrey40);
Plot(g112, "l3",colorLime);
Plot(g108, "l2",colorRed);
Plot(11,"",IIf(g104 > Ref(g112,-1),colorRed,IIf(g104  < Ref(g112,-1),colorBlue,colorYellow)),styleOwnScale+styleArea+styleNoLabel,-0.5,100);

_SECTION_END();
Code:
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_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("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1);
factor = Param("factor",0.01,0.01,1,0.01)/1000;
e =  EMA( P, Periods );
d = ROC(e)/C;
//Plot(e, "EMA", IIf(d > factor, colorBlue, IIf(d < -factor,colorRed, colorYellow)), styleThick); 
Plot(d,"",IIf(d > factor, colorBlue, IIf(d < -factor,colorRed, colorYellow)), styleThick|styleHistogram|styleOwnScale);
_SECTION_END();
Similar concept

Happy :)
 

Cubt

Algo Trader
Happy_Singh, I tried the afl but it is plotting wrong buy sell signals. Can u check pls
 

xsis

Active Member
dear all

please help in making this afl where i can find if todays volume for a particular TF is greater than the avg volume of last n days for that TF.

for e.g. i want to see for first n minutes if on a 15min (x) chart todays volume is greater/less than the avg volume in last days (y) where x and y can be changed i.e. they aret he variables and n can be 1, 2....to wtever!

basically, this will help in knowing if the underlying is heavily/thinly traded for first n minutes than the usual or the volatility in other terms.

i hope i have been able to put across my thots. pls revert/question if logic not clear.

thks
 

pratapvb

Well-Known Member
dear all

please help in making this afl where i can find if todays volume for a particular TF is greater than the avg volume of last n days for that TF.

for e.g. i want to see for first n minutes if on a 15min (x) chart todays volume is greater/less than the avg volume in last days (y) where x and y can be changed i.e. they aret he variables and n can be 1, 2....to wtever!

basically, this will help in knowing if the underlying is heavily/thinly traded for first n minutes than the usual or the volatility in other terms.

i hope i have been able to put across my thots. pls revert/question if logic not clear.

thks
just drag MA afl of amibroker to a volume pane
 

xsis

Active Member
sorry pratap! pls dont get me wrng! u have been such an asset to this thread. but u hvnt got the concept!
if i do wt u said, it will draw MA line in volume pane for past n periods. so if my TF is 1min and n=200 then it will draw MA line of volume of past 200 mins!

my requirement is different. lets say i work on 1 minute chart and i want to see the avg volume for past 30 days but only for first 60 mins. so it will be only an avg for 30 days but it will take into a/c only first 60 mins volume. basically this is gonna tell us if in first 60 mins the volume is high/low than the usual 60 mins of last 30 days!

i hope its clear or u can ask other doubts too.

just drag MA afl of amibroker to a volume pane
 
Just a small request.

Say I want to test a code only on nr7 days. ie if monday was a nr7 day for that particular scrip then the code should work on tuesday. I understand that we can do that by adding previous day nr7 condition in buy, short conditions but what if we are trading a smaller tf eg. 30 mins and not eod tf.

We need to make use of timeframeset and timeframerestore in afl. I tried it but failed.

HTML:
TimeFrameSet(inDaily);
_SECTION_BEGIN("NR7");

/*********** NR7 System for Chart and Exploration ***********************/

R = H - L;
NR7 = False;
NR4 = False;
m7 = m4 = idm7 = idm4 = idm = 0;

for(i = 7; i < BarCount; i++)
{
if( R[i] < R[i - 1] AND R[i] < R[i -2] AND R[i] < R[i - 3] AND R[i] < R[i - 4] AND R[i] < R[i - 5] AND R[i] < R[i - 6]) 
{
NR7[i] = True;
m7[i] = 1;
}
}
_SECTION_END();
TimeFrameRestore();

Buy	= conditions	 AND (Ref(nr7,-1)==1);
Short	= conditions	 AND (Ref(nr7,-1)==1);
I am using this afl to get nr7.
Code:
_SECTION_BEGIN("NR7");

/*********** NR7 System for Chart and Exploration ***********************/

R = H - L;
NR7 = False;
NR4 = False;
m7 = m4 = idm7 = idm4 = idm = 0;

for(i = 7; i < BarCount; i++)
{
if( R[i] < R[i - 1] AND R[i] < R[i -2] AND R[i] < R[i - 3] AND R[i] < R[i - 4] AND R[i] < R[i - 5] AND R[i] < R[i - 6]) 
{
NR7[i] = True;
m7[i] = 1;
}
}

for(i = 4; i < BarCount; i++)
{
if((R[i] < R[i - 1] AND R[i] < R[i -2] AND R[i] < R[i - 3] ) AND NOT NR7[i])
{
NR4[i] = True;
m4[i] = 1;
}
}
IDNR7 = Inside() * NR7;
IDNR4 = Inside() * NR4;
ID = Inside();
idm7 = IIf(IDNR7, 1, 0);
idm4 = IIf(IDNR4, 1, 0);
idm = IIf(id, 1, 0);

for(i = 1; i < BarCount; i++)
{
if(IDNR7[i] == IDNR7[i - 1]) idm7[i] = idm7[i] + idm7[i - 1];
if(IDNR4[i] == IDNR4[i - 1]) idm4[i] = idm4[i] + idm4[i - 1];
if(NR7[i] == NR7[i - 1]) m7[i] = m7[i] + m7[i - 1];
if(NR4[i] == NR4[i - 1]) m4[i] = m4[i] + m4[i - 1];
if(ID[i] == ID[i - 1]) idm[i] = idm[i] + idm[i - 1];
}

MarkerIDNR7 = MarkerIDNR4 = shapeStar ;

Marker7 = shapeDigit7;
NR7Color = colorBrightGreen;

Marker4 = shapeDigit4;
NR4Color = colorLightOrange;

MarkerID = shapeHollowCircle;
IDColor = colorYellow;

IDNR7Color = colorBrightGreen;
IDNR4Color = colorLightOrange;

MarkerDist = L * 0.995;
IDNRDist = H * 1.03;

if(Status("action") == actionIndicator)
{
_N(Title = StrFormat("{{NAME}}, {{DATE}} ({{INTERVAL}}): {{VALUES}}") + ", Range=" + Prec(R + 0.00001, 2) + "," 
+ WriteIf(IDNR7, EncodeColor(colorBrightGreen) + WriteIf(idm7 > 1, StrLeft(NumToStr(idm7), 4), "") + " IDNR7 ", "")
+ WriteIf(IDNR4, EncodeColor(colorLightOrange) + WriteIf(idm4 > 1, StrLeft(NumToStr(idm4), 4), "") + " IDNR4 ", "") 
+ WriteIf(NR7 AND NOT ID, EncodeColor(colorBrightGreen) + WriteIf(m7 > 1, StrLeft(NumToStr(m7), 4), "") + " NR7 ", "")
+ WriteIf(NR4 AND NOT ID, EncodeColor(colorLightOrange) + WriteIf(m4 > 1, StrLeft(NumToStr(m4), 4), "") + " NR4 ", "")
+ WriteIf(ID AND NOT NR7 AND NOT NR4, EncodeColor(colorTurquoise) + WriteIf(idm > 1, StrLeft(NumToStr(idm), 4), "") + " Inside Day ", ""));

PlotOHLC(O, H, L, C, "Close", colorLightGrey, styleBar);
PlotShapes(IIf(IDNR7, MarkerIDNR7, shapeNone), IDNR7Color, 0, IDNRDist);
PlotShapes(IIf(IDNR4 AND NOT IDNR7, MarkerIDNR4, shapeNone), IDNR4Color, 0, IDNRDist);
PlotShapes(IIf(NR7 AND NOT ID, Marker7, shapeNone), NR7Color, 0, MarkerDist);
PlotShapes(IIf(NR4 AND NOT NR7 AND NOT ID, Marker4, shapeNone), NR4Color, 0, MarkerDist);
PlotShapes(IIf(ID AND NOT NR7 AND NOT NR4, MarkerID, shapeNone), IDColor, 0, IDNRDist);
}

if(Status("action") == actionExplore)
{
Filter = (m7 > 0) OR (m4 > 0) OR (idm > 0);

SetOption("NoDefaultColumns", True);

AddColumn(DateTime(), "DATE", formatDateTime, colorDefault, colorDefault, 96);
AddTextColumn(Name(), "SYMBOL", 77, colorDefault, colorDefault, 120);
AddColumn(R, "Range", 6.2, colorDefault, colorDefault, 84);
AddColumn(IIf(idm, 48 + idm, 32), "INSIDE", formatChar, colorYellow, IIf(idm, colorLightBlue, colorDefault));
AddColumn(IIf(m4, 48 + m4, 32), "NR4", formatChar, colorYellow, IIf(m4, colorBlue, colorDefault));
AddColumn(IIf(m7, 48 + m7, 32), "NR7", formatChar, colorYellow, IIf(m7, colorGreen, colorDefault));
}

/************************** END OF AFL CODE *****************************/

_SECTION_END();
Plz help to make this work. I hope i have made myself clear.:thumb:


Thanks,
Purusharth
 
Dear All, in my ATS afl I am having bar completion mode but in 3 min tf the entry signals are taken immediately and the log also confirms. The order is passing to the terminal for execution. But I want the bar to complete to avoid complications.

Also, in the same mode the chart signals should exactly match the log in number, time and price. But they are differing occasionally.

Please help.
 

Similar threads