سورس کد اصلی میانگین متحرک ساده ( Moving Average ) مووینگ اوریج-جهت برنامه نویسی به زبان متاتریدر(MetaTrader 5) و متا ادیتور MQL5 برای ترید فارکس و بازارهای مالی
يكشنبه, ۷ شهریور ۱۴۰۰، ۰۸:۵۶ ق.ظ
جهت مشاهده سورس کد اصلی میانگین متحرک ساده ( Moving Average ) مووینگ اوریج-جهت برنامه نویسی به زبان متاتریدر(MetaTrader 5) و متا ادیتور MQL5 برای ترید فارکس و بازارهای مالی از سایت MQL لینک زیر را کلیک نمایید :
https://www.mql5.com/en/articles/16308#node01
هچنین اصل کد برای استفاده در زیر آمده است :
//+------------------------------------------------------------------+
//| SMAonPriceCloseRAW.mq5 |
//| Copyright 2024, MetaQuotes Ltd. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2024, MetaQuotes Ltd."
#property link "https://www.mql5.com"
#property version "1.00"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots 1
//--- plot MA
#property indicator_label1 "SMA"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrRed
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//--- input parameters
input int InpPeriod = 10; // SMA Period
//--- indicator buffers
double MABuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,MABuffer,INDICATOR_DATA);
//--- successful initialization
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[])
{
//--- in the loop from the value of InpPeriod to the current history bar
for(int i=InpPeriod; i<rates_total; i++)
{
//--- calculate average close prices for InpPeriod bars
double result=0;
for(int j=0; j<InpPeriod; j++)
result+=close[i-j];
result/=InpPeriod;
//--- Write the calculation result to the buffer
MABuffer[i]=result;
}
//--- return value of prev_calculated for the next call
return(rates_total);
}
۰۰/۰۶/۰۷