Need some clarification in afl coding

hello seniors,

I have some setup conditions in 5min chart to take a trade. I want to add a condition in afl which first checks the stochastics momentum in 30minute chart and takes only long trades in 5mins if 30min momentum is bullish and vice versa for short trades. I tried as follows,

timeframeset(in1minute*30) {
     condition1=stochK(8,5)>stochD(8,5,3);
}

timeframerestore();
timeframeset(in5minute) {
    conditon2;
    condition3;
}
timeframerestore();
buy=condition1 and condition2 and condition3;



But it didn't work. As im a newbie to this afl coding stuff, i just need a guidance from the seniors in this.

Thanks in advance. :)

Hey,

(in1minute*30) is nothing either use longerĀ period in 15 minutes time frame or use hourly timeframe.

or you can use MA of stochk to smoothen it

If you want trade to happen in 5minutes timeframe, just set periodicity to 5mins in your backtester settings. Use 5 mins as base time and useĀ other time frames Ā likeĀ timeframeset(inhourly) as reference time frames.

May sound tough but you will need to spend time with it to get up to the speedĀ :)

Thanks

1 Like

Hi,

Make sure you set base interval of your charts/scan to <=5mins as u have few conditions which are in 5mins interval. If you set the timeframe >5mins, you might not get the expected result. Attaching the basic AFL which u can add and check in charts with TimeFrame set from <=5mins

Ā 

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

_SECTION_BEGIN("Multi Time Frame Stoch Trading");
timeframeset(in1minute*30);

//Buy condition in 30mins
condition1=stochK(8,5)>stochD(8,5,3);

//Sell Condition in 30mins
condition1_1 = stochK(8,5)<StochD(8,5,3);
timeframerestore();

timeframeset(in5minute);

//Buy Condtion in 5mins interval
condition2=stochK(8,5)>stochD(8,5,3);

//Sell Condition in 5mins Interval
condition2_1 = stochK(8,5)<StochD(8,5,3);
timeframerestore();

Buy=condition1 and condition2;
Sell = condition1_1 AND condition2_1;

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);                      
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);                      
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);
_SECTION_END();
1 Like

I donot know about afl . But, looking at the logic, may i know y u r calling ā€˜timeframerestore()ā€™ twice? also, there are other queries related to afl that might be usefull for u:
http://tradingqna.com/1803/anyone-help-code-using-coding-amibroker-strategy-given-below
http://tradingqna.com/1757/anybody-sites-books-learn-about-coding-stuff-just-amibroker
http://tradingqna.com/4075/from-where-can-i-get-afls-for-amibroker

first, i have set the time frame to 30min and wrote the conditions and restored it. next i have done the same by setting the time frame to 5min. and restoring it again. when i removed the 30min condition, the afl is working perfect. But when i add that, its staying dumb without doing anything till august data.

Thanks for the reply. Actually, i use hourly timeframe momentum as my first reference to take the trade direction and i wait untill th 30min momentum comes in the direction of trade and then i execute the trades in 5mins chartā€¦

I have written my strategy as per the above structure. But didnā€™t get the expected results. Infact, it is showing that there were no trades before august. Can i call the codition in higher timeframe directly in buy definition without using timeframeexpand??

Hi Jagdeesh,
can u give the conditions which you are trying to use so that i can help you better.
Regards
Neotrade Analytics

yeah sure. Can i mail you the conditions?? my id is [email protected].
Thanks and i appreciate your helpā€¦ :slight_smile:

Sure Mr. Jagadeesh. I will check and let u know.
You can email me on [email protected]