Please EDIT your post and use the CODE button when you insert code.
MQL5.community - User Memo
- www.mql5.com
You have just registered and most likely you have questions such as, "How do I insert a picture to my a message?" "How do I format my MQL5 source code?" "Where are my personal messages kept?" You may have many other questions. In this article, we have prepared some hands-on tips that will help you get accustomed in MQL5.community and take full advantage of its available features.
-
Please edit your (original) post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum #25 (2019)
Forum rules and recommendations - General - MQL5 programming forum (2023)
Messages Editor - irman1: error-free but nothing will appear.
double upperBand[], lowerBand[]; ⋮ upperBand[i] = ma + stdDev; lowerBand[i] = ma - stdDev;Nothing appears because your arrays have zero size, and your code crashes. You would know that if you looked at the logs or used the debugger.
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
I have written a custom indicator code, and it will attach a to the MT4 chart successfully and error-free but nothing will appear. It is supposed to show me some up and down arrows.
Here is the code
#property indicator_chart_window
// Input parameters
extern int period = 20;
extern double deviation = 2.0;
// Arrow distance from the bands
int arrowDistance = 50;
// Enumerated constants for arrow direction
enum ArrowDirection {
UpArrow = 233,
DownArrow = 234
};
// Initialization function
int init() {
return(0);
}
// Deinitialization function
int deinit() {
return(0);
}
// Main function
int start() {
// Calculate Bollinger Bands
double upperBand[], lowerBand[];
int limit = Bars - period;
for (int i = 0; i <= limit; i++) {
double ma = iMA(NULL, 0, period, 0, MODE_SMA, PRICE_CLOSE, i);
double stdDev = deviation * iStdDev(NULL, 0, period, 0, MODE_SMA, PRICE_CLOSE, i);
upperBand[i] = ma + stdDev;
lowerBand[i] = ma - stdDev;
// Redraw the chart
ChartRedraw();
return(0);
}
// Calculate arrow position
double arrowPosition = 0;
if (Period() == PERIOD_H4 || Period() == PERIOD_D1 ||
Period() == PERIOD_W1 || Period() == 1440) {
if (Close[0] >= upperBand[limit]) {
arrowPosition = upperBand[limit] - arrowDistance * Point;
Comment("Sell @ ", DoubleToStr(arrowPosition, Digits), " (" + DoubleToStr(upperBand[limit], Digits) + ")");
ObjectCreate("SellArrow", OBJ_ARROW, 0, Time[limit], arrowPosition);
ObjectSet("SellArrow", OBJPROP_ARROWCODE, DownArrow);
}
else if (Close[0] <= lowerBand[limit]) {
arrowPosition = lowerBand[limit] + arrowDistance * Point;
Comment("Buy @ ", DoubleToStr(arrowPosition, Digits), " (" + DoubleToStr(lowerBand[limit], Digits) + ")");
ObjectCreate("BuyArrow", OBJ_ARROW, 0, Time[limit], arrowPosition);
ObjectSet("BuyArrow", OBJPROP_ARROWCODE, UpArrow);
}
}
return(0);
}