DislikedAs previously mentioned, ..., if you are not aware of these tools. ...{image}Ignored
Tks a lot.
Sincerely.
Tomcat98
1
What is the best way to get started learning MQL4 programming language? 22 replies
Free mql4 programming 65 replies
MQL4 programming help needed - simply combining indicators 0 replies
MQL4 Language Most Recent Version is it updated beyond the tutorial on the mql4 websi 6 replies
The Guide in Post 1 has been updated to version 3.5.
DislikedI have tested all and can reaffirm that Gemini PRO 2.5 is way inteligent for coding than any other ai ,till now. Use GEMS in Gemini and give the custom command. Each new chat into the Gem will consider the master command. Also use MQL5 so u can backtest multi pair strategies. I usually create and test 2-3 strategies per day into EAs. My Approach is this : I go to Claude to create the prompt for Gemini. I copy paste it into the New Chat into Gems and debug further. I specify to log everything into the...Ignored
DislikedHi Guys, Just reading some of the posts at the weekend. Just wondered if any have tried Grok on X. - might be worth a try. PCIgnored
Recommended Models for General Tasks
2. General Task-Model Matching
The suitability of each model for general tasks depends on its strengths in reasoning, speed, and context handling.
3. MQL4/MQL5 Coding Suitability Analysis
MQL4 and MQL5 are niche programming languages used for developing trading algorithms (e.g., scripts, indicators, expert advisors) on the MetaTrader platform. Due to limited direct evidence on Gemini models’ performance with these languages, recommendations are based on their general coding capabilities and user discussions.
ModelGeneral Task SuitabilityMQL4/MQL5 Suitability
Gemini 2.5 Pro 05-06
Best for complex reasoning, advanced coding, high-accuracy tasksBest suited; superior coding and reasoning
Gemini 2.5 Flash 05-20
Fast, cost-efficient; good for simpler coding, real-time interactionsSuitable for simpler tasks; less capable than Pro
Gemini 2.5 Flash 04-17Similar to 05-20 but slightly olderSimilar to 05-20
Gemini 2.5 (general)Advanced reasoning and coding; specific versions matterLikely good; Pro is preferred
Gemini 2.0Good for multimodal tasks; less advanced than 2.5Less suitable than 2.5
Gemini 1.5Basic capabilities; older modelNot recommended for complex tasks
5. Final Recommendations
QuoteDislikedGemini 2.5 Pro Preview 05-06:
- Tasks: Ideal for creative writing (e.g., drafting nuanced marketing emails), complex problem-solving (e.g., multi-step math or research analysis), and advanced coding (e.g., building full applications).
- Rationale: Its advanced reasoning and large context window ensure high-quality, accurate outputs for tasks requiring depth and precision.
//+------------------------------------------------------------------+ // Matern Kernel Function //+------------------------------------------------------------------+ matrix CSignalGauss::Matern_Kernel(vector &Rows,vector &Cols) { matrix _matern; _matern.Init(Rows.Size(), Cols.Size()); for(int i = 0; i < int(Rows.Size()); i++) { for(int ii = 0; ii < int(Cols.Size()); ii++) { _matern[i][ii] = (1.0 + (sqrt(3.0) * fabs(Rows[i] - Cols[ii]) / m_next)) * exp(-1.0 * sqrt(3.0) * fabs(Rows[i] - Cols[ii]) / m_next); } } return(_matern); } For smoothing, x_* = x, so K(x_*, x) = K(x, x).
The formula becomes: f_smooth = K(x, x) [K(x, x) + σ_n^2 I]^-1 y
The Matérn kernel (specifically the one you hinted at, with sqrt(3.0), which is the Matérn 3/2 kernel) is:
k(x_i, x_j) = σ_f^2 * (1 + sqrt(3) * r / l) * exp(-sqrt(3) * r / l)
Where:
Let's outline the MQL5 Indicator Structure:
Here was the finalcode after correcting errors( mostly matrix conversions to vectors)
//+------------------------------------------------------------------+ //| ZeroLAG_Stochs_GP.mq5 | //| Copyright 2023, Your Name/Company | //| https://www.example.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2023, Your Name/Company" #property link "https://www.example.com" #property version "1.05" // Incremented version - Added Diagnostics #property indicator_chart_window #property indicator_buffers 3 // K_Buffer, FastK_Buffer, Smoothed_FastK_Buffer #property indicator_plots 1 //--- Plot K #property indicator_label1 "ZeroLAG Stoch %K (GP)" #property indicator_type1 DRAW_LINE #property indicator_color1 clrDodgerBlue #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- Input parameters input int N_Period = 14; // Stochastic Period & GP Smoothing Window input double GP_LengthScale = 2.0; // Matérn Kernel Length Scale input double GP_NoiseVariance = 0.1; // Noise Variance for GP Smoothing (sigma_n^2) input double GP_SignalVariance = 1.0; // Signal Variance for Matérn Kernel (sigma_f^2) input bool EnableDebugPrint = false; // Enable detailed OnCalculate prints //--- Indicator buffers double K_Buffer[]; double FastK_Buffer[]; // Stores raw Fast%K double Smoothed_FastK_Buffer[];// Stores GP_Smooth(Fast%K) //--- Global vector for x_indices (time points 0, 1, ..., N_Period-1) vector x_indices_global; //+------------------------------------------------------------------+ //| Manual Matrix-Vector Multiplication | //+------------------------------------------------------------------+ vector ManualMatVecMul(const matrix& M, const vector& V) { vector result_vec; ulong M_rows = M.Rows(); ulong M_cols = M.Cols(); ulong V_size = V.Size(); if (M_cols != V_size || M_rows == 0 || M_cols == 0) { // PrintFormat("ManualMatVecMul: Dimension mismatch or zero size. M_rows=%lu, M_cols=%lu, V_size=%lu", M_rows, M_cols, V_size); if (M_rows > 0) { if (result_vec.Resize(M_rows)) { result_vec.Fill(EMPTY_VALUE); } } return result_vec; } if (!result_vec.Resize(M_rows)) { // PrintFormat("ManualMatVecMul: Failed to resize result_vec to %lu rows.", M_rows); return result_vec; } for (ulong i = 0; i < M_rows; i++) { double sum = 0.0; for (ulong j = 0; j < M_cols; j++) { sum += M[i][j] * V[j]; } result_vec[i] = sum; } return result_vec; } //+------------------------------------------------------------------+ //| Matérn 3/2 Kernel Function | //+------------------------------------------------------------------+ matrix MaternKernel(const vector &X1, const vector &X2, double length_scale, double signal_variance) { matrix K; int n1 = (int)X1.Size(); int n2 = (int)X2.Size(); if(n1 == 0 || n2 == 0) { // Print("MaternKernel: Input vector size is zero."); return K; } if(!K.Resize(n1, n2)) { PrintFormat("MaternKernel: Failed to resize matrix to %d x %d", n1, n2); return K; } if(length_scale <= 1e-9) length_scale = 1e-9; for(int i = 0; i < n1; i++) { for(int j = 0; j < n2; j++) { double r = MathAbs(X1[i] - X2[j]); double term_val = MathSqrt(3.0) * r / length_scale; K[i][j] = signal_variance * (1.0 + term_val) * MathExp(-term_val); } } return K; } //+------------------------------------------------------------------+ //| Gaussian Process Smoothing Function | //+------------------------------------------------------------------+ vector GPSmooth(const vector &observed_x, const vector &observed_y, double length_scale, double noise_variance, double signal_variance, int bar_index_debug, string smooth_step_name_debug) // Added for debug { vector smoothed_values_out; int n = (int)observed_x.Size(); if(n == 0) { // if(EnableDebugPrint) PrintFormat("Bar %d, GPSmooth (%s): n=0, returning empty.", bar_index_debug, smooth_step_name_debug); return smoothed_values_out; } if (n != (int)observed_y.Size()) { if(EnableDebugPrint) PrintFormat("Bar %d, GPSmooth (%s): Input size mismatch. X_size=%d, Y_size=%d", bar_index_debug, smooth_step_name_debug, n, observed_y.Size()); if (!smoothed_values_out.Resize(n)) { /* Resize failed, returns empty */ } else { for(ulong i=0; i<smoothed_values_out.Size(); ++i) smoothed_values_out[i] = EMPTY_VALUE; } return smoothed_values_out; } if(!smoothed_values_out.Resize(n)) { if(EnableDebugPrint) PrintFormat("Bar %d, GPSmooth (%s): Failed to resize smoothed_values_out vector to %d.", bar_index_debug, smooth_step_name_debug, n); return smoothed_values_out; } matrix K_xx = MaternKernel(observed_x, observed_x, length_scale, signal_variance); if(K_xx.Rows() != (ulong)n || K_xx.Cols() != (ulong)n) { if(EnableDebugPrint) PrintFormat("Bar %d, GPSmooth (%s): MaternKernel for K_xx invalid. Expected %dx%d, got %lux%lu.", bar_index_debug, smooth_step_name_debug, n, n, K_xx.Rows(), K_xx.Cols()); for(ulong i=0; i<smoothed_values_out.Size(); ++i) smoothed_values_out[i] = EMPTY_VALUE; return smoothed_values_out; } matrix K_noisy = K_xx; for(int i = 0; i < n; i++) { K_noisy[i][i] += noise_variance; } matrix K_noisy_inv = K_noisy; if(!K_noisy_inv.Inv()) { if(EnableDebugPrint) PrintFormat("Bar %d, GPSmooth (%s): K_noisy.Inv() failed. Fallback to observed_y.", bar_index_debug, smooth_step_name_debug); for(ulong i=0; i<smoothed_values_out.Size(); ++i) smoothed_values_out[i] = observed_y[i]; // Fallback return smoothed_values_out; } if(K_noisy_inv.Rows() != (ulong)n || K_noisy_inv.Cols() != (ulong)n) { if(EnableDebugPrint) PrintFormat("Bar %d, GPSmooth (%s): K_noisy_inv dimensions incorrect. Expected %dx%d, got %lux%lu.", bar_index_debug, smooth_step_name_debug, n, n, K_noisy_inv.Rows(), K_noisy_inv.Cols()); for(ulong i=0; i<smoothed_values_out.Size(); ++i) smoothed_values_out[i] = EMPTY_VALUE; return smoothed_values_out; } vector alpha_intermediate = ManualMatVecMul(K_noisy_inv, observed_y); if(alpha_intermediate.Size() != (ulong)n) { if(EnableDebugPrint) PrintFormat("Bar %d, GPSmooth (%s): ManualMatVecMul for alpha result size mismatch. Expected %d, got %lu.", bar_index_debug, smooth_step_name_debug, n, alpha_intermediate.Size()); for(ulong k=0; k<smoothed_values_out.Size(); ++k) smoothed_values_out[k] = EMPTY_VALUE; return smoothed_values_out; } smoothed_values_out = ManualMatVecMul(K_xx, alpha_intermediate); if(smoothed_values_out.Size() != (ulong)n) { if(EnableDebugPrint) PrintFormat("Bar %d, GPSmooth (%s): ManualMatVecMul for final result size mismatch. Expected %d, got %lu.", bar_index_debug, smooth_step_name_debug, n, smoothed_values_out.Size()); if(!smoothed_values_out.Resize(n)) { /* This should ideally not fail */ } for(ulong k=0; k<n; ++k) smoothed_values_out[k] = EMPTY_VALUE; return smoothed_values_out; } // if(EnableDebugPrint) PrintFormat("Bar %d, GPSmooth (%s): Success. Last smoothed value: %.2f", bar_index_debug, smooth_step_name_debug, smoothed_values_out[n-1]); return smoothed_values_out; } //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { Print("ZeroLAG_Stochs_GP: OnInit started."); SetIndexBuffer(0, K_Buffer, INDICATOR_DATA); SetIndexBuffer(1, FastK_Buffer, INDICATOR_CALCULATIONS); SetIndexBuffer(2, Smoothed_FastK_Buffer,INDICATOR_CALCULATIONS); PlotIndexSetString(0, PLOT_LABEL, "ZeroLAG Stoch %K (GP " + IntegerToString(N_Period) + ")"); IndicatorSetString(INDICATOR_SHORTNAME, "ZLS_GP(" + IntegerToString(N_Period) + ")"); PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, EMPTY_VALUE); IndicatorSetInteger(INDICATOR_DIGITS, 2); if(N_Period <= 0) { Print("ZeroLAG_Stochs_GP: OnInit Error - N_Period must be positive."); return INIT_FAILED; } if(!x_indices_global.Resize(N_Period)) { Print("ZeroLAG_Stochs_GP: OnInit Error - Failed to resize x_indices_global."); return INIT_FAILED; } for(int i = 0; i < N_Period; i++) { x_indices_global[i] = (double)i; } if(GP_LengthScale <= 0) { Print("ZeroLAG_Stochs_GP: OnInit Error - GP_LengthScale must be positive."); return INIT_FAILED; } if(GP_NoiseVariance < 0) { Print("ZeroLAG_Stochs_GP: OnInit Error - GP_NoiseVariance should be non-negative."); return INIT_FAILED; } Print("ZeroLAG_Stochs_GP: OnInit SUCCEEDED."); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { if (EnableDebugPrint && prev_calculated == 0) PrintFormat("ZeroLAG_Stochs_GP: OnCalculate - Full calculation. Rates total: %d", rates_total); int min_bars_needed = 0; if (N_Period > 0) min_bars_needed = 3 * N_Period - 2; else min_bars_needed = 1; // Prevent issues if N_Period somehow 0 if(rates_total < min_bars_needed ) { if(prev_calculated == 0 && EnableDebugPrint) PrintFormat("ZeroLAG_Stochs_GP: OnCalculate - Not enough bars. Need %d, have %d. N_Period=%d", min_bars_needed, rates_total, N_Period); return(0); // Not enough data to calculate even one value } if(N_Period <=0) return 0; // Should be caught by OnInit int start_bar; if(prev_calculated == 0) { start_bar = 0; ArrayInitialize(K_Buffer, EMPTY_VALUE); ArrayInitialize(FastK_Buffer, EMPTY_VALUE); ArrayInitialize(Smoothed_FastK_Buffer, EMPTY_VALUE); if(EnableDebugPrint) Print("ZeroLAG_Stochs_GP: OnCalculate - Buffers initialized for full calc."); } else { start_bar = prev_calculated - 1; } vector y_values; if(!y_values.Resize(N_Period)) { Print("ZeroLAG_Stochs_GP: OnCalculate Error - Failed to resize y_values"); return 0; } for(int i = start_bar; i < rates_total; i++) { if(prev_calculated > 0 && i >= prev_calculated -1 ) { K_Buffer[i] = EMPTY_VALUE; FastK_Buffer[i] = EMPTY_VALUE; Smoothed_FastK_Buffer[i] = EMPTY_VALUE; } // 1. Calculate Fast%K if(i < N_Period - 1) { FastK_Buffer[i] = EMPTY_VALUE; if (EnableDebugPrint && i == rates_total -1) PrintFormat("Bar %d: FastK set to EMPTY (i < N_Period-1)", i); continue; } double min_low_N = low[i]; double max_high_N = high[i]; for(int k = 1; k < N_Period; k++) { if(i - k < 0) break; if(low[i - k] < min_low_N) min_low_N = low[i - k]; if(high[i - k] > max_high_N) max_high_N = high[i - k]; } if(MathAbs(max_high_N - min_low_N) < 1e-9) { FastK_Buffer[i] = (i > 0 && FastK_Buffer[i-1] != EMPTY_VALUE && FastK_Buffer[i-1] >=0 && FastK_Buffer[i-1] <=100 ) ? FastK_Buffer[i-1] : 50.0; } else { FastK_Buffer[i] = 100.0 * (close[i] - min_low_N) / (max_high_N - min_low_N); } FastK_Buffer[i] = MathMax(0.0, MathMin(100.0, FastK_Buffer[i])); if (EnableDebugPrint && i == rates_total -1) PrintFormat("Bar %d: FastK=%.2f", i, FastK_Buffer[i]); // 2. Calculate Smoothed_FastK_Buffer[i] = GP_Smooth(FastK_Buffer over N_Period) if(i < (N_Period - 1) + (N_Period - 1)) { Smoothed_FastK_Buffer[i] = EMPTY_VALUE; if (EnableDebugPrint && i == rates_total -1) PrintFormat("Bar %d: SmoothedFastK set to EMPTY (i < 2*N_Period-2)", i); continue; } bool data_ok_fk = true; for(int k = 0; k < N_Period; k++) { int source_idx = i - (N_Period - 1) + k; if(source_idx < 0 || FastK_Buffer[source_idx] == EMPTY_VALUE){ data_ok_fk = false; if (EnableDebugPrint && i == rates_total -1) PrintFormat("Bar %d: Data not OK for SmoothedFastK at y_values[%d] (source_idx %d, FastK=%.2f)", i, k, source_idx, (source_idx>=0 ? FastK_Buffer[source_idx] : -999.0) ); break; } y_values[k] = FastK_Buffer[source_idx]; } if(!data_ok_fk){ Smoothed_FastK_Buffer[i] = EMPTY_VALUE; if (EnableDebugPrint && i == rates_total -1) PrintFormat("Bar %d: SmoothedFastK set to EMPTY (data_ok_fk=false)", i); continue; } vector smoothed_fk_series = GPSmooth(x_indices_global, y_values, GP_LengthScale, GP_NoiseVariance, GP_SignalVariance, i, "SmoothFastK"); if(smoothed_fk_series.Size() == (ulong)N_Period && smoothed_fk_series[N_Period - 1] != EMPTY_VALUE) { Smoothed_FastK_Buffer[i] = smoothed_fk_series[N_Period - 1]; } else { Smoothed_FastK_Buffer[i] = EMPTY_VALUE; if (EnableDebugPrint && i == rates_total -1) PrintFormat("Bar %d: SmoothedFastK set to EMPTY (GPSmooth failed or returned empty)", i); continue; } if (EnableDebugPrint && i == rates_total -1) PrintFormat("Bar %d: SmoothedFastK=%.2f", i, Smoothed_FastK_Buffer[i]); // 3. Calculate GP_Smooth(Smoothed_FastK_Buffer over N_Period) for K_Buffer if(i < (N_Period - 1) * 2 + (N_Period - 1)) { K_Buffer[i] = EMPTY_VALUE; // Ensure K_Buffer is also empty here if (EnableDebugPrint && i == rates_total -1) PrintFormat("Bar %d: K_Buffer set to EMPTY (i < 3*N_Period-3)", i); continue; } bool data_ok_sfk = true; for(int k = 0; k < N_Period; k++) { int source_idx = i - (N_Period - 1) + k; if(source_idx < 0 || Smoothed_FastK_Buffer[source_idx] == EMPTY_VALUE){ data_ok_sfk = false; if (EnableDebugPrint && i == rates_total -1) PrintFormat("Bar %d: Data not OK for FinalK at y_values[%d] (source_idx %d, SmoothedFastK=%.2f)", i, k, source_idx, (source_idx>=0 ? Smoothed_FastK_Buffer[source_idx] : -999.0)); break; } y_values[k] = Smoothed_FastK_Buffer[source_idx]; } if(!data_ok_sfk){ K_Buffer[i] = EMPTY_VALUE; if (EnableDebugPrint && i == rates_total -1) PrintFormat("Bar %d: K_Buffer set to EMPTY (data_ok_sfk=false)", i); continue; } vector smoothed_sfk_series = GPSmooth(x_indices_global, y_values, GP_LengthScale, GP_NoiseVariance, GP_SignalVariance, i, "SmoothSmoothedFastK"); double current_smoothed_smoothed_fk; if(smoothed_sfk_series.Size() == (ulong)N_Period && smoothed_sfk_series[N_Period - 1] != EMPTY_VALUE) { current_smoothed_smoothed_fk = smoothed_sfk_series[N_Period - 1]; } else { K_Buffer[i] = EMPTY_VALUE; if (EnableDebugPrint && i == rates_total -1) PrintFormat("Bar %d: K_Buffer set to EMPTY (GPSmooth for current_smoothed_smoothed_fk failed)", i); continue; } if (EnableDebugPrint && i == rates_total -1) PrintFormat("Bar %d: current_smoothed_smoothed_fk=%.2f", i, current_smoothed_smoothed_fk); // 4. Calculate K_Buffer[i] K_Buffer[i] = 2.0 * Smoothed_FastK_Buffer[i] - current_smoothed_smoothed_fk; if (EnableDebugPrint && i == rates_total -1) PrintFormat("Bar %d: FINAL K_Buffer=%.2f", i, K_Buffer[i]); } return(rates_total); } //+------------------------------------------------------------------+ DislikedHere is the article where I obtained the mattern kernel GP smoothing:https://www.mql5.com/en/articles/15767Ignored
Disliked...I want to go beyond the moving average smoothing.In my opinion except the symbolic regression smoothing ,GP smoothing is better than the convolutional neural network smoothing and generalized additive models (GAM) .Ignored
DislikedOff Topic Here is a link to guide for using VS Code for MQL4 Code Development in my GitHub MQL4 repository. I got a little tired of Gemini truncating code, so I am switching over to Visual Studio Code for editing code, and using Copilot Ai. I am new to using VS Code for MQL4 development, so personally I am still trying it out. https://github.com/EgoNoBueno/MQL4-C...evelopment.pdfIgnored