Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, Nymphodora), 972 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
MQL4 indicator conversion #471623
03/11/18 18:43
03/11/18 18:43
Joined: Jun 2017
Posts: 78
B
BobbyT Offline OP
Junior Member
BobbyT  Offline OP
Junior Member
B

Joined: Jun 2017
Posts: 78
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:
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:
Code:
#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

Attached Files
full_indi.txt (236 downloads)
Full MT4 indicator code
atr_test.c (122 downloads)
full lite-c script
Re: MQL4 indicator conversion [Re: BobbyT] #471905
03/24/18 18:58
03/24/18 18:58
Joined: Jun 2017
Posts: 78
B
BobbyT Offline OP
Junior Member
BobbyT  Offline OP
Junior Member
B

Joined: Jun 2017
Posts: 78
The scope of the problem has been narrowed and a new thread opened.

Html:
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=471901#Post471901



Cheers

Last edited by BobbyT; 03/24/18 19:00.

Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1