Im 3 month old programming student, i need help to debug this code. The indicator is supposed to place arrows on buy and sell signals but it just scatters arrows all over the chart on candles that dont meet the signal conditions and i have failed to understand what is wrong here.
The buy and sell conditions are +ve RSI movement on M15, buy when RSI on M1 <35, and -ve RSI movement on 1M5, sell when RSI on M1>65.
The same 'i' cannot be used to access data from different timeframes. If your chart runs on M1, your 'i' and 'Bars' are for M1, and you must make use of iBarShift() to get the bar index for other timeframes, like this:
int i4M15 = iBarShift(Symbol(),Period(),Time[i]); buf0 = iRSI(NULL,PERIOD_M15,14,0,i4M15) ; buf1 = iRSI(NULL,PERIOD_M15,14,0,i4M15+1) ;
- Why did you post your MT4 question in the Root / MT5 Indicators
section instead of the MQL4 section, (bottom of the Root page?)
General rules and best pratices of the Forum. - General - MQL5 programming forum
Next time post in the correct place. The moderators will likely move this thread there soon. -
buf0 = iRSI(NULL,PERIOD_M15,14,0,i) ; buf1 = iRSI(NULL,PERIOD_M15,14,0,i+1) ; buf2 = iRSI(NULL,PERIOD_M1,RSIPeriod_M1,0,i);
Like Seng said don't mix apples and oranges. - On MT4: Unless the current chart is that specific pair/TF referenced, you must handle 4066/4073 errors
before accessing candle values.
Download history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26 № 4The function linked to, opens a hidden chart for the symbol/TF in question (if not already open,) thus updating history, and temporarily placing the symbol on Market Watch (if not already there,) so SymbolInfoDouble(symbol, SYMBOL_BID) or MarketInfo(symbol, MODE_BID) don't also return zero on the first call.
-
for (i=Bars-50;i>=0;i--)
Why are recomputing all bars every tick? See How to do your lookbacks correctly. - Don't use NULL.
- You can use NULL in place of _Symbol only in those calls that the documentation specially says you can. iHigh does, iCustom does, MarketInfo does not. OrderSend does not.
- Don't use NULL (except for pointers where you explicitly check for it.) Use _Symbol and _Period, that is minimalist as possible and more efficient.
- Zero is the same as PERIOD_CURRENT which means _Period. Don't hard code numbers.
- MT4: No need for a function call with iHigh(NULL,0,s) just use the predefined arrays, i.e. High[].
The same 'i' cannot be used to access data from different timeframes. If your chart runs on M1, your 'i' and 'Bars' are for M1, and you must make use of iBarShift() to get the bar index for other timeframes, like this:
Hairs were jumping off my head but Oh Man, you just saved me from a nightmare, im adding you to my list of saviours.
Arrows are plotting well now but another problem though, the arrows are plotting on each candle as long as the condition still holds (see image). Is there a way i can make the arrows appear only on the first candle when condition is true and ignore the rest until the condition reverses.?..
- Why did you post your MT4 question in the Root / MT5 Indicators
section instead of the MQL4 section, (bottom of the Root page?)
General rules and best pratices of the Forum. - General - MQL5 programming forum
Next time post in the correct place. The moderators will likely move this thread there soon. - Like Seng said don't mix apples and oranges.
- On MT4: Unless the current chart is that specific pair/TF referenced, you must handle 4066/4073 errors
before accessing candle values.
Download history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26 № 4The function linked to, opens a hidden chart for the symbol/TF in question (if not already open,) thus updating history, and temporarily placing the symbol on Market Watch (if not already there,) so SymbolInfoDouble(symbol, SYMBOL_BID) or MarketInfo(symbol, MODE_BID) don't also return zero on the first call.
- Why are recomputing all bars every tick? See How to do your lookbacks correctly.
- Don't use NULL.
- You can use NULL in place of _Symbol only in those calls that the documentation specially says you can. iHigh does, iCustom does, MarketInfo does not. OrderSend does not.
- Don't use NULL (except for pointers where you explicitly check for it.) Use _Symbol and _Period, that is minimalist as possible and more efficient.
- Zero is the same as PERIOD_CURRENT which means _Period. Don't hard code numbers.
- MT4: No need for a function call with iHigh(NULL,0,s) just use the predefined arrays, i.e. High[].
William, apologies for posting in the wrong place, had not entirely read the rules. I appreciate your feedback, very good and informative. Didn't know about all that but im catching up bit by bit.
Thank you.. I highly appreciate.
Arrows are plotting well now but another problem though, the arrows are plotting on each candle as long as the condition still holds (see image). Is there a way i can make the arrows appear only on the first candle when condition is true and ignore the rest until the condition reverses.?..
You can probably try adding this declaration first:
int i; double buf0,buf1,buf2; static int lastBuySignal=-1, lastSellSignal=-1;
Then within each of your 'if' statement, add this:
if ((buf0 > buf1) && (buf2 < Buy_Level)) { if (lastBuySignal==-1 || lastBuySignal>i+1) ExtMapBuffer1[i]=Low[i]-5*Point; lastBuySignal = i; }
Edit: But for the above to work, you'll have to heed @William Roeder's advice to fix your "for (i=Bars-50; i>=0; i--)" first...
You can probably try adding this declaration first:
Then within each of your 'if' statement, add this:
Edit: But for the above to work, you'll have to heed @William Roeder's advice to fix your "for (i=Bars-50; i>=0; i--)" first...
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
Im 3 month old programming student, i need help to debug this code. The indicator is supposed to place arrows on buy and sell signals but it just scatters arrows all over the chart on candles that dont meet the signal conditions and i have failed to understand what is wrong here.
The buy and sell conditions are +ve RSI movement on M15, buy when RSI on M1 <35, and -ve RSI movement on 1M5, sell when RSI on M1>65.