Maybe its because you didnt specified the colors..try this right above the buffers..
#property indicator_color1 Red #property indicator_color2 White
Check the root cause first. Just do simple logic, use Comment() and see if the result correct and then go from there.
I can't understand your meaning.
The indicator is so simple that I just want to find out ma of certain number of bar length. The result is straight forward and can check it from terminal directly.
Where can I add Print() or Comment() to do a "simple" logic check???
Check the values for i?
values for length[i] are ok.
the problem is the values of ma[i], and they are calculated by iMAOnArray function.
I found in help page that iMAOnArray calculates from left to right, so I used i-- instead of i++;
I also have tried to change the value of range (variable) but no meaningful outcome can be found
any suggestion?
values for length[i] are ok.
May be not?
Try
Print("limit: ",(string)limit," loop i: ",(string)(limit-1)," .. 1");
May be not?
Try
Value of length[i] is simply the absolute value of close[i] - open[i]. I can double check them bar by bar on chart and they are correct.
In addition, if I change variable "range" to 1, length[i] should be equal to ma[i] but it's not now. That's the problem.
I'm not totally sure about what you want but try this
#property indicator_separate_window #property indicator_buffers 1 extern int range = 10; //--- indicator buffers double ma[], length[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { IndicatorBuffers(2); //--- indicator buffers mapping IndicatorDigits(Digits); //---- indicator buffers mapping SetIndexBuffer(0,ma); SetIndexBuffer(1,length); //--- drawing settings SetIndexStyle(0,DRAW_HISTOGRAM); SetIndexEmptyValue(0,0.0); SetIndexDrawBegin(0,1); //SetIndexStyle(1,DRAW_HISTOGRAM); //SetIndexEmptyValue(1,0.0); //SetIndexDrawBegin(1,1); //--- name for DataWindow and indicator subwindow label IndicatorShortName("ma"); SetIndexLabel(0,"ma"); //SetIndexLabel(1,"length"); //--- //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { //--- int limit=rates_total-prev_calculated; //--- if(rates_total<2) return(0); //--- int i; for(i=(limit-1); i>=1; i--) { length[i] = MathAbs(Close[i] - Open[i]); } for(i=(limit-1); i>=1; i--) { ma[i] = iMAOnArray(length,0,range,0,MODE_SMA,i); } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+
I have highlighted the changes
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Dear all
I have no idea why ma[] cannot show correct figures (moving average of bar length).
tob2011