embedding class from an indicator in an expert.

Post Reply
dvirma
Posts: 6
Joined: Tue Nov 15, 2011 10:06 pm

embedding class from an indicator in an expert.

Post by dvirma »

hello steve, hello everyone, and regards.

along with the gradual turn from mql4 to mql5 language, codes are becoming less and less understood, at least for the amateur coder. as new codes are published, some of them seems to be very professional in which plenty of thought were invested.

for instance this volatility indicator, coded by mladen rakic.

i tried to disintegrate the main class of the code and transform it into simple function which returns value by requested pair and timeframe, as seen in some of steve's codes, and which can be embeded easily in the shell ea. as for now i went lost with it. will someone take the challenge?


https://www.mql5.com/en/code/26159
User avatar
tomele
Administrator
Posts: 1166
Joined: Tue May 17, 2016 3:40 pm
Location: Germany, Forest of Odes, Defending the Limes

embedding class from an indicator in an expert.

Post by tomele »

dvirma wrote:i tried to disintegrate the main class of the code and transform it into simple function which returns value by requested pair and timeframe, as seen in some of steve's codes, and which can be embeded easily in the shell ea. as for now i went lost with it. will someone take the challenge?
Why? MQL4 knows classes ...
Happy pippin, Thomas :-BD

It ain't what you don't know that gets you into trouble.
It's what you know for sure that just ain't so.
(Mark Twain)

Keep the coder going: Donate
dvirma
Posts: 6
Joined: Tue Nov 15, 2011 10:06 pm

embedding class from an indicator in an expert.

Post by dvirma »

yes. the code itself is in mql4. the thing is that the form of classes isn't common in steve's codes. and i don't manage to merge it. how to call it? how many bars to count? how to inverse the index? how to refer symbol and timeframe to it?

what we are used to is something like that:

double getvolatility(string pair, int timeframe, int shift)
{...
...
return(volatility);
}

and here it works differently.
User avatar
tomele
Administrator
Posts: 1166
Joined: Tue May 17, 2016 3:40 pm
Location: Germany, Forest of Odes, Defending the Limes

embedding class from an indicator in an expert.

Post by tomele »

Nobody is interested in what you are used to. Fact is, it will work in Steve's (or any other) code exactly as in the code you attached.

Define a class with constructor (for initialization), (optional) destructor and methods:

Code: Select all

class cStdDevVolatilityRatio
{...};
Create an instance of the class:

Code: Select all

cStdDevVolatilityRatio iVolatilityRatio;
Initialize the instance in OnInit() by calling the constructor:

Code: Select all

iVolatilityRatio.init(inpPeriod);
Call method of the class in OnCalculate() or OnTimer() to get a value (this is the function you are looking for)

Code: Select all

val[i] = iVolatilityRatio.calculate(iMA(_Symbol,_Period,1,0,MODE_SMA,inpPrice,i),rates_total-i-1,rates_total);
You better learn to integrate that than trying to reverse-engineer classes.

Cheers
Happy pippin, Thomas :-BD

It ain't what you don't know that gets you into trouble.
It's what you know for sure that just ain't so.
(Mark Twain)

Keep the coder going: Donate
dvirma
Posts: 6
Joined: Tue Nov 15, 2011 10:06 pm

embedding class from an indicator in an expert.

Post by dvirma »

thank you thomas. i will try to do that. i'm also trying to fill the gap and learn the class section in c++.
User avatar
tomele
Administrator
Posts: 1166
Joined: Tue May 17, 2016 3:40 pm
Location: Germany, Forest of Odes, Defending the Limes

embedding class from an indicator in an expert.

Post by tomele »

Glad to help.

My approach always was to study working code and then look up everything in the language reference that I don't understand. You might try that for yourself. The MQ4 language reference is quite good.

Cheers
Happy pippin, Thomas :-BD

It ain't what you don't know that gets you into trouble.
It's what you know for sure that just ain't so.
(Mark Twain)

Keep the coder going: Donate
Post Reply

Return to “Coders Hangout”