Johnyparwwkh sir plz look in to StepMA

KelvinHand

Well-Known Member
#21
thanx for you greatly encouraging words kelvinhand.

and i will surly use your completely demystified help.
OK. Let Start Simple. To debug, use _TRACE() either log to internal log window or extern DbgView.exe

A. Easy work
1. From the MT4 "extern", create the exact Param/ParamList/ParamToggle for AFL except BarsNumber
2. Copy all the global variables into AFL styles.

B. Will See Errors, subscript out of range
3. Convert the 2 functions into AFL exact.

C. The most difficult part - looping
- MT4 loop from right to left, 0 is the Current Bar and counting backward (previous bar) i+1, ...
- Ami loop from left to right, BarCount-1 is always the Current Bar, so counting backward (previous bar) is i-1
- Since we need to loop from i=0 to BarCount-1, then MT style had to reverse into functions above for ami


4 In the case the Main Looping cannot be start from 0, otherwise subscript out of range again when called the functions
so need an start offset Length.

for(i=Length; i<BarCount; i++)
{
step= func1(..., i);
stepMA=func2(step,...,i);

...
}



Once the above problem solved, the rest of the problem are small issue.
 
Last edited:

extremist

Well-Known Member
#22
thank u sir for help.

i have added one parameter to the code " step size"

and tried to code the first function

it made code stable at least. except step size =0

//Step MA Based on the Popular MetaTrader Indicator
//Version V.1.0 dated 18-07-2012
//Coded by Karthik Marar
//Copyright www.tatechnics.in
//======================== Indicator============================

_SECTION_BEGIN("StepMA");

PeriodWATR = Param("length",14,1,1000,1);
ss = Param("Step Size",14,0,1000,1);
Kv = Param("Sensitivity", 1.25,0.1,1000,0.1);


function StepSizeCalc( Len,Km,size)
{if(Size==0)
{
AvgRange=0;
for(i=Len-1;i>=0;i--)
{
alfa= 1.0+1.0*(Len-i)/Len;
AvgRange=AvgRange+ alfa*(High[k+i]-Low[k+i]);
}
ATR0=AvgRange/Len;
//----

// i can not understand how to get these ATRmax and ATRmin?


/*
if (ATR0>ATRmax) ATRmax=ATR0;
if (ATR0<ATRmin) ATRmin=ATR0;
//----*/
//result=round(0.5*Km*(ATRmax+ATRmin));
result=round(0.5*Km*(ATR0));

}
else
result=Km*Size;
return result;
}


StepSize=StepSizeCalc(PeriodWATR,Kv,ss);

smax = Low+2*StepSize;
smin = High-2*StepSize;

trend[0] = 1;
Linebuffer[0] = C[0];
Linemax[0] = C[0];
Linemin[0] = C[0];
Linemid[0] = C[0];
for(i = PeriodWatr; i < BarCount; i++)
{
if(Close>smax[i-1]) trend=1;
else
{
if(Close<smin[i-1]) trend=-1;
else
trend = trend[i-1];
}
//--------------------
if(trend > 0 AND smin<smin[i-1]) smin=smin[i-1];
if(trend < 0 AND smax>smax[i-1]) smax=smax[i-1];

if (trend >0 ) LineBuffer=smin+StepSize;
else
{
if (trend <0) LineBuffer=smax-StepSize;
else
LineBuffer = LineBuffer[i-1];
}

}

Plot (lineBuffer,"StepMA ",colorYellow,1,0,0,0,2);
//Plot (C,"StepMA V.1.0",IIf(C>Linebuffer,colorLime,colorRed),styleBar);
_SECTION_END();

plz chk

i just coded first function. tht too not to perfection
 
Last edited:

KelvinHand

Well-Known Member
#23
thank u sir for help.

i have added one parameter to the code " step size"

and tried to code the first function

it made code stable at least. except step size =0

//Step MA Based on the Popular MetaTrader Indicator
//Version V.1.0 dated 18-07-2012
//Coded by Karthik Marar
//Copyright www.tatechnics.in
//======================== Indicator============================

_SECTION_BEGIN("StepMA");

PeriodWATR = Param("length",14,1,1000,1);
ss = Param("Step Size",14,0,1000,1);
Kv = Param("Sensitivity", 1.25,0.1,1000,0.1);


function StepSizeCalc( Len,Km,size)
{if(Size==0)
{
AvgRange=0;
for(i=Len-1;i>=0;i--)
{
alfa= 1.0+1.0*(Len-i)/Len;
AvgRange=AvgRange+ alfa*(High[k+i]-Low[k+i]);
}
ATR0=AvgRange/Len;
//----

// i can not understand how to get these ATRmax and ATRmin?


/*
if (ATR0>ATRmax) ATRmax=ATR0;
if (ATR0<ATRmin) ATRmin=ATR0;
//----*/
//result=round(0.5*Km*(ATRmax+ATRmin));
result=round(0.5*Km*(ATR0));

}
else
result=Km*Size;
return result;
}


StepSize=StepSizeCalc(PeriodWATR,Kv,ss);

smax = Low+2*StepSize;
smin = High-2*StepSize;

trend[0] = 1;
Linebuffer[0] = C[0];
Linemax[0] = C[0];
Linemin[0] = C[0];
Linemid[0] = C[0];
for(i = PeriodWatr; i < BarCount; i++)
{
if(Close>smax[i-1]) trend=1;
else
{
if(Close<smin[i-1]) trend=-1;
else
trend = trend[i-1];
}
//--------------------
if(trend > 0 AND smin<smin[i-1]) smin=smin[i-1];
if(trend < 0 AND smax>smax[i-1]) smax=smax[i-1];

if (trend >0 ) LineBuffer=smin+StepSize;
else
{
if (trend <0) LineBuffer=smax-StepSize;
else
LineBuffer = LineBuffer[i-1];
}

}

Plot (lineBuffer,"StepMA ",colorYellow,1,0,0,0,2);
//Plot (C,"StepMA V.1.0",IIf(C>Linebuffer,colorLime,colorRed),styleBar);
_SECTION_END();

plz chk

i just coded first function. tht too not to perfection


Dear Sir,

I ask you to code the MT4 code in Post #3 not Post #4. Copy and convert exact.

You complain the Post#4 (AFL) code did not display the same as Post#3 (MT4), why still touching Post#4. I also told you Post #4 not stable.

I take 3days to figure out the solution.
I need you face all the trouble to do all the works and progress.
If you face the error and don't understand, show out.
Meantime, if anyone want to join in to help and give advise or learn to convert mt4 to afl.
welcome.
 
Last edited:

Similar threads