How to call an .ex4 file into an EA?

Arav
Trader
Posts: 15
Joined: Tue Jan 21, 2014 2:06 pm

How to call an .ex4 file into an EA?

Post by Arav »

:hi: Guys,
I have few indicators in .ex4 format. I intended to automate them i.e. when they changes color altogether it will give me an alert. But as they are in .ex4 format so I don't have the source code.
But I heard that I can call those indicators in any EA without knowing the source code using buffer and iCustom() function.

I have searched online for the process but got example for mq4 files where the source code is known. So I need such process for .ex4 file. If anyone have it then please share.
And if don't then please suggest me.

I have opened the Data window in the chart using Ctrl+D. There I found three value. Y,G,R.
When I move the mouse over different bars, then the value of Y and G changes. R never changes for the indicator I have tested.
I observed that when the color of indicator goes from Gray to Blue Y becomes 1to 0 and G becomes 0 to 1 and vice versa for Blue to Gray changing.
So I concluded that Y is buffer '0', G is buffer '1' and R is buffer 2.
So the iCustom() function lines for each buffer for current bar [i.e. 0 bar]
can be like this?

Code: Select all

iCustom(Symbol(),Timefram e,"CUSOMT INDI NAME",all parameters separated by coma, 0, 0);
iCustom(Symbol(),Timefram e,"CUSOMT INDI NAME",all parameters separated by coma, 1, 0);
iCustom(Symbol(),Timefram e,"CUSOMT INDI NAME",all parameters separated by coma, 2, 0);
Any sorts of Help will be highly appreciated.
Thanks
You do not have the required permissions to view the files attached to this post.
garyfritz

Re: How to call an .ex4 file into an EA?

Post by garyfritz »

You don't need any help -- you've figured it out on your own, well done.

MQL can't change the color of an indicator. So color-changing indis like this use multiple indicator lines/bars/whatever with different colors. When the indicator is gray, the Y value goes to 0. Since the indicator is scaled to display the range 0.0-1.0, the 0 value isn't visible. At the same time G goes to 1, and you have a blue bar.

You have the right idea with your iCustom() calls. The last param is the bar on which you want the indicator value. Pass it a value of 0 for the current (realtime) indicator value for the bar that is actively being formed, 1 if you want the value on the most recently completed bar, 2 for the bar before that, etc.
Arav
Trader
Posts: 15
Joined: Tue Jan 21, 2014 2:06 pm

Re: How to call an .ex4 file into an EA?

Post by Arav »

garyfritz wrote:You don't need any help -- you've figured it out on your own, well done.

MQL can't change the color of an indicator. So color-changing indis like this use multiple indicator lines/bars/whatever with different colors. When the indicator is gray, the Y value goes to 0. Since the indicator is scaled to display the range 0.0-1.0, the 0 value isn't visible. At the same time G goes to 1, and you have a blue bar.

You have the right idea with your iCustom() calls. The last param is the bar on which you want the indicator value. Pass it a value of 0 for the current (realtime) indicator value for the bar that is actively being formed, 1 if you want the value on the most recently completed bar, 2 for the bar before that, etc.
Hello,
Thanks for the reply.
I have a question. Now if I want to compare two such color changing indicators and open trades upon their simultaneous change of color, then how can I relate them or compare them? Because like in the attached screenshot, I have used 4 indicators where two of them are having Y,G and R.
For Blue to Gray color change, Y of 1st Indicator and Y of 4th indicator both becomes '1.0'. So my condition will be like:

Code: Select all

if (Y==1 && Y==1) // I have omitted the other 2 indicators here.
{
//Place a Buy order 
}
Now here how can I distinguish that the 1st 'Y' is for 1st indicator and the 2nd 'Y' is for 4th indicator?
As I am unable to modify the Indicators, so I can't assign anything like Y1, Y2. Then how to compare them?

Thanks
You do not have the required permissions to view the files attached to this post.
garyfritz

Re: How to call an .ex4 file into an EA?

Post by garyfritz »

You determined Y is buffer 0. So you need to call iCustom for each indicator (I assume you're calling it with different parameters or something?), and save the buffer 0 return value for each one:

Code: Select all

Y1 = iCustom(Symbol(),Timeframe,"CUSTOM INDI NAME",first,set,of,parameters, 0, 0);
Y2 = iCustom(Symbol(),Timeframe,"CUSTOM INDI NAME",second,set,of,prameters, 0, 0);
That will tell you if both indicators are gray on the CURRENT TICK. It may change blue/gray/blue/gray many times before the current bar closes. Do you want to look at that transient value? Or do you want to look only at a bar that's closed? That would be bar 1, not bar 0.

That also tells you if the current open bar is gray, but NOT if it just TURNED gray. If you want to detect when it just turned from blue to gray, you'll have to look at the same indicators on the previous bar, and see if the Y value changed from 0 to 1.
Arav
Trader
Posts: 15
Joined: Tue Jan 21, 2014 2:06 pm

Re: How to call an .ex4 file into an EA?

Post by Arav »

Yes, I want the change to grab at every Tick not on every Bar.
So whenever the indicators change the color, EA will open order.

As you suggested:

Code: Select all

   Y1 = iCustom(Symbol(),Timeframe,"CUSTOM INDI NAME",first,set,of,parameters, 0, 0);
        Y2 = iCustom(Symbol(),Timeframe,"CUSTOM INDI NAME",second,set,of,parameters, 0, 0);
Here Y1 is for First Indicator and Y2 is for another?
Then I can compare two indicator's state of color by comparing their 'Returning' value?
This is for the first 'Buffer' of each indicator?

The function will be like:

Code: Select all

{
Double Y1, Y2;
 Y1 = iCustom(Symbol(),Timeframe,"CUSTOM INDI NAME",first,set,of,parameters, 0, 0);
Y2 = iCustom(Symbol(),Timeframe,"CUSTOM INDI NAME",second,set,of,prameters, 0, 0);
return Y1,Y2;
}
if (Y1==0 && Y2==0)
{
//Place a Sell Order;
}
And as I have to put 'Parameters' in the iCustom function, so I would use the Extern Variables available from the indicator? [Attached file]

Thanks
You do not have the required permissions to view the files attached to this post.
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Re: How to call an .ex4 file into an EA?

Post by SteveHopwood »

Arav » Thu Jan 30, 2014 10:35 am wrote:And as I have to put 'Parameters' in the iCustom function, so I would use the Extern Variables available from the indicator?

Thanks
Yes. You need to pass the same number of parameters in the iCustom() call as there are in the indi. You can also have these as extern's in your ea and call iCustom with these values.

For example, say your indi has one input: Range = 1;

Your ea can have an extern:
extern int EaRange - 5;
Your iCustom call would be
double RangeVal = iCustom(Symbol(), TimeFrame, EaRange, IndiBuffer, shift);
IndiBuffer is the buffer you are interrogating. shift is which ever candle you want the value returned for. RangeVal will hold the value of the return from the indi when EaRange = 5. This is how calls to an indi are made completely independent of those on your chart.

:D
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Re: How to call an .ex4 file into an EA?

Post by SteveHopwood »

To take things a step further, imagine you have an indi that returns the average height of a range of candles. It has just one parameter, NoOfCandles, which is the number of candles to calculate the average.

In your EA you would declare your variables.

Code: Select all

extern int NoOfCandles = 5;//Nice to use the same name as the indi input where possible, but not necessary.
double AverageHeight;//Will hold the average height of the candles in the range.
Then you add your function to call the indi in such a way as it is as flexible and reusable as possible.

Code: Select all

double GetIndiValue(string symbol, int TimeFrame, int buffer, int shift)
{
       return (iCustom(symbol, TimeFrame, "Indi name", buffer, shift);
}
Then, where relevant in your code you call the function:

Code: Select all

    AverageHeight = GetIndiValue(Symbol(), 0, 0, 1);//Returns the average height of the previous NoOfCandles
If you wanted the average height of candles 3 to 8, your call would be

Code: Select all

    AverageHeight = GetIndiValue(Symbol(), 0, 0, 3);//Returns the average height of the previous NoOfCandles starting at 3 candles ago
Go to http://www.stevehopwoodforex.com/phpBB3 ... ?f=15&t=79 and download my 'Shell auto trading code'. You will see a few examples there of how it is done - some better than others as it is long standing code.

:xm:
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
garyfritz

Re: How to call an .ex4 file into an EA?

Post by garyfritz »

Arav » Thu Jan 30, 2014 3:35 am wrote:Here Y1 is for First Indicator and Y2 is for another?
Then I can compare two indicator's state of color by comparing their 'Returning' value?
This is for the first 'Buffer' of each indicator?
Yes to all. The Buffer is indicated by the second-to-last parameter.

Code: Select all

{
Double Y1, Y2;
 Y1 = iCustom(Symbol(),Timeframe,"CUSTOM INDI NAME",first,set,of,parameters, 0, 0);
Y2 = iCustom(Symbol(),Timeframe,"CUSTOM INDI NAME",second,set,of,prameters, 0, 0);
return Y1,Y2;
}
if (Y1==0 && Y2==0)
{
//Place a Sell Order;
}
You won't like that. That will place a Sell order on EVERY TICK that the two indicator Y values are 0. You need to use some method to place the order once, e.g. when Y1/Y2 change from 1 to 0.

Gary
Arav
Trader
Posts: 15
Joined: Tue Jan 21, 2014 2:06 pm

Re: How to call an .ex4 file into an EA?

Post by Arav »

Yes. You need to pass the same number of parameters in the iCustom() call as there are in the indi. You can also have these as extern's in your ea and call iCustom with these values.
Ok. I have tried to write a short code for 2 indicators. Please correct me.

Characteristic:
When 1st Indicator goes from Gray to Blue, it's 'Buffer 1' [Here G] goes 0 to 1.
When 2nd indicator goes from Red to Blue, it's 'Buffer 1' [Here G] goes 0 to 1.

When 1st Indicator goes from Blue to Gray, it's 'Buffer 0' [Here Y] goes 1 to 0.
When 2nd indicator goes from Blue to Red, it's 'Buffer 2' [Here R] goes 1 to 0.

What I want:
When G(1st) and G(2nd) become 1, EA will open a Buy order.
When Y(1st) and R(2nd) become 0, EA will open a Sell order.

My code:

Code: Select all

Double start()
{
        {
        Double Y1, Y2, Y3, Y4;
        Y1 = iCustom(NULL,0,13 FIM,EarlySignal,M3_Coral_Filter,1,0);
        Y2 = iCustom(NULL,0,13 MoneyFlowIndex,EarlySignal,M3_Coral_Filter,1,0);
	Y3 = iCustom(NULL,0,13 FIM,EarlySignal,M3_Coral_Filter,0,0);
        Y4 = iCustom(NULL,0,13 MoneyFlowIndex,EarlySignal,M3_Coral_Filter,2,0);
        return Y1,Y2,Y3,Y4;
        }
        if (Y1==1 && Y2==1)
        {
        //Place a Sell Order;
        }

	if (Y3==0 && Y4==0)
        {
        //Place a Sell Order;
        }

return 0;

}
*I am concerned the way I have declared the Parameters. I have used the External parameters available at the indicators properties. Are they alright? [Please see the attachment]
You won't like that. That will place a Sell order on EVERY TICK that the two indicator Y values are 0. You need to use some method to place the order once, e.g. when Y1/Y2 change from 1 to 0.
Thanks for the code. I have used it to express my thought.
Yes, I have understood what selecting every Tick will do. I am planning a part of money management for it. Like no trade will be opened unless the current trade got closed or something like that.
You do not have the required permissions to view the files attached to this post.
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Re: How to call an .ex4 file into an EA?

Post by SteveHopwood »

The indi you are calling needs to be inside quotes so:
Y1 = iCustom(NULL,0,13 FIM,EarlySignal,M3_Coral_Filter,1,0);

needs to be

Y1 = iCustom(NULL,0,13 "FIM",EarlySignal,M3_Coral_Filter,1,0);
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
Post Reply

Return to “Coders Hangout”