Simple Coding Help - No Promise.

#41
Respected sir,
how to write an AFL with the logic's below?

EMA's are 12 24
If bullish crossover is in daily time frame and if bullish cross in 1/2/3/5/10/15/30/60min time frame then BUY and
and vice-versa.

please help.

toug
Hello Friend

I think i have already posted some related code . . . :thumb:

But any way i will post the complete framework for trading with MA along with cross over, optimization etc , different types moving averages with different sets of rules . . .with explanation

Do that after Lunch brk :)

Cheers

:) Happy
 
#42
MA Xross on a Single Time Frame

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

_SECTION_BEGIN("MA_CROSS");
p = Optimize("PERIOD 1",Param("PERIOD 1",10,2,30,1),2,20,2);
q = Optimize("PERIOD 2",Param("PERIOD 2",90,10,200,10),10,100,10);
y = Optimize("MAType 1",Param("MAType 1",2,1,8,1),1,8,1);
z = Optimize("MAType 2",Param("MAType 2",2,1,8,1),1,8,1);

m=0;	if (y==1) m	=	MA(C,p);	
else	if (y==2) m	=	EMA(C,p);	
else	if (y==3) m	=	DEMA(C,p);	
else	if (y==4) m	=	TEMA(C,p);	
else	if (y==5) m	=	WMA(C,p);	
else	if (y==6) m	=	HMA(C,p);	
else	if (y==7) m	=	Wilders(C,p);	
else	if (y==8) m	=	LinearReg(C,p);

n=0;	if (z==1) n	=	MA(C,q);	
else	if (z==2) n	=	EMA(C,q);	
else	if (z==3) n	=	DEMA(C,q);	
else	if (z==4) n	=	TEMA(C,q);	
else	if (z==5) n	=	WMA(C,q);	
else	if (z==6) n	=	HMA(C,q);	
else	if (z==7) n	=	Wilders(C,q);	
else	if (z==8) n	=	LinearReg(C,q);
Plot(m," MA",IIf(m < Ref(m,-1),colorBlue,colorRed),styleThick);
Plot(n," MA",IIf(n < Ref(n,-1),colorBlue,colorRed),styleThick);

Buy  = CROSS(m,n);
Sell = cross(n,m);
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Short = Sell; Cover = Buy;
PlotShapes(Buy+2*Sell,colorWhite,0,IIf(Buy,L,H));
SetPositionSize(1,4);
_SECTION_END();
 
#43
Respected sir,
how to write an AFL with the logic's below?

EMA's are 12 24
If bullish crossover is in daily time frame and if bullish cross in 1/2/3/5/10/15/30/60min time frame then BUY and
and vice-versa.

please help.

toug
Hi

I will demo how you can do it on 2/3 TFs rest is just copy / paste so you should be easily able to do that for the other 10-15 time frames you need . . .

But really, do you think its Sane to try to do TF Amalgamation right from 1 minute to daily charts :confused:

Anyway your money, your choice . . . :thumb:

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

_SECTION_BEGIN("MA_CROSS");
p	= 	12;		
q	=	24;
m	=	EMA(C,p);	
n	=	EMA(C,q);	
Plot(m," MA",IIf(m < Ref(m,-1),colorBlue,colorRed),styleThick);
Plot(n," MA",IIf(n < Ref(n,-1),colorBlue,colorRed),styleThick);

UP = m > n;
DN = m < n;

//2 MINUTES
TimeFrameSet(in1Minute*2);
	UP02	=	EMA(C,p) > EMA(C,q);
	DN02	=	EMA(C,p) < EMA(C,q);
TimeFrameRestore();
UP02e = TimeFrameExpand(UP02,in1Minute*2);
DN02e = TimeFrameExpand(DN02,in1Minute*2);

//3 MINUTES
TimeFrameSet(in1Minute*3);
	UP03	=	EMA(C,p) > EMA(C,q);
	DN03	=	EMA(C,p) < EMA(C,q);
TimeFrameRestore();
UP03e = TimeFrameExpand(UP03,in1Minute*3);
DN03e = TimeFrameExpand(DN03,in1Minute*3);

//10 MINUTES
TimeFrameSet(in1Minute*10);
	UP10	=	EMA(C,p) > EMA(C,q);
	DN10	=	EMA(C,p) < EMA(C,q);
TimeFrameRestore();
UP10e = TimeFrameExpand(UP10,in1Minute*10);
DN10e = TimeFrameExpand(DN10,in1Minute*10);


//.............. MINUTES ... COPY/PASTE MODIFY FOR OTHERS 




Buy  = UP AND UP02e AND UP03e AND UP10e;
Sell = DN  OR DN02e  OR DN03e  OR DN10e;
Buy = ExRem(Buy,Sell);	Sell = ExRem(Sell,Buy);
Short = DN AND DN02e AND DN03e AND DN10e; 
Cover = UP  OR UP02e  OR UP03e  OR UP10e;;
Short = ExRem(Short,Cover);	Cover= ExRem(Cover,Short);
PlotShapes(Buy+2*Short,colorWhite,0,IIf(Buy,L,H),-24);
PlotShapes(Cover*3+4*Sell,colorWhite,0,IIf(Cover,L,H));
_SECTION_END();
Set the chart to 1 minute TF. The above code then will take care of 1 min and 2/3/10 mins . . .

use the template to add more time frames that you want . . . anyway my advice will be to avoid using more than 4,
you can modify to the AFL choice of TF you want to include, for eg. using this on 5 minutes use 15/30/60 as higher TFs

Enjoy :)
 

mastermind007

Well-Known Member
#45
Respected sir,
how to write an AFL with the logic's below?

EMA's are 12 24
If bullish crossover is in daily time frame and if bullish cross in 1/2/3/5/10/15/30/60min time frame then BUY and
and vice-versa.

please help.

toug
Happy and toug

What would be the probability of trade that has had bullish crossover on all time frames?

In theory, it does mean strongest buy but IMHO it may be impractical because by the time, bullish crossover trade trickles upwards to reach the top most time frame, it would have already reversed on lower time frames.

Another way to phrase this question would be to "What time frames are best for What trade periods?"
 

a1b1trader

Well-Known Member
#46
Hi Happy

Need your help.

I want to shift the place of the indicator from far left to right side, as shown in the chart
Please let me know how to do it.

Thanks



Uploaded with ImageShack.us
 
#48
Hi Happy

Need your help.

I want to shift the place of the indicator from far left to right side, as shown in the chart
Please let me know how to do it.

Thanks



Uploaded with ImageShack.us

Don't know how your panel is coded but any way try these steps

there are 2 type of graphics functions one using 4 co-ordinates other using only 2

the ones with just 2 is x, y
the ones with 4 is start-x, start-y, end-x, end-y

sample panel

Code:
GfxSelectPen(colorWhite,2); 
GfxMoveTo(100,100); 
GfxLineTo(100,200); 
GfxLineTo(300,200); 
GfxLineTo(300,100); 
GfxLineTo(100,100); 
GfxSelectFont("Comic Sans MS",12,600);
GfxSetBkColor( colorBlack);
GfxSetTextColor(colorRed);
GfxDrawText(" I  WaS  There",140,130,450,250,0);
GfxDrawText("Now I Am Here",140,160,450,250,0);
new code for above with movable panel :thumb:

Code:
x = Param("ADD X", 0,0,1200,10);
GfxSelectPen(colorWhite,2); 
GfxMoveTo(100+x,100); 
GfxLineTo(100+x,200); 
GfxLineTo(300+x,200); 
GfxLineTo(300+x,100); 
GfxLineTo(100+x,100); 
GfxSelectFont("Comic Sans MS",12,600);
GfxSetBkColor( colorBlack);
GfxSetTextColor(colorRed);
GfxDrawText(" I  WaS  There",140+x,130,450+x,250,0);
GfxDrawText("Now I Am Here",140+x,160,450+x,250,0);
Cheers


:) Happy
 
#49
happy bro can u create an exploration afl for finding the stocks which are away from their MA and how much
Aree Bhaiya thoda vistar se jaankare deejeyega :D

( bro few more details might just be more helpful for both of us :lol: )

Cheers

:) Happy
 

Similar threads