价格常数
价格常数
技术指标的计算要求价格价值和成交量价值,该计算将执行,有7个预先的标识符在ENUM_APPLIED_PRICE 项目中,以指定计算的期望价值基础。
ENUM_APPLIED_PRICE
| ID | 描述 |
|---|---|
| PRICE_CLOSE | 收盘价格 |
| PRICE_OPEN | 开盘价格 |
| PRICE_HIGH | 一个时期的最高价格 |
| PRICE_LOW | 一个时期的最低价格 |
| PRICE_MEDIAN | 中间值(高+低)/2 |
| PRICE_TYPICAL | 典型价格(高+低+收盘价)/3 |
| PRICE_WEIGHTED | 平均价格(高+低+收盘价格+开盘价格)/4 |
如果成交量用于计算,必要在 ENUM_APPLIED_VOLUME 中列举出一两个值
ENUM_APPLIED_VOLUME
| ID | 描述 |
|---|---|
| VOLUME_TICK | 赊欠成交量 |
| VOLUME_REAL | 交易成交量 |
iStochastic() 技术指标以两种方式计算使用:
- 或者只以收盘价;
- 或者以最高或最低价;
- 为计算选择必须变量,指定ENUM_STO_PRICE 计算中的一种值 ENUM_STO_PRICE
| ID | 描述 |
|---|---|
| STO_LOWHIGH | 基于最低价/最高价的计算 |
| STO_CLOSECLOSE | 基于开盘价/收盘价的计算 |
如果技术指标使用价格数据的计算,建立ENUM_APPLIED_PRICE类型,然后任何指标处理(内置在终端里或者使用者输入)都能用来输入价格序列。在此情况下,指标中零缓冲器的值会用来计算,这样就很容易使用另一指标建造该指标的值,自定义指标的处理需要调用 iCustom() 函数处理。
示例:
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots 2
//--- 输入函数
input int RSIperiod=14; // 计算RSI的周期
input int Smooth=8; // 平滑RSI周期
input ENUM_MA_METHOD meth=MODE_SMMA; // 修匀法
//---- 图 RSI
#property indicator_label1 "RSI"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrRed
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//---- 图 RSI_Smoothed
#property indicator_label2 "RSI_Smoothed"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrNavy
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
//--- 指标缓冲区
double RSIBuffer[]; // 这里存储 RSI值
double RSI_SmoothedBuffer[]; // RSI平滑值
int RSIhandle; // 处理 RSI 指标
//+------------------------------------------------------------------+
//| 自定义指标初始化函数 |
//+------------------------------------------------------------------+
void OnInit()
{
//--- 指标缓冲区绘图indicator buffers mapping
SetIndexBuffer(0,RSIBuffer,INDICATOR_DATA);
SetIndexBuffer(1,RSI_SmoothedBuffer,INDICATOR_DATA);
IndicatorSetString(INDICATOR_SHORTNAME,"iRSI");
IndicatorSetInteger(INDICATOR_DIGITS,2);
//---
RSIhandle=iRSI(NULL,0,RSIperiod,PRICE_CLOSE);
//---
}
//+------------------------------------------------------------------+
//| 自定义指标重复函数 |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const int begin,
const double &price[]
)
{
//--- 重置上一个错误值
ResetLastError();
//--- 数组RSIBuffer []中获得 RSI 指标数据
int copied=CopyBuffer(RSIhandle,0,0,rates_total,RSIBuffer);
if(copied<=0)
{
Print("Unable to copy the values of the indicator RSI. Error = ",
GetLastError(),", copied =",copied);
return(0);
}
//--- 创建使用RSI值的平均值的指标
int RSI_MA_handle=iMA(NULL,0,Smooth,0,meth,RSIhandle);
copied=CopyBuffer(RSI_MA_handle,0,0,rates_total,RSI_SmoothedBuffer);
if(copied<=0)
{
Print("Unable to copy the smoothed indicator of RSI. Error = ",
GetLastError(),", copied =",copied);
return(0);
}
//--- 为下次调用返回prev_calculated值
return(rates_total);
}