Опубликовал пост Пример математически правильной Торговой Системы Ниже математически правильная ТС с проверкой, что это так. Логика ТС следующая: переворачивается вовнутрь, когда цена с запасом пересекает EMA-шку от цены. // Пример математически правильной ТС с возможностью ее проверки в MT5-Тестере. // https://www.mql5... Добавил тему...
Non sono un grande fan del condividere il mio lavoro, quindi alcune ottimizzazioni runtime per gli array Pod sono state tagliate. Invece, una funzionalità leggermente estesa: - compila per MT4 (build 1262, ME 2380) e MT5 (build 2380, ME 2380); - Supporta entrambe le strutture Pod e NonPod; - lavora con array di strutture statiche e dinamiche;
#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;
}
};
La risposta non era per tutte le occasioni. La maggior parte sta chiudendo.
Grazie millefxsaber per il tuo aiuto! Dove trasferire 10 dollari
Grazie millefxsaber per il tuo aiuto! Dove trasferire 10 dollari
Non c'è di che.
Non c'è di che.
Il tuo metodo non funziona se ci sono dati stringa nella struttura ordinata...
Il tuo metodo non funziona se ci sono dati stringa nella struttura ordinata...
Usate questo.
Non direttamente implementabile in mql.
Ma a proposito, sì :-( uno (pseudo)puntatore a una funzione non può essere un carattere jolly
Ma si potrebbe pensare, qual è il problema...
Dopo C/C++ tale comportamento disgusta i tentativi di "creare un'ortica" in MQL. Solo soluzioni individuali specifiche
Usa questo.
Anche questo non funziona ((((
Le dichiarazioni di template non sono permesse nelle classi locali
Ma a proposito, sì :-( uno (pseudo)puntatore a una funzione non può essere un carattere jolly
Ma si potrebbe pensare, qual è il problema...
Dopo C/C++ tale comportamento disgusta i tentativi di "creare un'ortica" in MQL. Solo soluzioni individuali specifiche
Qual è il problema?
Puoi ancora usare il codice suggerito se vuoi:
Anche questo non funziona ((((
Le dichiarazioni di template non sono permesse nelle classi locali
Controllato, funziona.
Invece, una funzionalità leggermente estesa:
- compila per MT4 (build 1262, ME 2380) e MT5 (build 2380, ME 2380);
- Supporta entrambe le strutture Pod e NonPod;
- lavora con array di strutture statiche e dinamiche;