Miscellaneous
0
Views
0
Downloads
0
Favorites
SMA
//+------------------------------------------------------------------+
//| SMA.mq4 |
//| |
//| |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 DodgerBlue
//---- input parameters
extern int period = 14;
//---- buffer
double Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- 1 additional buffer used for counting.
IndicatorBuffers( 1 );
IndicatorDigits( Digits );
//---- indicator line
SetIndexStyle( 0, DRAW_LINE );
SetIndexBuffer( 0, Buffer );
//---- name for DataWindow and indicator subwindow label
string short_name = "SMA("+period+")";
IndicatorShortName( short_name );
SetIndexLabel( 0, short_name );
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
//----
double sum;
int counted_bars = IndicatorCounted( );
//---- ïîñëåäíèé ïîñ÷èòàííûé áàð áóäåò ïåðåñ÷èòàí
if ( counted_bars > 0 ) counted_bars--;
int limit = Bars-counted_bars-1;
//---- îñíîâíîé öèêë
for ( int i = 0; i <= limit; i++ )
{
if ( i >= period )
{
Buffer[i - period] = sum / period;
sum = sum + Close[i] - Close[i - period];
}
else
{
if ( i < period )
{
sum = sum + Close[i];
}
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---