| stevehopwoodforex.com https://www.stevehopwoodforex.com/phpBB3/ Print view |
|
| Changing Templates https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=5463 |
Page 1 of 1 |
| Author: | Bruster400 [ Mon May 21, 2018 12:31 pm ] |
| Post subject: | Changing Templates |
Hi, I'm having a couple of issues with the ChartApplyTemplate function that I hope someone can help me with. I have a template that I like to trade on an offline range bar chart which has a bunch of indicators and a trade pannel EA. However, some of the indicators don't update properly, so occasionally I force them to refresh by re-applying the template. To make this easier I coded the following simple script that I assign to a key and just hit that to refresh. Code: Select all The second problem I had was when I moved this code to an on-screen button within an indicator. Using standard button code taken from the mql4 reference files I put a button on the chart with the sole purpose of refreshing the template. So the active code itself hasn't changed, I just dropped it into an OnChartEvent (with input string Template declared globally). Code: Select all So in theory, this is the same code it's just that it is called from a button click rather than a script. However, the difference is that this way of sending the code removes the live trading permissions from an EA that I have loaded in the template - even though the original template was saved with the EA trading permissions ticked. I've read in the reference that "Live trading and DLL imports permissions cannot be extended for the Expert Advisors launched by applying the template using ChartApplyTemplate() function." The script method works fine though so how do I give the indicator "permission to trade" so that it can extend it to the EA? Or is it simply that scripts can trade and indicators can't? If that's the case, can a button click call a script perhaps? Any ideas? Thanks Bruster |
|
| Author: | Radar [ Mon May 21, 2018 11:46 pm ] |
| Post subject: | Changing Templates |
Hey Bruster, How... Code: Select all Where? In the EA... Indicators cannot trade, so anything launched by indicators also cannot trade. As for how to put buttons into an EA, that's beyond me Have fun! Radar =8^) |
|
| Author: | renexxxx [ Tue May 22, 2018 1:05 am ] |
| Post subject: | Changing Templates |
Hello Bruster, I think you should concentrate on getting the indicator to work on the offline chart, rather than installing buttons you need to press from time to time, to force the indicator to reload. For offline charts there are two things to remember, when it comes to EAs and indicators: 1. Offline charts do not receive ticks. So, whatever you put in the OnTick() event handler (for EAs), or OnCalculate() event handler (for Custom Indicators), is not executed. Instead, create a timer, with EventSetTimer() or EventSetMillisecondTimer(), and put your main loop in the OnTimer() event handler. 2. You have to refresh the latest OHLCV values from the offline file into the automatic variables and arrays (i.e. Ask, Bid, Open[], Close[], High[], Low[], Time[], Volume[] etc), by calling the RefreshRates() function. Do this at the beginning of your OnTimer() function. Provided you have done this, there is no reason why your custom indicator should not update on an offline chart. Templates saved by ChartSaveTemplate() or manually, are saved in the folder: <data_folder>\templates\, where <data_folder> is the folder you get from File->Open Data Folder. Templates loaded by ChartApplyTemplate() are read/loaded from the same <data_folder>\templates\ folder. No need to prefix the template name with '\\'. As Radar already mentioned: An indicator can not trade -- therefore, as a security precaution, MetaQuotes has built their code such that anything that is loaded from an indicator, can not trade either. If you want to load the template by pressing a button, you should create that button and the event handler for that button inside an EA. |
|
| Author: | Bruster400 [ Tue May 22, 2018 3:04 pm ] |
| Post subject: | Changing Templates |
Radar & Renexxxx, Once again you've proved what a great source of expert help this forum can be - very good advice, thanks guys. The advice to get my indicators working offline seems to be the best place to start as it looks like my indicator button is a no-go because of the permissions. One question about using OnTimer rather than OnCalculate is - how best to make it so that the indicator works for both offline and standard charts.... ? I've got two possible ideas. 1 - just copy the current indicator into an additional OnTimer loop and have both the OnCalculate and OnTimer loops check whether the chart is offline or not. Simple but lots of code (albeit copy and pasted!) 2 - or check whether the chart is offline check within an OnTimer loop and if it is, somehow trigger the OnCalculate loop to run? I'll play around with both but if I'm missing the obvious please let me know! Thanks again Bruster |
|
| Author: | renexxxx [ Wed May 23, 2018 2:24 am ] |
| Post subject: | Changing Templates |
I was looking at this a little more and found something interesting: It is possible for the offline generating EA, to send ticks to the offline chart. For instance the offline charts created with MathTrader7_RenkoChartCreatorEA, do receive ticks and therefore the EAs loaded on the offline charts do execute the OnTick() event handler. I didn't code that EA and I don't have the source code for it, but I think it uses the window message "Metatrader4_Internal_Message", that is sent with the WM_COMMAND 0x822c. I am not a big Renko and/or Offline chart user, therefore wasn't aware of this before. But I tested with the little attached EA, that indeed these offline charts do receive ticks. So, I now have had to eat my own words. Good luck with your project. |
|
| Author: | Bruster400 [ Wed May 23, 2018 2:13 pm ] |
| Post subject: | Changing Templates |
Hi, Thanks for this, very interesting and helpful. I've run your EA on my charts and although I don't use the same generator, I too get ticks. I'm not sure how they are generated though... it doesn't look like an OnTimer call because they are irregular much like normal ticks - several in one second and sometimes a 3 or even 4 second delay between them. However, whilst that means that I don't have to go down the full OnTimer loop route I'm still going to follow up on the other advice you've given. In fact, your path advice for finding my templates folder worked perfectly and I will certainly be putting in some RefreshRates() calls. Thanks again for your help Bruster |
|
| All times are UTC | Page 1 of 1 |
|
Powered by phpBB® Forum Software © phpBB Limited |
|