Can anyone have idea why this is happened to me? I am new to MQL and created an indicator to show arrow at specific combination of the candles. It appears correct for the past history but for the upcoming candles it requires refresh window. What could be the reason?
- Arrow appears after refreshing window everytime
- fractal not work correctly
- Indicator not updating arrows
Show us the code then. Please use SRC when posting the codes.
#property indicator_chart_window #property indicator_buffers 2 #property indicator_color1 DodgerBlue #property indicator_color2 Magenta //---- input parameters int RSIPeriod=14; int j=0, k=0; bool ArrowUp=false; bool ArrowDown=false; datetime lastAlert; //---- buffers double RSIBuffer[]; double DrawArrowUp[]; double DrawArrowDown[]; int init() { IndicatorBuffers(3); SetIndexStyle(0, DRAW_ARROW,1,2); SetIndexArrow(0, 233); SetIndexBuffer(0, DrawArrowUp); SetIndexStyle(1, DRAW_ARROW,1,2); SetIndexArrow(1, 234); SetIndexBuffer(1, DrawArrowDown); SetIndexStyle(2,DRAW_NONE); SetIndexBuffer(2,RSIBuffer); lastAlert=Time[0]; return(0); } int deinit() { ObjectsDeleteAll(); return(0); } int start() { int i,counted_bars=IndicatorCounted(); double PriceLow1, RSILow1; datetime TimeLow1; double PriceHigh1, RSIHigh1; datetime TimeHigh1; if(Bars<=RSIPeriod) return(0); if(counted_bars<1) for(i=1;i<=RSIPeriod;i++) RSIBuffer[Bars-i]=0.0; i=Bars-RSIPeriod-1; if(counted_bars>=RSIPeriod) i=Bars-counted_bars-1; while(i>=0) { RSIBuffer[i]=iRSI(NULL,0,RSIPeriod,PRICE_CLOSE,i); //BUY CALL Option signal started if (Low[i+2]<Low[i+3] && Low[i+2]<Low[i+1] && RSIBuffer[i+2]<30) { PriceLow1=Low[i+2]; RSILow1=RSIBuffer[i+2]; TimeLow1=Time[i+2]; ArrowUp=true; } if (Low[i+2]<Low[i+3] && Low[i+2]<Low[i+1] && Time[i+2]>TimeLow1 && Low[i+2]<PriceLow1 && RSIBuffer[i+2]>RSILow1) { if (ArrowUp==true) { DrawArrowUp[i+2]=Low[i+2]; WindowRedraw(); if(Time[0]>lastAlert) { lastAlert=Time[0]; Alert(Symbol()+"-Buy..."); } ArrowUp=false; } } //BUY CALL option signal ended //BUY PUT option signal started if (High[i+2]>High[i+3] && High[i+2]>High[i+1] && RSIBuffer[i+2]>70) { PriceHigh1=High[i+2]; RSIHigh1=RSIBuffer[i+2]; TimeHigh1=Time[i+2]; ArrowDown=true; } if (High[i+2]>High[i+3] && High[i+2]>High[i+1] && Time[i+2]>TimeHigh1 && High[i+2]>PriceHigh1 && RSIBuffer[i+2]<RSIHigh1) { if (ArrowDown==true) { DrawArrowDown[i+2]=High[i+2]; WindowRedraw(); if(Time[0]>lastAlert) { lastAlert=Time[0]; Alert(Symbol()+"-Sell..."); } ArrowDown=false; } } //BUY PUT Option signal ended i--; } return(0); }
jrbhatt: It appears correct for the past history but for the upcoming candles it requires refresh window.
You remember ArrowUp/Down from previous bars but you aren't remembering the other values because they are not global or static.double PriceLow1, RSILow1; // PriceLow1 is a random value here : while(i>=0){ : if (Low[i+2]<Low[i+3] && Low[i+2]<Low[i+1] && RSIBuffer[i+2]<30){ // If this isn't true this bar. PriceLow1=Low[i+2]; RSILow1=RSIBuffer[i+2]; TimeLow1=Time[i+2]; ArrowUp=true; } if (Low[i+2]<Low[i+3] && Low[i+2]<Low[i+1] && Time[i+2]>TimeLow1 && Low[i+2]<PriceLow1 && RSIBuffer[i+2]>RSILow1) // then this is bogus.First time and after refresh you do all bars, so the local variables will have valid values (from previous bars.) After that i == 0 mostly, there is only one pass and local variables have random values.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
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