See ArraySetAsSeries() for your personal arrays when trying to use the built-in functions like iMAOnArray() with them.
phy:
I did already but with no success. How would you implement it in the above code?
See ArraySetAsSeries() for your personal arrays when trying to use the built-in functions like iMAOnArray() with them.
Like this example.
Change the indicator option from false to true to set the array as a series array. You can do that while the indicator is running.
#property indicator_separate_window #property indicator_buffers 2 #property indicator_color1 Red #property indicator_color2 DodgerBlue extern bool UseSeriesArray = false; double ma[]; double maOnArray[]; double array[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { SetIndexStyle(0,DRAW_LINE); SetIndexBuffer(0,ma); SetIndexStyle(1,DRAW_LINE); SetIndexBuffer(1,maOnArray); return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int counted_bars=IndicatorCounted(); ArrayResize(array, Bars); ArraySetAsSeries(array, UseSeriesArray); // Option sets true or false int period = 13; // Fill private array with prices
for(int i = Bars-1; i >= 0; i--){ array[i] = Close[i]; } // display indicators. if the private array is good, the two lines will be the same double offset = 10*Point; // so the two indicators don't overlap exactly for( i = Bars-1-period; i >= 0; i--){ ma[i] = iMA(Symbol(), 0, period, 0, 0, 0, i); maOnArray[i] = iMAOnArray(array, 0, period, 0, 0, i) - offset; } return(0); }
Great phy, it works. Thanks a lot.
Any idea why I keep getting "cannot resize the array" error though? It seems the array is resized (the number of elements in the array increases by 1 with each new bar) but I still get the error with each new tick.
Any idea why I keep getting "cannot resize the array" error though? It seems the array is resized (the number of elements in the array increases by 1 with each new bar) but I still get the error with each new tick.
Hey phy,
as promissed, you deserve a part of the money I got for the indicator. Drop me a line at jan[dot]klimo[@t]gmail[dot]com if you have paypal and care to accept a few bucks ;).
Take care,
Jan
as promissed, you deserve a part of the money I got for the indicator. Drop me a line at jan[dot]klimo[@t]gmail[dot]com if you have paypal and care to accept a few bucks ;).
Take care,
Jan
This forum needs private messaging...
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
I would like to kindly ask you for help with the following issue:
What I want to do, is to draw an SMA (which is drawn OK) and to create a channel around it based on the volatility of the previous days. I create an array with daily ranges (OK as well) and try to use iMAOnArray to smoothe it. The problem I keep having is that the indicator seems to be using oldest ranges for the latest bars, because the values for the current bar changes when I load new bars into history.
Here is the part that causes trouble:
Attached is the whole indicator. Will be glad to reward the brave individual who fixes this.
Take care,
Jan