The behaviour is entirely correct. You set the Indexes in the init function. Within the start function you only do calculus and your Indexes wont be updated until you switch the timeframe (which causes a deinit, init, start again). What you need to do is this. You need to setindex your new values again (before the return 0) within the start function or alternatively just call init(); before return 0; which jumps in your subfunction (init) to set the correct values.
int start() { ... // all the other code in your start function init(); // call init before you leave start to set the index correctly return(0); }
The behaviour is entirely correct. You set the Indexes in the init function. Within the start function you only do calculus and your Indexes wont be updated until you switch the timeframe (which causes a deinit, init, start again). What you need to do is this. You need to setindex your new values again (before the return 0) within the start function or alternatively just call init(); before return 0; which jumps in your subfunction (init) to set the correct values.
PLEASE BOSS I DIN GET YOU CORRECTLY , PLEASE KINDLY UPDATE ME WITH MY CODE,SO THAT I WILL LEARN FROM IT SIR
THANKS FOR YOUR RESPONSE SIR.
have removed all the alert from it but the arrow is still performing the same problem//+------------------------------------------------------------------+ //| BINARY .mq4 | //| Copyright 2015,YOUNGHADIZ | //| https://www.webthread.com | //+------------------------------------------------------------------+ #property copyright "YOUNGHADIZ" #property link "https://www.webthread.com" #property version " V1.00" #property strict #property indicator_chart_window #property indicator_buffers 2 #property indicator_color1 White #property indicator_color2 White double CrossUp[]; double CrossDown[]; extern string EMAIL=false; int FasterMode = 1; //0=sma, 1=ema, 2=smma, 3=lwma int FasterMA = 1; int SlowerMode = 1; //0=sma, 1=ema, 2=smma, 3=lwma int SlowerMA = 2; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators SetIndexStyle(0, DRAW_ARROW, EMPTY); SetIndexArrow(0, 233); SetIndexBuffer(0, CrossUp); SetIndexStyle(1, DRAW_ARROW, EMPTY); SetIndexArrow(1, 234); SetIndexBuffer(1, CrossDown); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int limit, i, counter; double fasterMAnow, slowerMAnnow, fasterMAprevous, slowerMAprevous, fasterMAafte, slowerMAafter; double Range, AvgRange; int counted_bars=IndicaCounted(); //---- check for possible errors if(counted_bars<1) return(-1); //---- last counted bar will be recounted if(counted_bars>0) counted_bars--; limit=Bars-counted_bars; for(i = 0; i <= limit; i++) { counter=i; Range=0; AvgRange=0; for (counter=i ;counter<=i+9;counter++) { AvgRange=AvgRange+MathAbs(High[counter]-High[counter]); } Range=AvgRange/10; fasterMAnow = iMA(NULL, 0, FasterMA, 0, FasterMode, PRICE_CLOSE, i); fasterMAprevious = iMA(NULL, 0, FastMA, 0, FasterMode, PRICE_CLOSE, i+1); fasterMAafter = iMA(NULL, 0, FasterMA, 0, FastMode, PRICE_CLOSE, i-2); slowerMAnow = iMA(NULL, 0, SlowerMA, 0, SlowerMode, PRICE_OPEN, i); slowerMAprevious = iMA(NULL, 0, SlowerMA, 0, SlowerMode, PRICE_OPEN, i+0); slowerMAafter = iMA(NULL, 0, SlowerMA, 0, SlowerMode, PRICE_OPEN, i-1); if ((fasterMAnow<slowerMAnow) && (fasterMAprevious < slowerMAprevious) && (fasterMAafter > slowerMAafter)) { CrossUp[i] = High[i] - Range*0.5; } else if ((fasterMAnow<sloweMAnow) && (fasterMAprevious > slowerMAprevious) && (fasterMAafter < slowerMAafter)) { CrossDown[i] = Low[i] + Range*0.5; } } return(0); }
You should replace
limit=Bars-counted_bars;
with
if(counted_bars==0) limit=MathMin(Bars-10-1,Bars-MathMax(FasterMA,SlowerMA)-1); else limit=Bars-counted_bars;
The 10 is because you are using 10 for the average range. If you had checked your experts tab, you would see an "array out of range" error.
As you don't need to calculate this every tick, so it makes sense to only check once per bar, so insert
static datetime bar_time=0; if(bar_time==Time[0]) return(0); bar_time=Time[0];
after start()
Also to avoid repainting, it is an idea to only check on closed bars
for(i = 0; i <= limit; i++) {
change to
for(i = 1; i <= limit; i++) {
.
IT NOW WORKING PERFECTLY NOW SIR, BUT I DONT WANT IT TO BE GIVEN ALERT IN EVERY TICK. THANKS FOR YOUR SUPPORT SIR.//+------------------------------------------------------------------+ //| BINARY.mq4| //| Copyright 2015| //| https://www.webthread.com | //+------------------------------------------------------------------+ #property copyright "YOUNGHADIZ" #property link "https://www.webthread.com" #property version "V1.00" #property indicator_chart_window #property indicator_buffers 2 #property indicator_color1 White #property indicator_color2 White double CrossUp[]; double CrossDown[]; extern string EMAIL=false; int FasterMode = 1; //0=sma, 1=ema, 2=smma, 3=lwma int FasterMA = 1; int SlowerMode = 1; //0=sma, 1=ema, 2=smma, 3=lwma int SlowerMA = 2; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators SetIndexStyle(0, DRAW_ARROW, EMPTY); SetIndexArrow(0, 233); SetIndexBuffer(0, CrossUp); SetIndexStyle(1, DRAW_ARROW, EMPTY); SetIndexArrow(1, 234); SetIndexBuffer(1, CrossDown); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int limit, i, counter; double fasterMAnow, slowerMAnow, fasterMAprevious, slowerMAprevious, fasterMAafter, slowerMAafter; double Range, AvgRange; 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++) { counter=i; Range=0; AvgRange=0; for (counter=i ;counter<=i+9;counter++) { AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]); } Range=AvgRange/10; fasterMAnow = iMA(NULL, 0, FasterMA, 0, FasterMode, PRICE_CLOSE, i); fasterMAprevious = iMA(NULL, 0, FasterMA, 0, FasterMode, PRICE_CLOSE, i+1); fasterMAafter = iMA(NULL, 0, FasterMA, 0, FasterMode, PRICE_CLOSE, i-1); slowerMAnow = iMA(NULL, 0, SlowerMA, 0, SlowerMode, PRICE_OPEN, i); slowerMAprevious = iMA(NULL, 0, SlowerMA, 0, SlowerMode, PRICE_OPEN, i+1); slowerMAafter = iMA(NULL, 0, SlowerMA, 0, SlowerMode, PRICE_OPEN, i-1); if ( (fasterMAnow > slowerMAnow) && (fasterMAprevious < slowerMAprevious) && (fasterMAafter > slowerMAafter)) { CrossUp[i] = Low[i] - Range*0.5; if(alertTag<Time[i] && counted_bars!=0) { PlaySound("news.wav");// buy wav Alert(Symbol()," M",Period()," BUY/CALL"); alertTag=Time[i]; } } else if ((fasterMAnow < slowerMAnow) && (fasterMAprevious > slowerMAprevious) && (fasterMAafter < slowerMAafter)) { CrossDown[i] = High[i] + Range*0.5; if(alertTag<counted_bars!=0) { PlaySound("news.wav");// buy wav Alert(Symbol()," M",Period()," SELL/PUT"); alertTag=Time[0]; } } } return(0); }
I don't see how that code will give alerts every tick as it is only processing once per bar.
You also have alertTag which should prevent additional alerts.
Incidently, I don't understand the reason for calling init() before return(). I don't see that it is necessary.
I don't see how that code will give alerts every tick as it is only processing once per bar.
You also have alertTag which should prevent additional alerts.
Incidently, I don't understand the reason for calling init() before return(). I don't see that it is necessary.
k, have removed it but , it still alerting in every new candle
k, have removed it but , it still alerting in every new candle
Before, you said every tick, now you say every candle.
As far as I can tell from the code, it should only alert if the condition is true.
I didn't look too closely at the conditions before. Using these are not a good idea, in my opinion. They paint an arrow on a bar after looking at the following bar. This may cause some repainting on re-initializing as they "look into the future"
fasterMAafter = iMA(NULL, 0, FasterMA, 0, FasterMode, PRICE_CLOSE, i-1);
slowerMAafter = iMA(NULL, 0, SlowerMA, 0, SlowerMode, PRICE_OPEN, i-1);
Before, you said every tick, now you say every candle.
As far as I can tell from the code, it should only alert if the condition is true.
I didn't look too closely at the conditions before. Using these are not a good idea, in my opinion. They paint an arrow on a bar after looking at the following bar. This may cause some repainting on re-initializing as they "look into the future"
Am sorry sir , It was a mistake.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use