Опубликовал пост Пример математически правильной Торговой Системы Ниже математически правильная ТС с проверкой, что это так. Логика ТС следующая: переворачивается вовнутрь, когда цена с запасом пересекает EMA-шку от цены. // Пример математически правильной ТС с возможностью ее проверки в MT5-Тестере. // https://www.mql5... Добавил тему...
Not a big fan of sharing my own work, so some runtime optimisations for Pod arrays have been cut out. Instead, slightly extended functionality: - compiles for MT4 (build 1262, ME 2380) and MT5 (build 2380, ME 2380); - Supports both Pod and NonPod structures; - works with static and dynamic arrays of structures;
#property strict#define PRINT(x) ; Print(#x, ":", string(x))
#define CONSTRAINT(ex) if(false){string test = typename(ex);}
//+------------------------------------------------------------------+//| Test Inviroment |//+------------------------------------------------------------------+struct Pod{
int value;
};
struct NonPod : public Pod{
uchar data[];
};
template<typename T>
void ArrayInit(T &arr[]){
int size = ArraySize(arr);
for(int i = 0; i < size; ++i){
arr[i].value = size - i;
}
}
template<typename T>
string ArrayPrintValue(T &arr[]){
string result = "";
for(int i = 0; i < ArraySize(arr); ++i){
result += string(arr[i].value) + " ";
}
return result;
}
//+------------------------------------------------------------------+//| Fixed code |//+------------------------------------------------------------------+template <typename T>
void ArrayReindex( T &Array[], constdouble &TmpSort[][2] )
{
T TmpArray[];
for (int x = ::ArrayResize(TmpArray, ::ArrayRange(TmpSort, 0)) - 1; x >= 0; x--){
TmpArray[x] = Array[(int)(TmpSort[x][1] + 0.1)];
}
#ifdef __MQL5__if(!::ArraySwap(Array, TmpArray)){
ArrayFunctions::ArrayCopy(Array, TmpArray);
}
#endif
#ifdef __MQL4__
ArrayFunctions::ArrayCopy(Array, TmpArray);
#endif
return;
}
// Сортировка массива структур и указателей на объекты по (под-) полю/методу. #define ArraySortStruct(ARRAY, FIELD) \
{ \
double TmpSort[][2]; \
int size = ::ArraySize(ARRAY); \
::ArrayResize(TmpSort, ::ArraySize(ARRAY)); \
for (int x = size - 1; x >= 0; x--) \
{ \
TmpSort[x][0] = (double)ARRAY[x].FIELD; \
TmpSort[x][1] = x; \
} \
\
::ArraySort(TmpSort); \
::ArrayReindex(ARRAY, TmpSort); \
}
//+------------------------------------------------------------------+//| Test |//+------------------------------------------------------------------+voidOnStart(){
Pod arr_pod[9];
NonPod arr_nonpod[];
ArrayResize(arr_nonpod, 9);
ArrayInit(arr_pod);
ArrayInit(arr_nonpod);
PRINT(ArrayPrintValue(arr_pod)); // 9 8 7 6 5 4 3 2 1
PRINT(ArrayPrintValue(arr_nonpod)); // 9 8 7 6 5 4 3 2 1
ArraySortStruct(arr_pod, value);
ArraySortStruct(arr_nonpod, value);
PRINT(ArrayPrintValue(arr_pod)); // 1 2 3 4 5 6 7 8 9
PRINT(ArrayPrintValue(arr_nonpod)); // 1 2 3 4 5 6 7 8 9
}
//+------------------------------------------------------------------+//| Optimization Standat Array Functions |//+------------------------------------------------------------------+class ArrayFunctions{
public:
//+------------------------------------------------------------------+//| Copies an array into another one |//+------------------------------------------------------------------+template<typename T_dst, typename T_src>
staticintArrayCopy(T_dst &dst_array[], const T_src &src_array[], int dst_start = 0, int src_start = 0, int count = WHOLE_ARRAY){
CONSTRAINT(dst_array[0] = src_array[0]);
if(dst_start < 0 || src_start < 0){
return -1;
}
if(ArraySize(src_array) - src_start <= 0){
return -1;
}
int max_count = MathMin(ArraySize(dst_array) - dst_start, ArraySize(src_array) - src_start);
count = count > 0 ? count : max_count;
count = count < max_count ? count : max_count;
int result = ArrayCopy_AnyType(dst_array, src_array, dst_start, src_start, count);
return result;
}
//+------------------------------------------------------------------+private:
template<typename T_dst, typename T_src>
staticint ArrayCopy_AnyType(T_dst &dst_array[], const T_src &src_array[], int dst_start, int src_start, int count){
int dst_size = dst_start + count;
if(dst_size > ArraySize(dst_array)){
ArrayResize(dst_array, dst_size);
}
if(dst_size >= src_start && dst_start < src_start){
for(int i = 0; i < count; ++i){
dst_array[dst_start + i] = src_array[src_start + i];
}
}
else{
for(int i = count - 1; i >= 0; --i){
dst_array[dst_start + i] = src_array[src_start + i];
}
}
return count;
}
};
The answer was not for all occasions. Most are closing.
Thank youfxsaber very much for your help! Where to transfer $10
Thank youfxsaber very much for your help! Where to transfer $10
You're welcome.
You're welcome.
Your method doesn't work if there is string data in the sorted structure...
Your method doesn't work if there is string data in the sorted structure...
Use this.
directly unrealizable in mql.
But by the way, yes :-( a (pseudo)pointer to a function cannot be a wildcard
But one would think, what's the big deal...
After C/C++ such behaviour disgusts from attempts to "create a nettle" in MQL. Only specific individual solutions
Use this one.
This one doesn't work either ((((
Template declarations are not allowed in local classes
But by the way, yes :-( a (pseudo)pointer to a function cannot be a wildcard
But one would think, what's the big deal...
After C/C++ such behaviour disgusts from attempts to "create a nettle" in MQL. Only specific individual solutions
What's the problem?
You can still use the suggested code if you want to:
This one doesn't work either ((((
Template declarations are not allowed in local classes
Checked, it works.
Instead, slightly extended functionality:
- compiles for MT4 (build 1262, ME 2380) and MT5 (build 2380, ME 2380);
- Supports both Pod and NonPod structures;
- works with static and dynamic arrays of structures;