按价格标记位置脚本

转载原文:http://www.popoding.club/post/33/

价格是行情分析的重要参照因素,尤其是以支撑阻力位为核心的交易系统中,寻找合适的进场和出场价格位置是首要任务。那么按价格标记出这些参照位置就对分析、统计有实际意义。

画线对象

这里用画横线的方式来进行标记,需要用到画对象函数ObjectCreate(),指定对象类型为OBJ_HLINE,创建画线对象便可以设置颜色、宽度、风格等相关属性。

//画横线对象
string line_name = DoubleToString(1.20330);
if(!ObjectCreate(0,line_name,OBJ_HLINE,0,0,1.20330))
{
printf(": failed to create a line! Error code = ",GetLastError());
}
ObjectSetInteger(0,line_name,OBJPROP_COLOR,clrRed);  //设置颜色
ObjectSetInteger(0,line_name,OBJPROP_STYLE,STYLE_SOLID); //设置风格
ObjectSetInteger(0,line_name,OBJPROP_WIDTH,1);   //设置宽度

价格位置

在这个例子中,拟定一个应用场景,需要实现找出所有以00、50价格结尾的整点价位,并进行画线标记出来。在历史报价数据中,价位是有波动范围的,给定一个最大值2.00000和最小值1.00000,在这个价格区间找出需要的价位。

//整点价格位置
double price_max = 2.00000;
double price_min = 1.00000;
double price_integer[];
ArrayResize(price_integer,300);
double price_tmp = price_min;
int m = 0;
for(m = 0; price_tmp <= price_max; m++)
{
   price_integer[m] = price_tmp;
   price_tmp = price_tmp + 0.00500;
}
ArrayRemove(price_integer,m);
for(int i = 0; i < ArraySize(price_integer); i++)
{
//画横线对象
}

需要注意的是,用到了ArrayResize()函数分配一个动态数组空间,这里直接定义一个静态数组,是因为动态数组可以灵活进行插入、删除操作,在无法准确得到数组元素个数时,先动态分配,再用ArrayRemove()函数清理多余的数据,将空间利用到最优。

同样可以将线的颜色、样式、宽度等作为输入参数,实现更加灵活的控制。

input color line_color = clrRed;
input ENUM_LINE_STYLE line_style = STYLE_SOLID;
input int line_width = 2;

实现源码

#property copyright "公众号 Luyuanmw 微信 wentxiong"
#property link      "http://www.popoding.club/"
#property version   "1.00"
#property script_show_inputs
input color line_color = clrRed;
input ENUM_LINE_STYLE line_style = STYLE_SOLID;
input int line_width = 2;
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
{
//---
//整点价格位置
double price_max = 2.00000;
double price_min = 1.00000;
double price_integer[];
ArrayResize(price_integer,300);
double price_tmp = price_min;
int m = 0;
for(m = 0; price_tmp <= price_max; m++)
{
price_integer[m] = price_tmp;
price_tmp = price_tmp + 0.00500;
}
ArrayRemove(price_integer,m);
for(int i = 0; i < ArraySize(price_integer); i++)
{
//画横线对象
string line_name = DoubleToString(price_integer[i]);
if(!ObjectCreate(0,line_name,OBJ_HLINE,0,0,price_integer[i]))
{
printf(": failed to create a line! Error code = ",GetLastError());
}
ObjectSetInteger(0,line_name,OBJPROP_COLOR,line_color); //设置颜色
ObjectSetInteger(0,line_name,OBJPROP_STYLE,line_style);  //设置风格
ObjectSetInteger(0,line_name,OBJPROP_WIDTH,line_width); //设置宽度
}
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值