| stevehopwoodforex.com https://www.stevehopwoodforex.com/phpBB3/ Print view |
|
| Indi to Function - help needed.... https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=5147 |
Page 1 of 1 |
| Author: | Bruster400 [ Tue Apr 25, 2017 8:41 am ] |
| Post subject: | Indi to Function - help needed.... |
Hi, In typical bloke style I've been going round in circles on this one for ages trying to solve it myself but I've finally given up and need some help. I'm trying to use the attached Heiken Ashi smoothed indicator within an EA as trend direction (based on the last closed candle). I've got it working using an iCustom call but I'd like to incorporate it into the EA as a function - I've tried to do it as an include and couldn't get that working either! The idea is that an internal function call will be less cpu intensive as it doesn't have to calculate all bars and I will only need the opens and closes and not the highs and lows. It also makes it neat and portable without having to move the indicator with the EA each time. My attempt is here - with comments Code: Select all I think the issue might be with the arrays as series but I can't find a combination that works. I'm sure this should be done as an include file in OOP but that's well beyond me at the moment. If anyone can help point me in the right direction that would be great! Thanks Bruce |
|
| Author: | renexxxx [ Wed Apr 26, 2017 6:42 am ] |
| Post subject: | Indi to Function - help needed.... |
Bruce, I am like you and I loathe iCustom calls, especially, if/when they are totally unnecessary. However, in this case, an iCustom call (to the Heiken Ashi Smoothed indicator) is not a lot worse (in terms of efficiency) than a function call to a function that does the calculations internally. Why is that? Because, in this case, the calculated values for shift=n depend on the calculated values for shift=n+1. In other words, this is a Markov Chain. Even if we are only interested in the calculated values for shift=0, we need a sufficiently large lead-up (i.e. lookback) to ensure that the calculated values for shift=0 have converged to their final values. (The calculated values for shift=0, depend on the calculated values for shift=1, which in turn depend on the calculated values for shift=2, which in turn ... .... etc etc.) I have attached a script with two functions: getHARates() and getHASmoothedRates() (the latter one is the one you are interested in). Both these functions fill an internal array HA[] of type Rates with their OHLC values. The script calls these functions with a lookback of 200 bars, which is sufficient to ensure that the values at shift=0 are converged. (The script prints the OHLC values to the "Experts"-tab, so that you can verify that indeed the values from the getHASmoothedRates() function are the same as those from the indicator. In any case, whether you use an iCustom call, or the internal function, you should try to limit the number of calls. (eg. don't call them for every tick, but perhaps only on a new bar). Hope that this is of any help to you. |
|
| Author: | Bruster400 [ Wed Apr 26, 2017 7:32 am ] |
| Post subject: | Indi to Function - help needed.... |
Thank you so much! As always you've shown me how far I've got to go with learning this stuff!! I really like the use of a Structure for assigning variables to the main array - much easier to keep track of than coordinates! I've also not seen the ternary operator before instead of if/else - very neat. I'll need to look at this more closely though because I can't currently see where I've gone wrong. You use separate dimensions in one array to capture the values rather than the 4 arrays I used and you've used a "for loop" rather than a "while" but essentially the order of things seems similar. I'll need to look again at my arrays and make sure I've got the sizes and series correct etc. - All just to learn from of course because I'll be using your excellent solution in my EA!! Thanks once again for sharing your time and expertise - it really does help. Bruce |
|
| Author: | ruktoa [ Fri Apr 28, 2017 7:58 pm ] |
| Post subject: | Indi to Function - help needed.... |
The attached code calculates MA*MA - MA*MA*MA using weighting coefficient tables. dMs: EMA(34)*EMA(8) dSs: EMA(34)*EMA(3)*EMA(8) dWts: dMs-dSs |
|
| All times are UTC | Page 1 of 1 |
|
Powered by phpBB® Forum Software © phpBB Limited |
|