AFL writing guide for new user

#71
AFL FOR SAR BASED SIGNAL : Debarghya mukherjee

Output:
Code:
_SECTION_BEGIN("SAR Based System: Debarghya Mukherjee");
acc = Param("Acceleration", 0.02, 0, 1, 0.001 );
accm = Param("Max. acceleration", 0.2, 0, 1, 0.001 );
Plot( SAR( acc, accm ), "_SARS", IIf( SAR() > H, colorRed, colorGreen ),styleDots | styleNoLine);
Plot( Close, "Price", IIf(C > O,colorGreen, colorRed), styleCandle );
Buy=Ref( High , -1 ) < Ref( SAR() , -1 ) AND Low>SAR();
Sell= Ref( Low , -1 )> Ref(SAR() , -1) AND High <SAR();
PlotShapes( Buy * shapeUpArrow + Sell * shapeDownArrow, IIf( Buy, colorGreen, colorRed ),0,IIf( Buy, L, H ),-10 );
_SECTION_END();
 

msa5678

Well-Known Member
#72
Dear DM,

I am in need of an AFL for a very simple strategy. It is something like this.

EMA 13 crosses EMA 21 from below on 15 min TF intitiates a BUY;
EMA 5 crosses EMA 8 from below on 60 min TF confirms the BUY;

If it would have been a single TF , I could have framed the lines myself. This 2 TF's are creating a problem.

Can you help me in this matter
 
#73
Ok. I will help you.

Dear DM,

I am in need of an AFL for a very simple strategy. It is something like this.

EMA 13 crosses EMA 21 from below on 15 min TF intitiates a BUY;
EMA 5 crosses EMA 8 from below on 60 min TF confirms the BUY;

If it would have been a single TF , I could have framed the lines myself. This 2 TF's are creating a problem.

Can you help me in this matter
 
#74
Debarghya Mukherjee bhaiya this is your COD and my pic image maybe not seem AFL , i thing some diffierent, what do u thing? excuse me please for this comment!!
 
Last edited:
#75
May be. But I was clueless about the output. It was only an image. So, I just tried to implement in my way. You can give me any clue on the lines? my candles are same. it is Heiken Ashi.
If you can give me more clue then I can help you more. :)

Debarghya Mukherjee bhaiya this is your COD and my pic image maybe not seem AFL , i thing some diffierent, what do u thing? excuse me please for this comment!!
 
Last edited:
#76
MULTI TIME FRAME AFL SYSTEM: DEBARGHYA MUKHERJEE

Image:

Code:
_SECTION_BEGIN("Multi Time Frame System");
Plot( Close, "Price", IIf(C > O, colorGreen, colorRed), styleCandle );
TimeFrameSet( in15Minute );
ma15_13 = EMA( C, 13 );
ma15_21 = EMA( C, 21 );

Plot( TimeFrameExpand( ma15_13, in15Minute), "EMA(13) 15 min bars", colorGreen );
Plot( TimeFrameExpand( ma15_21, in15Minute), "EMA(21) 15 min bars", colorRed );

TimeFrameRestore();
TimeFrameSet( inHourly );
mah_5 = EMA( C, 5 );
mah_8 = EMA( C, 8 );

Plot( TimeFrameExpand( mah_5, inHourly), "EMA(5) 60 min bars", colorBlue );
Plot( TimeFrameExpand( mah_8, inHourly), "EMA(8) 60 min bars", colorBlack );

_SECTION_END();



Dear DM,

I am in need of an AFL for a very simple strategy. It is something like this.

EMA 13 crosses EMA 21 from below on 15 min TF intitiates a BUY;
EMA 5 crosses EMA 8 from below on 60 min TF confirms the BUY;

If it would have been a single TF , I could have framed the lines myself. This 2 TF's are creating a problem.

Can you help me in this matter
 

msa5678

Well-Known Member
#78
DM,

Tussi Great Ho. Thanks a lot . It was really difficult jumping from one TF to another. This AFL is a great help.
Dear DM,

I added a few lines to the code written by you, the final version looks like this:
Code:
_SECTION_BEGIN("Multi Time Frame System");
Plot( Close, "Price", IIf(C > O, colorGreen, colorRed), styleCandle );
TimeFrameSet( in15Minute ); 
ma15_13 = EMA( C, 13 );
ma15_21 = EMA( C, 21 );

Plot( TimeFrameExpand( ma15_13, in15Minute), "EMA(13) 15 min bars", colorGreen ); 
Plot( TimeFrameExpand( ma15_21, in15Minute), "EMA(21) 15 min bars", colorRed );

TimeFrameRestore();
TimeFrameSet( inHourly ); 
mah_5 = EMA( C, 5 );
mah_8 = EMA( C, 8 );

Plot( TimeFrameExpand( mah_5, inHourly), "EMA(5) 60 min bars", colorBlue ); 
Plot( TimeFrameExpand( mah_8, inHourly), "EMA(8) 60 min bars", colorBlack ); 


///Addl Code
Cond1 = ma15_13 > ma15_21;
Cond2 = mah_5 > mah_8;

Cond3 = ma15_13 < ma15_21;
Cond4 = mah_5 < mah_8;

Buy = Cond1 AND Cond2;
Sell = Cond3 AND Cond4;

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


PlotShapes(shapeUpArrow*Buy,colorBlack,0);

PlotShapes(shapeDownArrow*Sell,colorRed,0);



dist = 1.0*ATR(20);

for( i = 0; i < BarCount; i++ ) 
{ 
if( Buy[i] ) PlotText( "Buy\n@" + C[ i ], i, L[ i ]-dist[i], colorGreen ); 
if( Sell[i] ) PlotText( "Sell\n@" + C[ i ], i, H[ i ]+dist[i], colorRed, colorYellow ); 
}
The problem I am facing is that as I scroll the mouse in Amibroker the signals are appearing and diappearing. Am I doing something wrong in the additional code.
 
#79
Hi, I have a problem with the code below:

Code:
MA1 = MA(C, 32);
MA2 = MA(C, 16);

trig = Cross(MA2, MA1);
vLINE = Ref(trig, 16);

LLBars= LLVBars(L, 16 + 5);
pd = ValueWhen(trig,LLBars,0);
vLINELow = Ref(trig, pd);


//Plot(MA1, "MA1", colorYellow, styleLine);
//Plot(MA2, "MA1", colorBlue, styleLine);

Plot(vLINElow, "", colorGrey50 , styleArea|styleOwnScale);
It basically draws a vertical line to the lowest low over the previous 16 days preceding the fast MA crossing the slow MA. The main goal of this formula is to detect past cycles.

However, the way the formula is written, it won't be able to skip whipsaws.

I maen, if the MA(16) crosses MA(32) from below, the formula will go search the lowest low over the preceding 16 days, to detect the starting point of the cycle. Yet, if then the MA(16) soon crosses back the MA(32) from above the there's no point in drawing the line. Because that is a whipsaw.

So, as a general rule, if the MA(16) crosses MA(32) from below, then the cycle will be labeled by the vertical line (at the lowest low over the preceding 16 days the crossover) as long as the MA(16) does not cross back MA(32) from above over the next 16 days at least.

How can I add this rule to the formula?

Thanks

NB: picture below, you get to see at the very left of the chart the yellow crossing the orange from below. The formula is wrong in drawing the vertical line, because then the yellow shortly after crosses the orange from above...only 3/4 days later. So, the first vertical line should not be drawn.

Later on, you see one more crossover. The yellow crosses the orange from below and the formula draws a vertical line to the lowest low over the past 16 days. The formula is right, in fact, next time yellow crosses back orange from above is more then 16 days later...

Hopefully I made my self understood.

Thanks
I understand it is something quite difficult to accomplish :(
 
#80
/Debarghya Mukherjee bhaiya u have been post your COD , i think plain HAchart and also diffirent candle from my pic image , and u look your pic image nobody candle out of average line but my pic image anything breakdown and breakout, so i think not seem COD?
 
Last edited:

Similar threads