Article-16308-MQL5-Moving-A.../SMMA/SMMAonPriceCloseRAW.mq5

78 lines
5.5 KiB
MQL5
Raw Permalink Normal View History

2026-03-23 20:06:06 +07:00
<EFBFBD><EFBFBD>//+------------------------------------------------------------------+
//| SMMAonPriceCloseRAW.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 "SMMA"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrRed
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//--- input parameters
input int InpPeriod=10; // SMMA Period
//--- indicator buffers
double MABuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,MABuffer,INDICATOR_DATA);
//---
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[])
{
//--- 2 F8:;5 >B InpPeriod-1 4> B5:CI53> 10@0
double result=0.0;
for(int i=InpPeriod-1; i<rates_total; i++)
{
//--- ?5@2K9 @0AGQB
if(i==InpPeriod-1)
{
//--- @0AAG8B05< ?@>ABCN A:>;L7OICN A@54=NN 4;O InpPeriod ?5@2KE 10@>2
for(int j=0; j<InpPeriod; j++)
{
double price=close[i-j];
result+=price;
}
result/=InpPeriod;
//--- 70?8AK205< ?5@2>5 >B>1@0605<>5 7=0G5=85 SMMA, @0AAG8B0==>5 :0: SMA
MABuffer[InpPeriod-1]=result;
}
//--- 2A5 ?>A;54CNI85 @0AGQBK
else
result=(MABuffer[i-1]*(InpPeriod-1)+close[i])/InpPeriod;
//--- 0?8AK205< @57C;LB0B @0AGQB0 2 1CD5@
MABuffer[i]=result;
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+