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

Follow My Leader auto-trading EA
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=502
Page 3 of 4
Author:  garyfritz [ Mon Apr 23, 2012 7:29 pm ]
Post subject:  Re: Follow My Leader auto-trading EA

garyfritz wrote:And I don't think that's the optimal way to use this. I suspect "buy all baskets whose index is rising" and "sell all baskets whose index is falling" would work MUCH better.
Quick illustration: here's how you'd trade one symbol based on the JPY index (dark purple line) rising or falling. Green lines = buy, red lines = sell. This is a very simple implementation and I'm sure you could improve on it, e.g. by adding "dead bands" so you don't get whipsawed when the index goes sideways, or (probably best) trading only the baskets whose indexes are moving up or down the fastest.
CurrStrengthSigs.gif
OK, now I *have* to go get some work done...
Author:  SteveHopwood [ Mon Apr 23, 2012 9:30 pm ]
Post subject:  Re: Follow My Leader auto-trading EA

garyfritz wrote:Steve, I will try to resolve the issues with the indi (in my copious free time :roll:). But since I haven't written any EAs, I haven't discovered if they use the same braindead stupid benighted idiotic f'ing DUMB execution model as indicators. I don't know if fixing the indi will make the code work in an EA.

Though I suppose in a pinch you could just call the indi with iCustom. Grubby but it would let us test it with a minimum of braindamage. If it turns out to be a money machine, we can always put more effort into it to make it pretty.
Yep. This is a 3-stage process:
  • 1) You decide your indi code is working as you intend. No rush. Take your time. I have already done 6 years without it, so a few more days will do no harm.
    2) Once you are happy with your code, I devise a few iCustom calls to interrogate it.
    3) Once we are happy with the calls, we scream to squalou to come and bring the code in house, so an EA does not need to call your indi. :lol:
So Gary, you develop your indi and the rest of us with different levels of CrapMql4 understanding can take it from there.

If you can code an indi at any level, you get my vote feller. The damn things defeat me utterly.

:D
Author:  squalou [ Tue Apr 24, 2012 8:33 am ]
Post subject:  Re: Follow My Leader auto-trading EA

SteveHopwood wrote:
garyfritz wrote:Steve, I will try to resolve the issues with the indi (in my copious free time :roll:). But since I haven't written any EAs, I haven't discovered if they use the same braindead stupid benighted idiotic f'ing DUMB execution model as indicators. I don't know if fixing the indi will make the code work in an EA.

Though I suppose in a pinch you could just call the indi with iCustom. Grubby but it would let us test it with a minimum of braindamage. If it turns out to be a money machine, we can always put more effort into it to make it pretty.
Yep. This is a 3-stage process:
  • 1) You decide your indi code is working as you intend. No rush. Take your time. I have already done 6 years without it, so a few more days will do no harm.
    2) Once you are happy with your code, I devise a few iCustom calls to interrogate it.
    3) Once we are happy with the calls, we scream to squalou to come and bring the code in house, so an EA does not need to call your indi. :lol:
So Gary, you develop your indi and the rest of us with different levels of CrapMql4 understanding can take it from there.

If you can code an indi at any level, you get my vote feller. The damn things defeat me utterly.

:D
sounds like A plan to me...

Honestly, i don't think step 3) will be needed :lol:
iCustom() calls are pain in the ... when backtesting, but here we won't be able to backtest with the currency strength indi anyway, as it requires accessing multiple pairs.

And as i said earlier, the fact that Gary's strength indicator does not yet work properly on live data (i.e when new bars are forming, the EMA calculation as it is gets screwed due to Empty4 design), is IRRELEVANT because the EA is re-loading the indicator with every call to iCustom(), which makes it recalculate all its buffers with the latest available data from scratch, so it is the same as when you are just loading the indicator : it WILL give you the CORRECT output.
Embedding the indicator code into the EA would be another story, it would require the fixed version of the EMA calc.


Sq
Author:  garyfritz [ Tue Apr 24, 2012 6:12 pm ]
Post subject:  Re: Follow My Leader auto-trading EA

Interesting. Thanks for that insight, Sq.

So tell me, does an EA use exactly the same insane execution model as indicators? I.e. re-executing the code for recent bars, etc? That behavior causes repainting in indicators but I would think it would be impossible in EAs. You don't get to go back and change your mind about the trade you placed 3 bars ago. If EAs *don't* use that logic, then how hard is it to move indicator code into an EA?

BTW it would be possible to backtest this, with a bit of effort. We could modify the indicator to dump all its strength values to a file, then write the EA to pull its values from the file instead of the indicator. (Can an EA trade multiple pairs in a backtest?) Might be a pain but it would be nice to be able to see how this would actually work. If that's not possible, I might try dumping pair data to a spreadsheet and hack together a backtest by hand. That definitely WOULD be a pain.

I think data is going to be a bigger problem. This indicator pulls data from 8 pairs. If any of those pairs have bogus data, it throws off the calculation. E.g. PFG has bad data in NZDUSD so the NZD index gets screwed up. It actually screws up everything, but it's strongest in the NZD index.

There's also the question of how to get enough good data to do any decent testing. I don't understand Empty4's model for how much data it charts, how much is available to an EA, etc. Somebody posted a script a while back to populate data in all pairs, but I can't find it. Does anyone have a pointer to that?
Author:  squalou [ Tue Apr 24, 2012 8:49 pm ]
Post subject:  Re: Follow My Leader auto-trading EA

garyfritz wrote:Interesting. Thanks for that insight, Sq.

So tell me, does an EA use exactly the same insane execution model as indicators? I.e. re-executing the code for recent bars, etc? That behavior causes repainting in indicators but I would think it would be impossible in EAs. You don't get to go back and change your mind about the trade you placed 3 bars ago. If EAs *don't* use that logic, then how hard is it to move indicator code into an EA?
No, EAs do not use that logic.
When a tick comes in, start() is called, just like indicators, but EAs do not have access to those indicator data "buffers".
EAs can invoke indicators with iCustom();
iCustom() will :
- load the indicator,
- run its init()
- run its start() ONCE with a "certain" amount of available history data, so it can create its "buffers",
- when start() returns, iCustom() returns with the element of the "buffer" specified by the last 2 arguments passed to iCustom().
This process is performed at each call to iCustom().
This is why fixing the EMA computation does not matter for an EA that would use iCustom(), as the "indicator" will rebuild all of its buffers at each call.

What makes moving indicator code into an EA difficult (sometimes) is that the EA needs to simulate what the indicator does with past candles. It needs to maintain the equivalent of the "Buffers" if past values of the Buffers are needed to produce the latest indicator value.
In order to calculate an EMA in an EA, you need to recalculate all past values of the EMA in order to get the latest EMA value.
Not a big deal in the case of a moving average or similar, but it can get very tricky when the indicator is complex.

garyfritz wrote: BTW it would be possible to backtest this, with a bit of effort. We could modify the indicator to dump all its strength values to a file, then write the EA to pull its values from the file instead of the indicator. (Can an EA trade multiple pairs in a backtest?) Might be a pain but it would be nice to be able to see how this would actually work. If that's not possible, I might try dumping pair data to a spreadsheet and hack together a backtest by hand. That definitely WOULD be a pain.
Agreed!
This is a possible solution.
It requires a 2-steps backtest:
-1- create the currency-strength-values file with a specific indicator (an option added to your indicator will do the trick)
-2- run the backtest where the EA will load the file and retrieve the record corresponding to the timestamp of the "current bar" being handled by the EA in its start() function.
IsTesting() can be used to decide if the EA should call iCustom() ("real-time" mode), or read data from the strength file (backtesting).

The pre-processed strength file could be a CSV where each "line" has a timestamp and the strength value.
Easy to implement.


garyfritz wrote:
I think data is going to be a bigger problem. This indicator pulls data from 8 pairs. If any of those pairs have bogus data, it throws off the calculation. E.g. PFG has bad data in NZDUSD so the NZD index gets screwed up. It actually screws up everything, but it's strongest in the NZD index.
This is a very good point.
And this is again a big bloop in Empty4...

When you copy pair price series with ArrayCopySeries(), it simply copies the price series into that array.
But if bars are missing in the pair original series, then the copied series will also have the same missing bars.
What is even worth is that, just like Close[] or High[] or any other price series, consecutive elements of the series do NOT necessarily have a constant time difference...
In other words, in the H1 Close[] series, Close[9] may be more than 1 hour away from Close[8].
This is what happens on week-ends for instance.
But it also happens when history data is missing...

In your indicator, you are using ArrayCopySeries() to copy all pairs into arrays, and you are then ASSUMING that NzdUsd has the same TIMESTAMP as EurUsd.
But this is WRONG, thanks to Empty4 designers!
This is what is screwing your indexes currently.

You should rather use iClose(pair,0,iTime(NULL,0,i)) to be sure to read the correct candle of each pair for the given "shift".
If that value is 0, then it means that candle does not "exist" in the pair, and you should exclude this pair for the index calculation of that candle.
That will fix the bogus pair data.


garyfritz wrote: There's also the question of how to get enough good data to do any decent testing. I don't understand Empty4's model for how much data it charts, how much is available to an EA, etc. Somebody posted a script a while back to populate data in all pairs, but I can't find it. Does anyone have a pointer to that?


is that it ?
http://www.stevehopwoodforex.com/phpBB3 ... 8437#p8437

sq
Author:  garyfritz [ Tue Apr 24, 2012 9:06 pm ]
Post subject:  Re: Follow My Leader auto-trading EA

No, somebody posted code to do it. That way I could call it for all important pairs from the indicator.
squalou wrote:In your indicator, you are using ArrayCopySeries() to copy all pairs into arrays, and you are then ASSUMING that NzdUsd has the same TIMESTAMP as EurUsd.
But this is WRONG, thanks to Empty4 designers!

Oh BARF. The Empty4 design cockups just never case to amaze me.

You should rather use iClose(pair,0,iTime(NULL,0,i)) to be sure to read the correct candle of each pair for the given "shift".

OK, so I have to loop through each bar, loading up data with iClose, instead of using ArrayCopySeries(). That's a PITA but do-able. THANKS MUCH for saving me figuring that out myself!!

That will fix the bogus pair data.

Not PFG's data. As you scan back in the H4 data, you find that in November 2011 NZDUSD suddenly jumps from about 0.8000 to about 62! It looks like NZDJPY data got dropped in there. Then in May 2011 it starts *alternating* between ~62 and ~0.8000 on every other bar. You can imagine what that does to the calculations...

I told PFG about this yesterday and they informed me that Empty4 only displays 2000 bars, so it's not possible to display that data. "Hello!? Did you think I hallucinated it!? Did you think to LOOK yourself!? Look at these charts and this screen shot from the History Manager!!" Idiots. PFG usually does better than that but I got a McDonald's burger-flipper this time. I'm surprised he didn't ask me if I wanted fries with that.
Author:  squalou [ Tue Apr 24, 2012 9:30 pm ]
Post subject:  Re: Follow My Leader auto-trading EA

garyfritz wrote: Not PFG's data. As you scan back in the H4 data, you find that in November 2011 NZDUSD suddenly jumps from about 0.8000 to about 62! It looks like NZDJPY data got dropped in there. Then in May 2011 it starts *alternating* between ~62 and ~0.8000 on every other bar. You can imagine what that does to the calculations...

I told PFG about this yesterday and they informed me that Empty4 only displays 2000 bars, so it's not possible to display that data. "Hello!? Did you think I hallucinated it!? Did you think to LOOK yourself!? Look at these charts and this screen shot from the History Manager!!" Idiots. PFG usually does better than that but I got a McDonald's burger-flipper this time. I'm surprised he didn't ask me if I wanted fries with that.
:lol:

Then backtesting will have to be done on another crook.
Author:  SWG123 [ Tue Apr 24, 2012 10:07 pm ]
Post subject:  Re: Follow My Leader auto-trading EA

Gary, Squalou - this dialogue is great. Not only am i learning a lot about MQL4 but it also confirms some strange issues I've seen myself with crim data. I thought I was hallucinating at the time but perhaps I still retain a tenuous grip on sanity. :D
Author:  cuzgeorge [ Tue Apr 24, 2012 11:17 pm ]
Post subject:  Re: Follow My Leader auto-trading EA

Agreed, no better place to learn. Really cant keep up with the pace though. I have installed a version without the 'cretin' thingy, hehe, sneaky! , and would be willing to run a test on ava or markets.com if you like. please holler and i'll get it done first thing with a link to myfxbook dingus also if needed.
thanks guys for the great info and read,
cuzgeorge
Author:  jboy [ Tue Apr 24, 2012 11:32 pm ]
Post subject:  Re: Follow My Leader auto-trading EA

I would suggest probably holding off on starting a test until we are finished with this week, and the 2nd iteration is posted. In just the limited trial I'm doing, I can already see this current iteration is not heading in the right direction because we never really hit our TP targets because the scenario #3 keeps cutting our baskets too quickly before there is a chance to hit the TP.
All times are UTC Page 3 of 4