Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refs #11. Renamed "index" variable names into "_idx" to prevent conflicts #727

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Array.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -753,12 +753,12 @@ static int GetLowestArrDoubleValue(double& arr[][], int key) {
}

template <typename X>
static void ArrayStore(ARRAY_REF(X, array), int index, X value, int reserve_size = 0) {
if (index >= ArraySize(array)) {
ArrayResize(array, MathMax(index + 1, ArraySize(array)), reserve_size);
static void ArrayStore(ARRAY_REF(X, array), int _idx, X value, int reserve_size = 0) {
if (_idx >= ArraySize(array)) {
ArrayResize(array, MathMax(_idx + 1, ArraySize(array)), reserve_size);
}

array[index] = value;
array[_idx] = value;
}
};

Expand Down
10 changes: 5 additions & 5 deletions Chart.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -378,23 +378,23 @@ class Chart : public Market {
*
* In case of error, check it via GetLastError().
*/
double GetPeakPrice(int bars, int mode, int index, ENUM_TIMEFRAMES timeframe = PERIOD_CURRENT) {
double GetPeakPrice(int bars, int mode, int _idx, ENUM_TIMEFRAMES timeframe = PERIOD_CURRENT) {
int ibar = -1;
// @todo: Add symbol parameter.
double peak_price = GetOpen(0);
switch (mode) {
case MODE_HIGH:
ibar = ChartStatic::iHighest(symbol, timeframe, MODE_HIGH, bars, index);
ibar = ChartStatic::iHighest(symbol, timeframe, MODE_HIGH, bars, _idx);
return ibar >= 0 ? GetHigh(timeframe, ibar) : false;
case MODE_LOW:
ibar = ChartStatic::iLowest(symbol, timeframe, MODE_LOW, bars, index);
ibar = ChartStatic::iLowest(symbol, timeframe, MODE_LOW, bars, _idx);
return ibar >= 0 ? GetLow(timeframe, ibar) : false;
default:
return false;
}
}
double GetPeakPrice(int bars, int mode = MODE_HIGH, int index = 0) {
return GetPeakPrice(bars, mode, index, Get<ENUM_TIMEFRAMES>(CHART_PARAM_TF));
double GetPeakPrice(int bars, int mode = MODE_HIGH, int _idx = 0) {
return GetPeakPrice(bars, mode, _idx, Get<ENUM_TIMEFRAMES>(CHART_PARAM_TF));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions Chart.struct.tf.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ struct ChartTf {
* @param
* _tf ENUM_TIMEFRAMES_INDEX Specify timeframe index enum.
*/
static ENUM_TIMEFRAMES const IndexToTf(ENUM_TIMEFRAMES_INDEX index) {
static ENUM_TIMEFRAMES const IndexToTf(ENUM_TIMEFRAMES_INDEX _idx) {
// @todo: Convert it into a loop and using tf constant, see: TfToIndex().
switch (index) {
switch (_idx) {
case M1:
return PERIOD_M1; // 1 minute.
case M2:
Expand Down
4 changes: 2 additions & 2 deletions Convert.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,8 @@ class Convert {
int i, j;
len = StringLen(in);
if (len % 4 != 0) len = len - len % 4;
int size = ArraySize(output);
if (size < len / 4) {
int _size = ArraySize(output);
if (_size < len / 4) {
ArrayResize(output, len / 4);
}
for (i = 0, j = 0; j < len; i++, j += 4) {
Expand Down
6 changes: 3 additions & 3 deletions DictBase.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ class DictBase {
*/
bool HasFlags(int flags) { return (_flags & flags) == flags; }

DictSlot<K, V>* GetSlot(const unsigned int index) {
if (index >= GetSlotCount()) {
DictSlot<K, V>* GetSlot(const unsigned int _idx) {
if (_idx >= GetSlotCount()) {
// Index of out bounds.
return NULL;
}

return &_DictSlots_ref.DictSlots[index];
return &_DictSlots_ref.DictSlots[_idx];
}

/**
Expand Down
25 changes: 14 additions & 11 deletions Draw.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class Draw;
bool ObjectCreate(string _name, ENUM_OBJECT _otype, int _swindow, datetime _t1, double _p1) {
return Draw::ObjectCreate(0, _name, _otype, _swindow, _t1, _p1);
}
bool ObjectCreate(string _name, ENUM_OBJECT _otype, int _swindow, datetime _t1, double _p1, datetime _t2, double _p2) {
return Draw::ObjectCreate(0, _name, _otype, _swindow, _t1, _p1, _t2, _p2);
}
bool ObjectDelete(string _name) { return Draw::ObjectDelete(_name); }
bool ObjectSet(string _name, int _prop_id, double _value) { return Draw::ObjectSet(_name, _prop_id, _value); }
int ObjectsTotal(int _type = EMPTY) { return Draw::ObjectsTotal(); }
Expand Down Expand Up @@ -126,34 +129,34 @@ class Draw : public Chart {
* @return
* If successful, returns true, otherwise false.
*/
static bool SetIndexLabel(int index, string text) {
static bool SetIndexLabel(int _idx, string text) {
#ifdef __MQL4__
// https://docs.mql4.com/customind/setindexlabel
::SetIndexLabel(index, text);
::SetIndexLabel(_idx, text);
return true;
#else
// https://www.mql5.com/en/docs/customind/plotindexsetstring
return PlotIndexSetString(index, PLOT_LABEL, text);
return PlotIndexSetString(_idx, PLOT_LABEL, text);
#endif
}

/**
* Sets the new type, style, width and color for a given indicator line.
*
*/
static void SetIndexStyle(int index, int type, int style = EMPTY, int width = EMPTY, color clr = CLR_NONE) {
static void SetIndexStyle(int _idx, int type, int style = EMPTY, int width = EMPTY, color clr = CLR_NONE) {
#ifdef __MQL4__
// https://docs.mql4.com/customind/setindexstyle
::SetIndexStyle(index, type, style, width, clr);
::SetIndexStyle(_idx, type, style, width, clr);
#else
if (width != EMPTY) {
PlotIndexSetInteger(index, PLOT_LINE_WIDTH, width);
PlotIndexSetInteger(_idx, PLOT_LINE_WIDTH, width);
}
if (clr != CLR_NONE) {
PlotIndexSetInteger(index, PLOT_LINE_COLOR, clr);
PlotIndexSetInteger(_idx, PLOT_LINE_COLOR, clr);
}
PlotIndexSetInteger(index, PLOT_DRAW_TYPE, type);
PlotIndexSetInteger(index, PLOT_LINE_STYLE, style);
PlotIndexSetInteger(_idx, PLOT_DRAW_TYPE, type);
PlotIndexSetInteger(_idx, PLOT_LINE_STYLE, style);
#endif
}

Expand Down Expand Up @@ -299,9 +302,9 @@ class Draw : public Chart {
/**
* Draw a line given the price.
*/
void ShowLine(string oname, double price, int colour = Yellow) {
void ShowLine(string oname, double price, int _colour = Yellow) {
Draw::ObjectCreate(chart_id, oname, OBJ_HLINE, 0, GetBarTime(), price);
Draw::ObjectSet(oname, OBJPROP_COLOR, colour);
Draw::ObjectSet(oname, OBJPROP_COLOR, _colour);
Draw::ObjectMove(oname, 0, GetBarTime(), price);
}

Expand Down
12 changes: 6 additions & 6 deletions Indicator.struct.cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,16 @@ class IndicatorCalculateCache : public Dynamic {
* Returns existing or new cache as a child of current one. Useful when indicator uses other indicators and requires
* unique caches for them.
*/
IndicatorCalculateCache<C> *GetSubCache(int index) {
if (index >= ArraySize(subcaches)) {
ArrayResize(subcaches, index + 1, 10);
IndicatorCalculateCache<C> *GetSubCache(int _idx) {
if (_idx >= ArraySize(subcaches)) {
ArrayResize(subcaches, _idx + 1, 10);
}

if (subcaches[index] == NULL) {
subcaches[index] = new IndicatorCalculateCache();
if (subcaches[_idx] == NULL) {
subcaches[_idx] = new IndicatorCalculateCache();
}

return subcaches[index];
return subcaches[_idx];
}

/**
Expand Down
6 changes: 3 additions & 3 deletions Log.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,10 @@ class Log : public Object {
}

bool DeleteByTimestamp(datetime timestamp) {
int size = ArraySize(data);
if (size > 0) {
int _size = ArraySize(data);
if (_size > 0) {
int offset = 0;
for (int i = 0; i < size; i++) {
for (int i = 0; i < _size; i++) {
if (data[i].timestamp == timestamp) {
Erase(data, i);
return true;
Expand Down
6 changes: 3 additions & 3 deletions MiniMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ class MiniMatrix2d {
T Get(int _x, int _y) { return data[(size_x * _y) + _x]; }

void Set(int _x, int _y, T _value) {
int index = (size_x * _y) + _x;
int _idx = (size_x * _y) + _x;

if (index < 0 || index >= (size_x * size_y)) {
if (_idx < 0 || _idx >= (size_x * size_y)) {
Alert("Array out of range!");
}

data[index] = _value;
data[_idx] = _value;
}

int SizeX() { return size_x; }
Expand Down
2 changes: 1 addition & 1 deletion Serializer.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class Serializer {
/**
* Returns child node for a given index or NULL.
*/
SerializerNode* GetChild(unsigned int index) { return _node ? PTR_ATTRIB(_node, GetChild(index)) : NULL; }
SerializerNode* GetChild(unsigned int _idx) { return _node ? PTR_ATTRIB(_node, GetChild(_idx)) : NULL; }

/**
* Returns floating-point precision.
Expand Down
16 changes: 8 additions & 8 deletions SerializerJson.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,9 @@ class SerializerJson {
return root;
}

static SerializerNode* GracefulReturn(string error, unsigned int index, SerializerNode* root,
static SerializerNode* GracefulReturn(string error, unsigned int _idx, SerializerNode* root,
SerializerNodeParam* key) {
Print(error + " at index ", index);
Print(error + " at index ", _idx);

if (root != NULL) delete root;

Expand All @@ -337,10 +337,10 @@ class SerializerJson {
return NULL;
}

static bool ExtractNumber(string& data, unsigned int index, string& number) {
static bool ExtractNumber(string& data, unsigned int _idx, string& number) {
string str;

for (unsigned int i = index; i < (unsigned int)StringLen(data); ++i) {
for (unsigned int i = _idx; i < (unsigned int)StringLen(data); ++i) {
#ifdef __MQL5__
unsigned short ch = StringGetCharacter(data, i);
#else
Expand All @@ -350,7 +350,7 @@ class SerializerJson {
if (ch >= '0' && ch <= '9') {
str += ShortToString(ch);
} else if (ch == '.') {
if (i == index) {
if (i == _idx) {
return false;
}
str += ShortToString(ch);
Expand All @@ -364,12 +364,12 @@ class SerializerJson {
return true;
}

static string ExtractString(string& data, unsigned int index) {
for (unsigned int i = index; i < (unsigned int)StringLen(data); ++i) {
static string ExtractString(string& data, unsigned int _idx) {
for (unsigned int i = _idx; i < (unsigned int)StringLen(data); ++i) {
unsigned short ch = StringGetCharacter(data, i);

if (ch == '"') {
return StringSubstr(data, index, i - index);
return StringSubstr(data, _idx, i - _idx);
}
}

Expand Down
8 changes: 4 additions & 4 deletions SerializerNode.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -279,15 +279,15 @@ class SerializerNode {
/**
* Returns pointer to the child node at given index or NULL.
*/
SerializerNode* GetChild(unsigned int index) { return index >= _numChildren ? NULL : _children[index]; }
SerializerNode* GetChild(unsigned int _idx) { return _idx >= _numChildren ? NULL : _children[index]; }

/**
* Removes child with given index.
*/
void RemoveChild(unsigned int index) {
delete _children[index];
void RemoveChild(unsigned int _idx) {
delete _children[_idx];

for (unsigned int i = ArraySize(_children) - 2; i >= index; --i) {
for (unsigned int i = ArraySize(_children) - 2; i >= _idx; --i) {
_children[i] = _children[i + 1];
}
}
Expand Down
5 changes: 4 additions & 1 deletion Terminal.define.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@
// @docs
// - https://docs.mql4.com/common/setusererror
// - https://www.mql5.com/en/docs/common/SetUserError

#ifndef __MQL5__
#define ERR_USER_ARRAY_IS_EMPTY 1
#define ERR_USER_INVALID_ARG 2
#define ERR_USER_INVALID_BUFF_NUM 3
#define ERR_USER_INVALID_HANDLE 4
#define ERR_USER_ITEM_NOT_FOUND 5
#endif
#define ERR_USER_INVALID_ARG 2
#define ERR_USER_NOT_SUPPORTED 6

// Return codes of the trade server.
Expand Down