Hi All,
I'm trying to convert a custom MT4 indicator into lite-C to run some tests on it. The values seem to be a long way out which may or may not be related to indexing issues.
Here is the original MQL4 code:
double GetSuperSlope(string symbol, int tf, int maperiod, int atrperiod, int pShift )
{
double dblTma, dblPrev;
int shiftWithoutSunday = pShift;
double atr = iATR( symbol, tf, atrperiod, shiftWithoutSunday + 10 ) / 10;
double result = 0.0;
if ( atr != 0 )
{
dblTma = iMA( symbol, tf, maperiod, 0, MODE_LWMA, PRICE_CLOSE, shiftWithoutSunday );
dblPrev = ( iMA( symbol, tf, maperiod, 0, MODE_LWMA, PRICE_CLOSE, shiftWithoutSunday + 1 ) * 231 + iClose( symbol, tf, shiftWithoutSunday ) * 20 ) / 251;
result = ( dblTma - dblPrev ) / atr;
}
return ( result );
}//GetSuperSlope(}
Here is my current best attempt in lite-C:
#define D1 (1440/BarPeriod)
var myATRS(int Period, int shift)
{
//change to D1
TimeFrame = frameSync(D1);
Period = max(1,Period);
var vATRS = 0;
int g_count;
//create the price series for the new timeframe
vars H = series(priceHigh()), L = series(priceLow());
//calculate the MT4 style ATR
for(g_count = shift; g_count < Period+shift; g_count++)
vATRS += H[g_count+shift]-L[g_count+shift];
//reset timeframe
//TimeFrame = 1;
return vATRS/Period;
}
double GetSlope(int shift)
{
//change to D1
TimeFrame = frameSync(D1);
vars Close = series(priceClose());
//get shifted ATR value
double atr = myATRS(50, 11)/10;
//some local variables
double gadblSlope = 0.0;
//main calculation block
if ( atr != 0 )
{
double dblTma = WMA(Close+1,7);
//double dblPrev = (WMA(Close+1,7)*231+Close[0]*20)/251;
double dblPrev = (WMA(Close+2,7)*231+Close[1]*20)/251;
gadblSlope = ( dblTma - dblPrev ) / atr;
}
printf("nSlope = %.5f, atr = %.5f, bar opened @ %s", gadblSlope, atr, (string)datetime());
//reset timeframe
TimeFrame = 1;
return ( gadblSlope );
}
I think there are two problems.
1) I have not correctly converted the index/shift values between lite-c and mql4. Zorro and MT4 index slightly differently
2) MT4 ATR is a little weird but is meant to be replicated by ATRS(). However, Even without the shift parameter, the ADR values are a long way away from what MT4 is reporting for the same data/indicator settings.
Some help with this would be greatly appreciated as I'm slowly going insane with this. I can't for the life of me get the indicator readouts close.
I intend on testing this with 1 hour charts for trading and daily charts for the indicator data.
The above MQL4 code is the indicator calculation block taken from an MT4 trading bot. The full indicator code is in excess of 1500 lines. The source can be found attached to this post along with the full lite-c test script
Cheers