#property indicator_chart_window #property indicator_buffers 2 #property indicator_color1 Blue #property indicator_color2 Red double BuyBuffer[]; double SellBuffer[]; double SMA, SMAAlert; double HAOpen, HAClose, HAOpen2, HAClose2; double HAOpena, HAClosea, HAOpen2a, HAClose2a; datetime AlertTime; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit(void) { //---- indicator buffers mapping IndicatorBuffers(6); IndicatorDigits(Digits); SetIndexBuffer(0,BuyBuffer); SetIndexBuffer(1,SellBuffer); //---- drawing settings SetIndexStyle(0,DRAW_ARROW); SetIndexArrow(0,233); //241 option for different arrow head SetIndexStyle(1,DRAW_ARROW); SetIndexArrow(1,234); //242 option for different arrow head //---- name for DataWindow SetIndexLabel(0,"Buy"); SetIndexLabel(1,"Sell"); 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[]) { ArraySetAsSeries(time,true); ArraySetAsSeries(high,true); ArraySetAsSeries(low,true); ArraySetAsSeries(close,true); int limit, i; limit = rates_total-prev_calculated; for (i = 0; i < limit; i++) { BuyBuffer[i+1]=0; SellBuffer[i+1]=0
limit = rates_total-prev_calculated; for (i = 0; i < limit; i++)
The first time prev_calculated == 0 so it processes all bars.
Until a new bar they will be equal and you do nothing.
limit=rates_total-prev_calculated; if(prev_calculated>0) limit++; // Reprocess last bar.
thanks your reply but not worked
limit = rates_total-prev_calculated; for (i = 0; i < limit; i++) { BuyBuffer[i+1]=0; SellBuffer[i+1]=0
when prev_calculated==0
limit=rates_total which is the number of bars on the chart, so limit-1 is the highest index position for the buffers
when i==limit-1,i+1 will give an array out of range error.
The only values assigned to the buffers is zero, in the code that you show, how do you expect it to do anything?
when prev_calculated==0
limit=rates_total which is the number of bars on the chart, so limit-1 is the highest index position for the buffers
when i==limit-1,i+1 will give an array out of range error.
The only values assigned to the buffers is zero, in the code that you show, how do you expect it to do anything?
#property indicator_chart_window #property indicator_buffers 2 #property indicator_color1 Blue #property indicator_color2 Red double BuyBuffer[]; double SellBuffer[]; double SMA, SMAAlert; double HAOpen, HAClose, HAOpen2, HAClose2; double HAOpena, HAClosea, HAOpen2a, HAClose2a; datetime AlertTime; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicator buffers mapping SetIndexBuffer(0,BuyBuffer); SetIndexBuffer(1,SellBuffer); //---- drawing settings SetIndexStyle(0,DRAW_ARROW); SetIndexArrow(0,233); //241 option for different arrow head SetIndexStyle(1,DRAW_ARROW); SetIndexArrow(1,234); //242 option for different arrow head //---- name for DataWindow SetIndexLabel(0,"Buy"); SetIndexLabel(1,"Sell"); //---- return(0); } //+------------------------------------------------------------------+ //| Custor indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- ObjectsDeleteAll(); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int limit, i, counter; int counted_bars=IndicatorCounted(); //---- check for possible errors if(counted_bars<0) return(-1); //---- last counted bar will be recounted // if(counted_bars>0) counted_bars--; limit=Bars-counted_bars; for (i = 0; i <= limit; i++) { BuyBuffer[i+1]=0; SellBuffer[i+1]=0; }This is my previous code and it was works fine, can you please show me how to convert it to new code style in the right way
I don't see how your previous indicator works fine. I refer you to my earlier reply
The only values assigned to the buffers is zero, in the code that you show, how do you expect it to do anything?
.
I don't see how your previous indicator works fine. I refer you to my earlier reply
.
show me how to write the right loop
How can I?
I have no idea what you are trying to do.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi
I was build a Custom Indicator which set buy and sell arrows on the chart with alerts and it was works fine, but when I tried to upgrade the code to MQL4 new build stile with OnCalculate() function the indicator set the arrows to previous bars only in start but not for new bars after it works and don't send alert.
Can any body help me in this
Regards ...