Empty4 has some severe limitations when it comes to controlling indicators from an EA. However, if we do a little bit of creative coding we can get around most of these. For example we can use iCustom to return values from an indicator and we can use global variables to pass values between the EA and indicator but for me I wanted something a little more tightly controlled than global variables. What I wanted was to control the indicator totally from the EA.
I also didn’t want users to enter parameters into the EA and then separately enter parameters into the indicator. For me that’s a little like the left hand not knowing what the right hand is doing. I wanted all parameters entered into the EA and then the EA passes them to the indicator. I also wanted the indicator to be removed when the user removed the EA.
After scouring the internet for ideas I put this example together on how to load an indicator onto a chart and modify its parameters directly from an EA. The end result is not perfect but it does get the job done and I hope it gives others dome ideas to play around with.
Note: I have been coding for over 30 years and I never claim any of my code to ever be original but I thank all of those anonymous and forgotten coders who I have gotten ideas and pieces of code from over the years. I hope that I am lucky enough to be one of those anonymous and forgotten coders for someone else.
Controlling an indicator from an EA
-
skinner36
Controlling an indicator from an EA
You do not have the required permissions to view the files attached to this post.
- tomele
- Administrator
- Posts: 1208
- Joined: Tue May 17, 2016 3:40 pm
- Location: Germany, Forest of Odes, Defending the Limes
Controlling an indicator from an EA
Hey-ho.
Thats the straight way for something I would have done much more complicated.
I would have
* written a template with ChartSaveTemplate()
* read, manipulated and written the template as a text file
* loaded the template again with ChartApplyTemplate()
I confess, your approach is much shorter. I dont know if the result is more predictable. Think of the same indicator loaded twice to the chart with different settings.
But a great idea at all. Thanks.
Cheers
Thomas
Thats the straight way for something I would have done much more complicated.
I would have
* written a template with ChartSaveTemplate()
* read, manipulated and written the template as a text file
* loaded the template again with ChartApplyTemplate()
I confess, your approach is much shorter. I dont know if the result is more predictable. Think of the same indicator loaded twice to the chart with different settings.
But a great idea at all. Thanks.
Cheers
Thomas
Happy pippin, Thomas 
It ain't what you don't know that gets you into trouble.
It's what you know for sure that just ain't so. (Mark Twain)
Keep the coder going: Donate
It ain't what you don't know that gets you into trouble.
It's what you know for sure that just ain't so. (Mark Twain)
Keep the coder going: Donate
-
skinner36
Controlling an indicator from an EA
I am glad you think it is of interest. I like to try to stimulate the old grey cells a bit.
To open multiple indicators just call the function again
To open multiple indicators just call the function again
- tomele
- Administrator
- Posts: 1208
- Joined: Tue May 17, 2016 3:40 pm
- Location: Germany, Forest of Odes, Defending the Limes
Controlling an indicator from an EA
Sure.
You are right if you are in total control of the chart you want to show. But what if the user has added his own version of your indi manually? How do you know which indicator to remove and load again?
Just thinking.
Cheers
Thomas
You are right if you are in total control of the chart you want to show. But what if the user has added his own version of your indi manually? How do you know which indicator to remove and load again?
Just thinking.
Cheers
Thomas
Happy pippin, Thomas 
It ain't what you don't know that gets you into trouble.
It's what you know for sure that just ain't so. (Mark Twain)
Keep the coder going: Donate
It ain't what you don't know that gets you into trouble.
It's what you know for sure that just ain't so. (Mark Twain)
Keep the coder going: Donate
-
skinner36
Controlling an indicator from an EA
Thanks for the reply Thomas, I have read your posts and value your input.tomele » Wed May 02, 2018 8:11 am wrote:Sure.
You are right if you are in total control of the chart you want to show. But what if the user has added his own version of your indi manually? How do you know which indicator to remove and load again?
Just thinking.
Cheers
Thomas
i don't have a problem with a trader adding additional indicators for whatever purpose as long as I am in control of what the EA I have supplied adds to the screen.
I get annoyed from the other point of view. I hate EA's and indicators that add things to the chart but don't clean up properly afterwards.
But to answer your question. You could possibly make a note of the sub window that the indicator was created in? Another option might be to have a label that is off-screen that the EA sets. I will give this some further thought.