诚信为本
量力而为
当前位置:ea编程网 EA知识 正文

创建线性回归通道相关函数

线性回归通道是一个重要的技术分析工具,通过下面的函数我们可以在图表上创建一个线性回归通道。让我们详细了解这个函数及其参数:

线性回归通道

创建线性回归通道

bool RegressionCreate(const long chart_ID=0, // 图表的ID
const string name="Regression", // 通道的名称
const int sub_window=0, // 子窗口的索引
datetime time1=0, // 第一个点的时间
datetime time2=0, // 第二个点的时间
const color clr=clrRed, // 通道的颜色
const ENUM_LINE_STYLE style=STYLE_SOLID, // 通道线的样式
const int width=1, // 通道线的宽度
const bool fill=false, // 是否填充通道颜色
const bool back=false, // 是否在背景中显示
const bool selection=true, // 是否高亮以便移动
const bool ray_right=false, // 是否将通道延伸到右侧
const bool hidden=true, // 在对象列表中是否隐藏
const long z_order=0) // 鼠标点击的优先级
{
// 设置锚点坐标(如果未设置)
ChangeRegressionEmptyPoints(time1,time2);
// 重置错误值
ResetLastError();
// 根据给定的坐标创建通道
if(!ObjectCreate(chart_ID,name,OBJ_REGRESSION,sub_window,time1,0,time2,0))
{
Print(FUNCTION,
": 创建线性回归通道失败!错误代码 = ",GetLastError());
return(false);
}
// 设置通道颜色
ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
// 设置通道线的样式
ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);
// 设置通道线的宽度
ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width);
// 设置通道是否在前景或背景中显示
ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
// 设置是否可以高亮和移动通道
ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
// 设置是否延伸通道显示到右侧
ObjectSetInteger(chart_ID,name,OBJPROP_RAY_RIGHT,ray_right);
// 设置在对象列表中是否隐藏通道名
ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
// 设置鼠标点击的优先级
ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
// 函数执行成功
return(true);
}

移动通道的锚点

bool RegressionPointChange(const long chart_ID=0, // 图表的ID
const string name="Channel", // 通道的名称
const int point_index=0, // 锚点的索引
datetime time=0) // 锚点的时间坐标
{
// 如果锚点时间未设置,则将锚点移至当前条形图
if(!time)
time=TimeCurrent();
// 重置错误值
ResetLastError();
// 移动锚点
if(!ObjectMove(chart_ID,name,point_index,time,0))
{
Print(FUNCTION,
": 移动锚点失败!错误代码 = ",GetLastError());
return(false);
}
// 函数执行成功
return(true);
}

删除通道

bool RegressionDelete(const long chart_ID=0, // 图表的ID
const string name="Channel") // 通道的名称
{
// 重置错误值
ResetLastError();
// 删除通道
if(!ObjectDelete(chart_ID,name))
{
Print(FUNCTION,
": 删除通道失败!错误代码 = ",GetLastError());
return(false);
}
// 函数执行成功
return(true);
}

检查并设置通道的锚点设置默认值

void ChangeRegressionEmptyPoints(datetime &time1,datetime &time2)
{
// 如果第二个点的时间未设置,则设为当前条形图的时间
if(!time2)
time2=TimeCurrent();
// 如果第一个点的时间未设置,则位于第二个点左边的9个条形图
if(!time1)
{
// 数组,用于接收最后10个条形图的打开时间
datetime temp[10];
CopyTime(Symbol(),Period(),time2,10,temp);
// 将第一个点设为第二个点左边的9个条形图
time1=temp[0];
}
}
未经允许不得转载:ea编程网 » 创建线性回归通道相关函数