bletrend -can somebody convert this mt4 code into afl

rvlv

Active Member
#1
LabTrend3_v2.mq4

//+------------------------------------------------------------------+
//| LabTrend3_v2.mq4 |
//|
//| http://finance.groups.yahoo.com/group/TrendLaboratory |
//+------------------------------------------------------------------+


#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Aqua
#property indicator_color2 Magenta
//---- input parameters

extern int Risk=3; // Sensivity Factor
extern double MoneyRisk=2.0; // Offset Factor

//---- indicator buffers
double UpTrendBuffer[];
double DownTrendBuffer[];
double smax[];
double smin[];
double bsmax[];
double bsmin[];
double trend[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
//---- indicator line
IndicatorBuffers(7);

SetIndexBuffer(0,UpTrendBuffer);
SetIndexBuffer(1,DownTrendBuffer);

SetIndexStyle(0,DRAW_ARROW);
SetIndexStyle(1,DRAW_ARROW);

SetIndexArrow(0,159);
SetIndexArrow(1,159);
SetIndexBuffer(2,smin);
SetIndexBuffer(3,smax);
SetIndexBuffer(4,bsmin);
SetIndexBuffer(5,bsmax);
SetIndexBuffer(6,trend);

IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
//---- name for DataWindow and indicator subwindow label
short_name="LabTrend3("+Risk+","+MoneyRisk+")";
IndicatorShortName(short_name);
SetIndexLabel(0,"UpTrend Stop");
SetIndexLabel(1,"DownTrend Stop");
//----
SetIndexDrawBegin(0,10);
SetIndexDrawBegin(1,10);
//----
return(0);
}

//+------------------------------------------------------------------+
//| LabTrend3_v1 |
//+------------------------------------------------------------------+
int start()
{
int i,shift,counted_bars=IndicatorCounted();
double Kv=0.382;

int Length=10; // Volatility(ATR) Period


if ( counted_bars > 0 ) int limit=Bars-counted_bars;
if ( counted_bars < 0 ) return(0);
if ( counted_bars ==0 ) limit=Bars-1;

//for(shift=limit;shift>=0;shift--)
//price[shift] = iMA(NULL,0,1,0,0,Price,shift);

//for (shift=Nbars;shift>=0;shift--)
//{
//UpTrendBuffer[shift]=0;
//DownTrendBuffer[shift]=0;
//}

for (shift=limit;shift>=0;shift--)
{
double Range=iATR(Null,0,Length,shift);
double AvgRange=iATR(Null,0,100,shift);

if (Range<AvgRange) Range=AvgRange;

double High=High[Highest(Null,0,MODE_HIGH,9,shift)];
double Low =Low[Lowest(Null,0,MODE_LOW,9,shift)];

smin[shift]=Low + 0.3*(High-Low);
smax[shift]=High- 0.3*(High-Low);

bsmax[shift]=High[shift]+(1.0+0.1*Risk)*Range;
bsmin[shift]=Low[shift]-(1.0+0.1*Risk)*Range;

trend[shift]=trend[shift+1];
if(Close[shift]>smax[shift]) trend[shift]=1;
if(Close[shift]<smin[shift]) trend[shift]=-1;

if(trend[shift]>0)
{
if(Low[shift]-bsmin[shift]<Kv*MoneyRisk*Range) bsmin[shift]=Low[shift]-Kv*MoneyRisk*Range;
if(bsmin[shift]<bsmin[shift+1]) bsmin[shift]=bsmin[shift+1];
}

if(trend[shift]<0)
{
if(bsmax[shift]-High[shift]<Kv*MoneyRisk*Range) bsmax[shift]=High[shift]+Kv*MoneyRisk*Range;
if(bsmax[shift]>bsmax[shift+1]) bsmax[shift]=bsmax[shift+1];
}

if (trend[shift]>0)
{
if (trend[shift+1]<0)
{
bsmin[shift]=Low[shift]-0.1*Risk*Range;
UpTrendBuffer[shift]=bsmin[shift];
}
else
{
UpTrendBuffer[shift]=bsmin[shift];
}
DownTrendBuffer[shift]=EMPTY_VALUE;
}
if (trend[shift]<0)
{
if (trend[shift+1]>0)
{
bsmax[shift]=High[shift]+0.1*Risk*Range;
DownTrendBuffer[shift]=bsmax[shift];
}
else
{
DownTrendBuffer[shift]=bsmax[shift];
}
UpTrendBuffer[shift]=EMPTY_VALUE;
}

}
return(0);
 

Similar threads

Broker Special Offers

Intraday Higher Leverage

Save up to 90% in brokerage and get higher leverage for intraday trades.

Name:Phone:
Email:City:
State:
Are you a day trader?