Trend Catching System

#11
Hi KelvinHand
Many thanks for this AFL
You are a genius dude.
I have gone through your other AFLs as well
They are just marvelous
Keep it up
Thanks
 
#12

jsb2012

Active Member
#15
Re: Can Somebody please convert mq4 formula to afl

//+------------------------------------------------------------------+
//| Bubbles&Drops.mq4 |
//| Maxaxa Angry Hunter |
//| [email protected] |
//+------------------------------------------------------------------+
#property copyright "Maxaxa Angry Hunter"
#property link "[email protected]"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Orange
#property indicator_color2 Red

extern int historyDeep=100; //
extern int future=50; //

double Buffer[],temp[],fut[];
int timeLen=0,divider=10000;

int init()
{
//---- indicators
IndicatorBuffers(2);
SetIndexBuffer(1,Buffer);
SetIndexBuffer(0,fut);

SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2);

SetIndexShift(1,0);
SetIndexShift(0,future);

return(0);
}
int deinit()
{
}

int start()
{
if (Digits==5) divider=100000;
if (Digits==4) divider=10000;

if (ArraySize(Time)!=timeLen) {
historyDeep++;
}
timeLen=ArraySize(Time);

ArrayInitialize(Buffer,Open[historyDeep]);
ArrayInitialize(fut,Open[historyDeep]);

for (int j=0;j<historyDeep;j++) {
splash(historyDeep-j);

for (int i=0;i<=historyDeep-j;i++) {
Buffer[historyDeep-j-i]=Buffer[historyDeep-j-i]+temp;
}
for (i=0;i<=future+1;i++) {
fut[future-i]=fut[future-i]+temp[historyDeep-j+i];
}
for (i=future;i<(historyDeep+future);i++) {
fut=Buffer[i-future];
}
}
fut[0]=fut[1];

return(0);
}

double splash(int length) {
ArrayResize(temp,length+future);
ArrayInitialize(temp,0.0);
double ampl=MathRound((Open[length]-Close[length])*divider); //
if (ampl!=0) {
for (int i=0;i<=(length+future);i++) {
temp=attenuation(ampl,(i+1))/divider;
}
} else {
for (i=0;i<=(length+future);i++) {
temp=0;
}
}
return;
}

double attenuation (double a,double x) {
if (a!=0) {
if (a<0) return ( (MathAbs(a)-100/(x)*MathSin(x/100*MathAbs(a)))); // sin(exp(cos($x)));
if (a>0) return (-(MathAbs(a)-100/(x)*MathSin(x/100*MathAbs(a)))); // sin(exp(cos($x)));
}
}
Edit/Delete Message
 

KelvinHand

Well-Known Member
#16
Hello Kevin, this system is copy of brain trend system. I can copy with few changes which i have since long long time. Try n provide ur comments.


Formula below ::

// ================AFL=========================
_SECTION_BEGIN("Brain Trend System");
SetChartBkColor(ParamColor("Panel color ",colorBlack));
//========================Initiation========================
bts=ParamToggle("BrainTrend1 signal","Yes|No" ,1);
btst=ParamToggle("BrainTrend1 stop","Yes|No" ,1);
btsl=ParamToggle("BrainTrend1 stop line","Yes|No" ,1);
period=Param("Period",13,2,21,1);
x1=53;
x2=47;
d=2.3;
f=7;
s=1.5;
range=ATR(f);
Range1 = ATR(f)/d;
Range2 = (ATR(f)*s)/4;
range3=ATR(10);
R = ((HHV(H,period) - C) /(HHV (H,period) -LLV (L,period))) *-100;
EMA1= EMA(R,Period);
EMA2= EMA(EMA1,5);
Difference= EMA1 - EMA2;
ZeroLagEMA= EMA1 + Difference;
value2=abs(ZeroLagEMA);


function PercentR( periods )
{
return -100 * ( HHV( H, periods ) - C )/( HHV( H, periods ) - LLV( L, periods ) );
}


for( i = period+10; i < BarCount; i++ )
{
C[0]=0;
Value2[0]=0;
p[0]=0;
Plot1[0]=0;
Plot2[0]=0;
Val1=0;
Val2=0;
temp[0]=0;
Value3[0]=0;
tm[0]=0;
p1=0;
bt1[0]=0;
bt2[0]=0;
r[0]=0;
bt1a[0]=0;
bt2a[0]=0;
istop[0]=Val1[0];
stop=Val1[0];
bstop[0]=0;
sstop=0;
//==================================Indicators============================
{
if (value2 < x2 AND abs(Close-Close[i-2]) > range1)
p = 1 ;
else
{
if (value2 > x1 AND abs(Close-Close[i-2]) > Range1)
p = 2 ;

else

p=0;
}
}

if ((value2 < x2 AND p == 1) OR (value2 < x2 AND p == 0))

{
if (abs(Close-Close[i-2]) > Range1)
{
Plot1=H;
Plot2=L;
}
else
{
Plot1=Plot1[i-1];
Plot2=Plot2[i-1];
}
}
else
{
if ((value2 > x1 AND p == 2) OR (value2 > x1 AND p == 0))

{
Plot1=L;
Plot2=H;
}
else
{
Plot1=Plot1[i-1];
Plot2=Plot2[i-1];
}
}
//==================KBrain Signal ====================================
{
if (value2 < x2 AND (abs(Close-Close[i-2]) > Range1))
{
if (p == 1 OR p == 0)
Value3=L-range3;
val1=Value3;
p=1;
temp=1;
}
else
{
temp=temp[i-1];
}
{
if (value2 > x1 AND (abs(Close-Close[i-2]) > Range1))
{
if (p == 2 OR p == 0)
Value3=H+range3;
val2=Value3;
p=2;
temp=2;;
}

}
}
{

if (temp==1 AND Plot1>0 AND tm != 1)
tm= 1;

if (temp==2 AND Plot2>0 AND tm != 2)
tm=2;

}
//===============================stop========================================
{
if (value2 < x2 AND (abs(Close-Close[i-2]) > Range1)AND p !=2)

{
value3=L-range3;
va1=Value3;
p1=2;
r=Va1;
bstop=Va1;
bt2=bt2[i-1];
}

if (value2 > x1 AND (abs(Close-Close[i-2]) > Range1)AND p !=1)

{
Value3=H+range3;
va2=Value3;
p1=1;

r=Va2;
sstop=Value3;
bt1=bt1[i-1];
}

}



if (val1 == 0 AND val2 == 0 AND p == 0 )
{
bstop=bstop[i-1];
sstop=sstop[i-1];
}


if (bstop<bstop[i-1] AND tm==1 AND tm[i-1]==1) bstop=bstop[i-1];
if (sstop>sstop[i-1] AND tm==2 AND tm[i-1]==2) sstop=sstop[i-1];

}
//=============================SYSTEM======================================
SetChartOptions(0,chartShowArrows | chartShowDates);
HaClose = (O + H + L + C)/4;
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( H, Max( HaClose, HaOpen ) );
HaLow = Min( L, Min( HaClose, HaOpen ) );
xDiff = (HaHigh - Halow) * 10000;
barcolor = IIf(HaClose >= HaOpen,colorLime,colorRed);
//PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "", barcolor, styleCandle );
PlotOHLC( Open, High, Low, Close, "", barcolor, styleCandle );
PlotShapes( shapeCircle* (bts AND tm==1 AND Ref(tm,-1)==2),colorTurquoise, 0, bstop, 0 );
PlotShapes( shapeCircle* (bts AND tm==2 AND Ref(tm,-1)==1), colorCustom12, 0, sstop, 0 );
PlotShapes( IIf(btst AND p==1,shapeSmallCircle,Null), colorTurquoise,0,bstop,0);
Plot(IIf(btsl AND tm==1,bstop,Null),"",colorPaleBlue,1);
PlotShapes( IIf(btst AND p==2,shapeSmallCircle,Null), colorCustom12,0,sstop,0);
Plot(IIf(btsl AND tm==2,sstop,Null),"",colorLightYellow,1);
Buy=Cover=(bts AND tm==1 AND Ref(tm,-1)==2);
Sell=Short=(bts AND tm==2 AND Ref(tm,-1)==1);
//SellPrice=ValueWhen(Sell,C,1);
//BuyPrice=ValueWhen(Buy,C,1);

Long=Flip(Buy,Sell);
Shrt=Flip(Sell,Buy );

//BuyPrice = ExRem(BuyPrice, SellPrice);
//SellPrice = ExRem(SellPrice, BuyPrice);

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

SellPrice=ValueWhen(Sell,C,1);ShortPrice=SellPrice;
BuyPrice=ValueWhen(Buy,C,1);CoverPrice=BuyPrice;



PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), colorGreen, layer = 0,yposition = HaLow, offset = -30);
//PlotShapes( IIf( Buy, shapeSmallCircle, shapeNone ), colorWhite, layer = 0,yposition = HaLow, offset = -8);

PlotShapes( IIf( Sell, shapeDownArrow, shapeNone ), colorRed, layer = 0, yposition = HaHigh, offset = -30);
//PlotShapes( IIf( Sell, shapeSmallCircle, shapeNone ), colorRed, layer = 0, yposition = HaHigh, offset = -8);

AlertIf( Buy, "SOUND C:\\Windows\\Media\\Chord.wav", "Audio alert", 2 );
AlertIf( Sell, "SOUND C:\\Windows\\Media\\Ding.wav", "Audio alert", 2 );


dist = 0.4*ATR(10);
for( i = 0; i < BarCount; i++ )
{
if( Buy ) PlotText( "BUY@" + H[ i ], i, L[ i ]-dist, colorBlack , colorLime);
if( Sell ) PlotText( "SELL@"+ L[ i ], i, H[ i ]+dist, colorBlack, colorRed);
}

_SECTION_END();






_SECTION_END();
//=================TITLE================================================================================================
_SECTION_BEGIN("Title");
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
_SECTION_END();


/*Guppy MMA */

SetChartBkColor(16);

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
ECw= EncodeColor(colorWhite);
ECy= EncodeColor(colorYellow);
_N(Title = ECw+ "Guppy MMA " +ECy+ StrFormat("- {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
//Plot( C, "", IIf(Close > Open, colorBrightGreen, colorRed), styleBar | styleThick, styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();


_SECTION_BEGIN("Fast Periods");
P13= EMA (C,13);
P1 = EMA(C,3);
P2 = EMA(C,5);
P3 = EMA(C,8);
P4 = EMA(C,10);
P5 = EMA(C,12);
P6 = EMA(C,15);
_SECTION_END();

_SECTION_BEGIN("Slow Periods");
S20 = MA(C,20);
P34 = EMA(C,34);

P7 = EMA(C,30);
P8 = EMA(C,35);
P9 = EMA(C,40);
P10 = EMA(C,45);
P11 = EMA(C,50);
P12 = EMA(C,55);
P13 = EMA(C,60);
_SECTION_END();

_SECTION_BEGIN("Guppy MMA");
Plot(P7,"",colorOrange,styleDashed = 32);
Plot(P8,"",colorOrange,styleDashed = 32);
Plot(P9,"",colorOrange,styleDashed = 32);
Plot(P10,"",colorOrange,styleDashed = 32);
Plot(P11,"",colorOrange,styleDashed = 32);
Plot(P12,"",colorOrange,styleDashed = 32);
Plot(P13,"",colorOrange,styleDashed = 32);

Plot(P1,"",colorLightGrey,styleDashed = 32);
Plot(P2,"",colorLightGrey,styleDashed = 32);
Plot(P3,"",colorLightGrey,styleDashed = 32);
Plot(P4,"",colorLightGrey,styleDashed = 32);
Plot(P5,"",colorLightGrey,styleDashed = 32);
Plot(P6,"",colorLightGrey,styleDashed = 32);
_SECTION_END();


Chg=Ref(C,-1);
MV15= Volume*100/MA(V,15);
DL = Ref(C,-20);


Vlp = 15;
VolAvg = MA( V, Vlp );
VolumeIdx = V / VolAvg;
Volbuy = VolumeIdx >=2 AND O<C ;// > SmallWhiteCandle ;
Volsell = VolumeIdx >=2 AND O>C ;// > SmallBlackCandle ;

//Imm SLR = SL Diff points/Profits

Filter = ( Buy OR Sell);

mytimenum = DateTimeConvert( 1, DateTime() );

AddColumn(IIf( Buy,66,IIf(Sell,83,32) ),"A", formatChar, colorWhite, bkcolor =IIf(Buy, colorGreen,IIf( Sell,colorRed, colorDefault) ));//Action Trade buy or sell
AddColumn( IIf(Buy,H,IIf(Sell,-L,Null)) ,"PRICE",1.2,colorWhite,IIf(Buy,colorGreen,IIf(Sell,colorRed,colorBlack)));
AddColumn( VolumeIdx*100,"%Vol",1.1, colorBlack, IIf(Buy AND VolumeIdx > 1.8 ,colorGreen,IIf(Sell AND VolumeIdx > 1.8,colorRed,colorWhite))); // VOLUME INDEX
AddColumn( mytimenum,"TimeNum",colorBlack);
SetSortColumns(-6);

_SECTION_END();
//==============================================



The GMMA method is a practical trend catching system.
Depend on different viewpoint of Buy/Sell Alert :-
- High volatility trend maybe good, huge profit on higher time frame.
- Low volatility trend Buy/Sell Alert too early, stuck in the ranging situation.

Beside, If I am totally disciplined based on your Alert Signal, i may had fewer re-entry signals
in a trending situation.
But using naked eyeball, I can see more entries than your Buy/Sell Alerts.


Always remember, indicators are lagging. sometimes it will run and alert late.

Same issue for the original Trend Catching system.
 
Last edited:
#17
hI FRIENDS
The Braintrend system is asctrend .
Asctrend uses 9 periods.
it plots support and resz as dots.
the rule is simple.
it is a barbased system if you use or add candles you spoil the system by removing the clarity. you need to see the small dots,big dot,line stops clearly to make money by taking power signals.

rules
for buy, let bluedot appear then let bluebars appear=go long
for sell, wait for red dot(big dot),then wait for redbars,once both things match go short.
the system depends on entry,trailingstop,exit on stop break. no target on scene.

Like a Jimberg formula cant use candles, so also never use candles on asctrend or braintrend.

good day!
ps Somebody said blackbackground on chart is not good.
If you use blackbackground your eyes are at peace.
use brighter colors,you place eyes at overload.
want it? have it!
 
#18
KH sir, i want your help. please code this conditions for amibroker.

condition 1 -
cover & buy - when di+ > di- , cci>100 and adx>15

condition 2 -
sell & short - when di- > di+ , cci<-100 and adx>15
 
Last edited:

Similar threads