
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Putting everything in OnInit() is not the correct way to code an Indicator. You should start there. If you use the OnCalculate() you can more easily know when data is available and when there are updates to that data.
I put everything in OnInit, because I want to make indicator do what it does only once, not on every tick.
Don't try to use any price (or indicator) or server related functions in OnInit (or on load or in OnTimer before you've received a tick), as there may be no connection/chart yet:
That is not the function of OnInit(). It has a purpose. Don't try to put a square peg into a round hole. Read the post above by William. Follow his advice.
William Roeder, understood, the whole process is clear now, please point me to the right place, where I can see, how to make indicator perform its actions in OnCalculate only once, regardless of new ticks being received. I guess I could combine it with the code, provided in this thread, to make my indicator load missing history first, and then do its job only once.
Use OnCalculate() event handler, check the "rates_total" to detect when all the data is loaded, then execute your code once by using a static boolean variable to prevent it running again.
Use OnCalculate() event handler, check the "rates_total" to detect when all the data is loaded, then execute your code once by using a static boolean variable to prevent it running again.
Would like to see some actual code, please.
There are examples in the documentation and much more example code in the CodeBase. How much more do you need?
Maybe something like this. You will need to adjust it based on your exact requirements. Code is untested and only an example.
How much more do you need?
What I needed (wanted) was not to search for it. I'm sure I'm not the 1st one who wants it, and I'm sure William Roeder has a bookmark for it, just like he did e.g. in this post.
I've given you a code sample in the post above. If it does not serve your purpose, then do your research please. We are not going to do it for you.
I've given you a code sample in the post above. If it does not serve your purpose, then do your research please. We are not going to do it for you.
Your post with the code wasn't here, when I posted my previous post. Thanks for the code.