Can anyone help me with mapping an indicator into the EA?

 

Hi Everyone!

I have been struggling with this problem for a while. I used mql4 references and Googled so hard that actually some keypad came out of my keyboard.

So what am I trying to achieve? I have this indicator SDX8 and EA from a template. SDX8 indicator draws lower and upper zones (max and lows in last 8 hours) and also draws entry signals.

I want the EA to be able to map those variables via iCustom function but I've had no luck so far. I want the EA to go long when entrysignals are drawn on the Zone1Lower and go short when entrysignals are drawn on the Zone1Upper. I only want them to go long/short when there are 2 or more signals (circles) drawn on those max/low lines.

I dont worry about the exit strategy because I will use fixed stop loss/ take profit and those should be pre-coded into the EA

I tried to code it but I am a beginner and this is too big challenge for me. Thank you in advance for help.

The indicator and the EA are attached.

 

rookie_forawhile, attachments are wrong (does not download anything)

 

Sorry, I'll try again

Here we go. Thanks for such a quick response.

Files:
sdx8.mq4  12 kb
sdx8-ea.mq4  10 kb
 

SDX indicator - Add ALL Externs For iCustom

rookie_forawhile:
Here we go. Thanks for such a quick response.

rookie_forawhile

I took a quick look at the indicator SDX8.mq4...and it seems to have problems with the email function...which may be causing problems with your EA...

That version SDX indicator also has many more "externs" than you have listed in your iCustom statements.

They are listed at the top and are associated with the email function....and ALL "externs" have to be added to your iCustom statements.

You can either add ALL the "externs" to your EA iCustom...or you can blank the email extern's out with // (right slashes) in the indicator.

You may need to go through the code and blank out all the other email stuff as well.

Also to help debugging...add Print and Comments to your EA's to make sure you are getting and displaying all the values you want.

I did find the original SDX version without the email mod's - SDX-ZoneBreakout2.mq4.

It is attached for your use.

sdx-zonebreakout2.mq4

Hope this helps you,

Robert

Files:
 

Externs

Thank you very much.

I added that email and push functions to the indicator, because you only get a few signals per day and I found the xpMail to attach screenshots to emails.

But now I figured an EA might be a better solution.

The idea behind the indicator works most of the times especially when there are Zone1Lower and upper and the price hits one of the zones more than once. iN that case there is a solid probability of a new trend.

So basically what you are saying is that I have to map all externs that are associated with the "if" statement, which takes care of alerts, right?

I'll start with the original indicator and I'll give your suggestions a try. Thank you again. Do you think that those iCustom statements that I put to the EA are correct from the syntax point of view? And that the logic behind those "if" statements to either buy or sell is correct?

The EA is pre-coded in such a way that I have to write some if statement with conditions when to buy/sell and then if it is true it should set Order=SIGNAL_BUY or Order=SIGNAL_SELL. Then the EA should take care of the rest (processing the order), right?

Thank you very much for answers.

-Robert

 

SDX indicator - Add ALL Externs For iCustom

rookie_forawhile:
Thank you very much.

I added that email and push functions to the indicator, because you only get a few signals per day and I found the xpMail to attach screenshots to emails.

But now I figured an EA might be a better solution.

The idea behind the indicator works most of the times especially when there are Zone1Lower and upper and the price hits one of the zones more than once. iN that case there is a solid probability of a new trend.

So basically what you are saying is that I have to map all externs that are associated with the "if" statement, which takes care of alerts, right?

I'll start with the original indicator and I'll give your suggestions a try. Thank you again. Do you think that those iCustom statements that I put to the EA are correct from the syntax point of view?

And that the logic behind those "if" statements to either buy or sell is correct?

The EA is pre-coded in such a way that I have to write some if statement with conditions when to buy/sell and then if it is true it should set Order=SIGNAL_BUY or Order=SIGNAL_SELL. Then the EA should take care of the rest (processing the order), right?

Hi rookie,

Just to be clear - The indicator externs are associated with the iCustom statements...not the "if" statements..."

You get your iCustom values first and then use the values in your "if" statements...

--------

Check other available EA's and study their iCustom syntax's and see the common syntax they all have.

iCustoms include all the # of externs, the buffer, and the bar shift...

Your iCustom only has 1 extern, the buffer, and bar shift.

double Zone1Upper = iCustom(NULL,0,"SDX8",0.0,0,0);

But...Your indicator has 3 externs...if you don't include the email externs...

Also look at your indicator externs for what "type" of variables you need in your iCustoms...then add the buffer and the bar shift.

Hint...one extern is a bool...not an integer or double...

SDX8 Indicator:

extern bool DoEntryAlerts= true;

extern int TimeZoneOfData= 1; // time zone of metatrader charts

extern int PipsForEntry= 5;

-------

I didn't check the Buy/Sell Trades part of the code...but that EA is a basic Expert Builder Template so I would assume if it hasn't been changed...it should work fine.

Again...add Comments to make sure you can see you are getting your iCustom values ok...

Hope that helps,

Robert

 

iCustom

Hi Robert,

ok, so i am using the original indicator now. so i have only 3 externs, which should be passed via iCustom. one of my mapped iCustoms should look like this:

1) double Zone1Upper = iCustom(NULL,0,"SDX-ZoneBreakout2",bool DoEntryAlerts,int TimeZoneOfData,int PipsForEntry,0,0);

or this:

2) double Zone1Upper = iCustom(NULL,0,"SDX-ZoneBreakout2",true,0,5,0,0);

this second one is considered as ok by the compiler, but it doesnt make any sense, right? I want those values to passed from the indicator to the EA (IN that case i don't want exact values in the iCustom). But when I use the first syntax then it says "variable not defined". Should I define it? Something like:

#define bool DoEntryAlerts etc.? Does it make sense to have it twice? Once in the indicator and then in the EA?

Thank you :-).

P.S.: I will add comments, but I have to google for it. Patience, please :-)

 

Hi Rookie,

iCustom only allows values to be passed into it to set the indicator it is running. So in this case, your number 2 example is correct.

You cannot pass out values for variables used and possibly changed by iCustom. The only way to get information out of iCustom is to specify the indicator buffer and time period in the last 2 parameters of iCustom. if you need two or three variables, you must call iCustom 2 or 3 times. Please be aware that this means each iCustom call runs your indicator separately, so 3 calls means it runs three times plus if it is on your chart, that is another time.

Tzuman

 
rookie_forawhile:
Hi Robert,

ok, so i am using the original indicator now. so i have only 3 externs, which should be passed via iCustom. one of my mapped iCustoms should look like this:

1) double Zone1Upper = iCustom(NULL,0,"SDX-ZoneBreakout2",bool DoEntryAlerts,int TimeZoneOfData,int PipsForEntry,0,0);

or this:

2) double Zone1Upper = iCustom(NULL,0,"SDX-ZoneBreakout2",true,0,5,0,0);

this second one is considered as ok by the compiler, but it doesnt make any sense, right? I want those values to passed from the indicator to the EA (IN that case i don't want exact values in the iCustom). But when I use the first syntax then it says "variable not defined". Should I define it? Something like:

#define bool DoEntryAlerts etc.? Does it make sense to have it twice? Once in the indicator and then in the EA?

Thank you :-).

P.S.: I will add comments, but I have to google for it. Patience, please :-)

Hi Rookie,

Yes #2 is the correct one (thanks to Tzuman)...

You are now ready to get values from the indicator.

And it would help you...if you thought of the externs as "settings" in the iCustoms...not variables (not values).

The externs "set" the indicator parameters...and then you get the values from the buffers directly based on that particular set of parameters...

And Yes to your last question - you need to define the variables to be used in the iCustom in BOTH the EA and the indicator. They can be the same named or different..but whatever names you use have to be defined first.

Looks like you are moving forward nicely... Good job so far...

Hope this helps,

Robert

 

iCustom

Hi Cosmiclifeform and Tzuman,

thanks. I hope I am making some progress but I am still missing some C++ basics :-(

I will use the original SDX for the EA and my edited version with emails for confirmation.

ok I think I get it now. So the externs must be in the exact order like in the indicator, right?

So no I added this code to the EA:

To define:

double Zone1Upper[];

double Zone2Upper[];

double Zone1Lower[];

double Zone2Lower[];

double EntrySignalsBuffer[];

To map:

//BEGIN ---- MAP CUSTOM INDICATOR VARIABLE //

double Zone1Upper = iCustom(NULL,0,"SDX-ZoneBreakout2",true,0,5,0,0);

double Zone1Lower = iCustom(NULL,0,"SDX-ZoneBreakout2",true,0,5,0,0);

double Zone2Upper = iCustom(NULL,0,"SDX-ZoneBreakout2",true,0,5,0,0);

double Zone2Lower = iCustom(NULL,0,"SDX-ZoneBreakout2",true,0,5,0,0);

double EntrySignalsBuffer = iCustom(NULL,0,"SDX-ZoneBreakout2",true,0,5,0,0);

//END ---- MAP CUSTOM INDICATOR VARIABLE //

To convert indicator signals into EA's signals to buy/sell:

// BUY ORDER- when the dot is on Zone1Lower line and also Zone1Lower is lower that Zone1Upper then Order value should be set equal to SIGNAL_BUY value (is this logic ok?)

if (Zone1Lower == EntrySignalsBuffer && Zone1Lower < Zone1Upper ) Order = SIGNAL_BUY;

// SELL ORDER- when the dot is on Zone1Upper line and also Zone1Upper is higher that Zone1Lower then Order value should be set equal to SIGNAL_SELL value (is this logic ok?)

if (Zone1Upper == EntrySignalsBuffer && Zone1Lower > Zone1Upper ) Order = SIGNAL_SELL;

Then the EA should handle it? I get no errors in the compiler and when I use strategy tester I get Entry Signals in the Journal but the EA doesnt make any orders. I think that I am missing something basic. Would you mind to take a look?

Thank you very much.

-Robert

Files:
sdx8-ea_v2.mq4  10 kb
 

SDX indicator - Add ALL Externs For iCustom

rookie_forawhile:
Hi Cosmiclifeform and Tzuman,

thanks. I hope I am making some progress but I am still missing some C++ basics :-(

I will use the original SDX for the EA and my edited version with emails for confirmation.

ok I think I get it now. So the externs must be in the exact order like in the indicator, right?

So no I added this code to the EA:

To define:

double Zone1Upper[];

double Zone2Upper[];

double Zone1Lower[];

double Zone2Lower[];

double EntrySignalsBuffer[];

To map:

//BEGIN ---- MAP CUSTOM INDICATOR VARIABLE //

double Zone1Upper = iCustom(NULL,0,"SDX-ZoneBreakout2",true,0,5,0,0);

double Zone1Lower = iCustom(NULL,0,"SDX-ZoneBreakout2",true,0,5,0,0);

double Zone2Upper = iCustom(NULL,0,"SDX-ZoneBreakout2",true,0,5,0,0);

double Zone2Lower = iCustom(NULL,0,"SDX-ZoneBreakout2",true,0,5,0,0);

double EntrySignalsBuffer = iCustom(NULL,0,"SDX-ZoneBreakout2",true,0,5,0,0);

//END ---- MAP CUSTOM INDICATOR VARIABLE //

To convert indicator signals into EA's signals to buy/sell:

// BUY ORDER- when the dot is on Zone1Lower line and also Zone1Lower is lower that Zone1Upper then Order value should be set equal to SIGNAL_BUY value (is this logic ok?)

if (Zone1Lower == EntrySignalsBuffer && Zone1Lower < Zone1Upper ) Order = SIGNAL_BUY;

// SELL ORDER- when the dot is on Zone1Upper line and also Zone1Upper is higher that Zone1Lower then Order value should be set equal to SIGNAL_SELL value (is this logic ok?)

if (Zone1Upper == EntrySignalsBuffer && Zone1Lower > Zone1Upper ) Order = SIGNAL_SELL;

Then the EA should handle it? I get no errors in the compiler and when I use strategy tester I get Entry Signals in the Journal but the EA doesnt make any orders. I think that I am missing something basic. Would you mind to take a look?

Thank you very much.

-Robert

Hi Rookie...

Looks better...but...check your iCustom buffers...

All are buffer 0....?

And for easier testing and better confidence - use only one condition for Buy/Sell to start with...just keep it simple to make sure you are getting...and using...the values correctly.

Then you can use your full Buy/Sell conditions when you are ready ...

Hope this helps you,

Robert

Reason: