stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

iConfused with iCustom!!!
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=5323
Page 1 of 2
Author:  Bruster400 [ Thu Nov 02, 2017 11:27 am ]
Post subject:  iConfused with iCustom!!!

Hi,

I've written an indicator that draws breakout boxes and it works fine. I now want to call this indi from an EA using iCustom(). I've made an "EA" version of the indicator for this purpose where I've changed all the inputs that don't affect the result (line styles and colours etc) to internal globals so the indicator now only has three user inputs:
2017-11-02_1053.png
I know the buffer that I need to call and I want the signal from the last closed candle so it should be an easy case of using a call such as this:

Code: Select all

BoxValue = iCustom(_Symbol,0,"MySqueezeBoxes_FOR_EA",LookBackBars,SqueezeZonePoints,MinBarsBetweenBoxes,21,1);
The inputs are declared like this in BOTH the indicator and the EA:

Code: Select all

//  user inputs:
extern int                     LookBackBars = 90;
extern int                     SqueezeZonePoints = 130;
extern int                     MinBarsBetweenBoxes = 60;
This should all be very simple and in fact, using this setup the EA takes trades. The problem is that it only takes trades for the default indicator values and not those passed via the iCustom call. The EA seems to be working fine using the defaults but it's ignoring the parameters passed with the iCustom call and is just using the defaults in the indicator. If I change the user inputs in the EA, it just continues to trade according to the indicator's defaults and ignores my settings.

I really don't want to take up people's time unnecessarily so before I get into posting pages and pages of indicator, EA and include code, has anyone else had a similar problem? Can anyone think of the things I could try differently?

Thanks

Bruster
Author:  tomele [ Thu Nov 02, 2017 12:50 pm ]
Post subject:  iConfused with iCustom!!!

Hi Bruster.

What happens if you define the inputs as "input int" instead of "extern int"?
Author:  Bruster400 [ Thu Nov 02, 2017 1:01 pm ]
Post subject:  iConfused with iCustom!!!

tomele » Thu Nov 02, 2017 1:50 pm wrote:Hi Bruster.

What happens if you define the inputs as "input int" instead of "extern int"?
Hi,

Thanks for helping. The same thing happens with both extern and input. I actually had them as input originally - extern was my attempt to check them both. I've also tried changing the names of the variables in the EA vs the Indicator but that hasn't changed anything.

It's very strange, I've never had this issue calling iCustom before, just thought maybe someone else had come across it.

Thanks again for your help,

Bruster.
Author:  tomele [ Thu Nov 02, 2017 1:21 pm ]
Post subject:  iConfused with iCustom!!!

Very strange.

You could try it in a fresh installed environment.

As what I know, iCustom sometimes can be problematic. I would always prefer to integrate the indi code directly into the EA or put it into a library. That also makes it faster.

Good luck.
Author:  Bruster400 [ Thu Nov 02, 2017 3:57 pm ]
Post subject:  iConfused with iCustom!!!

tomele wrote:Very strange.

You could try it in a fresh installed environment.

As what I know, iCustom sometimes can be problematic. I would always prefer to integrate the indi code directly into the EA or put it into a library. That also makes it faster.

Good luck.
I'll try the fresh install. I think you're probably right about the integration but having got it working well as an indicator, the thought of needing to re-write it for EA is painful! :( May well be the only way though.

Thanks again

Bruster
Author:  tomele [ Thu Nov 02, 2017 5:46 pm ]
Post subject:  iConfused with iCustom!!!

tomele wrote:got it working well as an indicator, the thought of needing to re-write it for EA is painful
Dont be scared. There is some code in the indi that fills the buffer. Take that code and cast it into a function in the EA. Instead of assigning the value to the buffer, the function simply returns the value. Then you call this function instead of iCustom. No rocket science at all. If you run into problems, just ask. There will be people in this brilliant forum to help you. Me included.

Good luck.
Author:  SteveHopwood [ Thu Nov 02, 2017 10:38 pm ]
Post subject:  iConfused with iCustom!!!

Bruster, just to back up what Thomas has written here: incorporate an indi code into your EA whenever you possibly can. The saving on cpu resources is huge.

Here is what I write to EA commissioners whinging to me that the EA I wrote for them calling 5 Crap Custom Abortions has slowed their machine to a crawl. Back in the days when I was daft enough to accept such commissions, I saved it in a doc so I could merely copy/paste it to them:
The biggest problem with Crap Custom Abortions (known by the uninitiated as 'custom indicators') is one that lies at the heart of CrapTx. When an EA consults an indicator, the platform loads it into memory, then unloads it again once it has responded to the EA call. This takes time.

An indi has to do a lot of work up front when loaded onto a chart. Most of them are based on some sort of moving average, and the calculation has to be done over every bar on the chart. On subsequent ticks, the indi only has to update its calculation by updating the last x bars actually involved – the reason that, say, a moving average indi does not make your cpu emit blue smoke.

Custom indis typically consist of a number of calls to the regular indicators that ship with Empty4, and manipulate the information thus gleaned according to what the coder requires. An indicator such as AllAverages will make a number of calls to standard indicators. At each tick; each standard indi called by the custom indi is loaded, does all the up-front stuff, used, then unloaded. This takes a long time. Ridiculous, but that is how it works, and is the reason that custom indis such as AA and VQ slow your machine.

And then, we put the EA/Crap Custom Abortion on multiple charts.................................
:xm:
Author:  simplex [ Fri Nov 03, 2017 10:26 am ]
Post subject:  iConfused with iCustom!!!

Bruster400 » 02 Nov 2017, 17:57 wrote:I think you're probably right about the integration but having got it working well as an indicator, the thought of needing to re-write it for EA is painful!
To reduce your pain, start with your indicator again: move the main logic that's required in your EA from OnCalculate() into a separate function, which then is called from OnCalculate(). This is not really difficult. Once this is working, try the very same function in your EA. Keep in mind that nor every action your indi might perform like drawing rectangles on a chart or something will make sense in the EA.

To sort this out, divide your code into separate functions, if applicable: functions that perform trading related calculations (the analytical layer) and separate functions that display the results on chart (the visual layer). In most cases, the analytical functions should work in indicators and EAs as well.

Visualization in EAs as compared to indicators will be quite different.
Author:  Bruster400 [ Wed Nov 08, 2017 9:22 pm ]
Post subject:  iConfused with iCustom!!!

Steve and Simplex,

Thanks guys for the additional help, really appreciate it. I'm working on putting the indicator into my EA directly. I was avoiding it because it uses multiple buffers for the internal calculations and I'm having to recreate these with arrays in the EA which is a pain.

On a separate note, I read somewhere that iCustom had been improved in one of the recent build changes and it is now much faster. I can't find the post ( :arrrg: ) but the general gist was that the calls have been improved by only initialising the indicator once and keeping it open in memory with all the buffers populated so that it doesn't recalculate historic bars on each new call. Of course that's all great if it actually works!....

Thanks again,

Bruster
Author:  renexxxx [ Thu Nov 09, 2017 12:24 am ]
Post subject:  iConfused with iCustom!!!

Bruster400 » Thu Nov 09, 2017 7:22 am wrote: On a separate note, I read somewhere that iCustom had been improved in one of the recent build changes and it is now much faster. I can't find the post ( :arrrg: ) but the general gist was that the calls have been improved by only initialising the indicator once and keeping it open in memory with all the buffers populated so that it doesn't recalculate historic bars on each new call. Of course that's all great if it actually works!....
Yes, that is true. An EA will load and cache in memory an instance of the indicator for each unique combination of its input parameters, as specified in the iCustom call. This can be demonstrated by the attached TestEA and TestIndicator: In the OnInit of TestIndicator there is a print statement telling us that it is being initialized. The TestEA loads TestIndicator with three different sets of input parameters: therefore Empty4 loads three different instances of the indicator and keeps them cached in memory -- resulting in only three print statements.
All times are UTC Page 1 of 2