OBJ_ELLIOTWAVE5

艾略特波浪动力

ObjElliotWave5

注意

对于"艾略特波浪动力",可以启用/禁用通过线连接点的模式 (OBJPROP_DRAWLINES 属性),以及设置波浪定位的水平 (从 ENUM_ELLIOT_WAVE_DEGREE 枚举)。

示例

下面的脚本创建和移动图表上的艾略特波浪动力。已开发的特别函数用于创建和改变图形对象的属性。您可以在您的个人应用中使用这些函数"as is" 。

 

//--- 描述
#property description "Script draws \"Elliott Motive Wave\"."
#property description "Anchor point coordinates are set in percentage of the size of"
#property description "the chart window."
//--- 启动脚本期间显示输入参数的窗口
#property script_show_inputs
//--- 脚本的输入参数
input string                  InpName="ElliotWave5";   // 对象名称
input int                     InpDate1=10;             // 第1个点的日期, %
input int                     InpPrice1=90;            // 第1个点的价格,%
input int                     InpDate2=20;             // 第2个点的日期,%
input int                     InpPrice2=40;            // 第2个点的价格,%
input int                     InpDate3=30;             // 第3个点的日期,%
input int                     InpPrice3=60;            // 第3个点的价格,%
input int                     InpDate4=40;             // 第4个点的日期,%
input int                     InpPrice4=10;            // 第4个点的价格,%
input int                     InpDate5=60;             // 第5个点的日期,%
input int                     InpPrice5=40;            // 第5个点的价格,%
input ENUM_ELLIOT_WAVE_DEGREE InpDegree=ELLIOTT_MINOR// 水平
input bool                    InpDrawLines=true;       // 显示线
input color                   InpColor=clrRed;         // 线的颜色
input ENUM_LINE_STYLE         InpStyle=STYLE_DASH;     // 线的风格
input int                     InpWidth=2;              // 线的宽度
input bool                    InpBack=false;           // 背景对象
input bool                    InpSelection=true;       // 突出移动
input bool                    InpHidden=true;          // 隐藏在对象列表
input long                    InpZOrder=0;             // 鼠标单击优先
//+------------------------------------------------------------------+
//| 通过已给的坐标创建“艾略特波浪动力”                                    |
//+------------------------------------------------------------------+
bool ElliotWave5Create(const long                    chart_ID=0,              // 图表 ID
                       const string                  name="ElliotWave5",      // 波浪名称
                       const int                     sub_window=0,            // 子窗口指数 
                       datetime                      time1=0,                 // 第一个点的时间
                       double                        price1=0,                // 第一个点的价格
                       datetime                      time2=0,                 // 第二个点的时间
                       double                        price2=0,                // 第二个点的价格
                       datetime                      time3=0,                 // 第三个点的时间
                       double                        price3=0,                // 第三个点的价格
                       datetime                      time4=0,                 // 第四个点的时间
                       double                        price4=0,                // 第四个点的价格
                       datetime                      time5=0,                 // 第五个点的时间
                       double                        price5=0,                // 第五个点的价格
                       const ENUM_ELLIOT_WAVE_DEGREE degree=ELLIOTT_MINUETTE// 度数
                       const bool                    draw_lines=true,         // 显示线
                       const color                   clr=clrRed,              // 对象颜色
                       const ENUM_LINE_STYLE         style=STYLE_SOLID,       // 线的风格
                       const int                     width=1,                 // 线的宽度
                       const bool                    back=false,              // 在背景中
                       const bool                    selection=true,          // 突出移动
                       const bool                    hidden=true,             // 隐藏在对象列表
                       const long                    z_order=0)               // 鼠标单击优先
  {
//--- 若未设置则设置定位点的坐标
   ChangeElliotWave5EmptyPoints(time1,price1,time2,price2,time3,price3,time4,price4,time5,price5);
//--- 重置错误的值
   ResetLastError();
//--- 通过已给的坐标创建“艾略特波浪动力”
   if(!ObjectCreate(chart_ID,name,OBJ_ELLIOTWAVE5,sub_window,time1,price1,time2,price2,time3,
      price3,time4,price4,time5,price5))
     {
      Print(__FUNCTION__,
            ": failed to create \"Elliott Motive Wave\"! Error code = ",GetLastError());
      return(false);
     }
//--- 设置程度(波动大小)
   ObjectSetInteger(chart_ID,name,OBJPROP_DEGREE,degree);
//--- 启用 (true) 或禁用 (false) 展示线型的模式
   ObjectSetInteger(chart_ID,name,OBJPROP_DRAWLINES,draw_lines);
//--- 设置对象的颜色
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
//---设置线的风格
   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);
//--- 设置线的宽度
   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width);
//--- 显示前景 (false) 或背景 (true)
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
//--- 启用 (true) 或禁用 (false) 突出通道移动的模式
//--- 当使用ObjectCreate函数创建图形对象时,对象不能
//--- 默认下突出并移动。在这个方法中,默认选择参数
//--- true 可以突出移动对象
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
//--- 在对象列表隐藏(true) 或显示 (false) 图形对象名称
   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
//--- 设置在图表中优先接收鼠标点击事件
   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
//--- 成功执行
   return(true);
  }
//+------------------------------------------------------------------+
//| 移动艾略特波浪动力定位点                                            |
//+------------------------------------------------------------------+
bool ElliotWave5PointChange(const long   chart_ID=0,         // 图表 ID
                            const string name="ElliotWave5"// 对象名称
                            const int    point_index=0,      // 定位点指数
                            datetime     time=0,             // 定位点时间坐标
                            double       price=0)            // 定位点价格坐标
  {
//--- 如果没有设置点的位置,则将其移动到当前的卖价柱
   if(!time)
      time=TimeCurrent();
   if(!price)
      price=SymbolInfoDouble(Symbol(),SYMBOL_BID);
//--- 重置错误的值
   ResetLastError();
//--- 移动定位点
   if(!ObjectMove(chart_ID,name,point_index,time,price))
     {
      Print(__FUNCTION__,
            ": failed to move the anchor point! Error code = ",GetLastError());
      return(false);
     }
//--- 成功执行
   return(true);
  }
//+------------------------------------------------------------------+
//| 删除艾略特波浪动力                                                 |
//+------------------------------------------------------------------+
bool ElliotWave5Delete(const long   chart_ID=0,         // 图表 ID
                       const string name="ElliotWave5"// 对象名称
  {
//--- 重置错误的值
   ResetLastError();
//--- 删除对象
   if(!ObjectDelete(chart_ID,name))
     {
      Print(__FUNCTION__,
            ": failed to delete \"Elliott Motive Wave\"! Error code = ",GetLastError());
      return(false);
     }
//--- 成功执行
   return(true);
  }
//+------------------------------------------------------------------+
//| 检查艾略特波浪动力定位点的值和                                       |
//| 为空点设置默认的值                                                 |
//+------------------------------------------------------------------+
void ChangeElliotWave5EmptyPoints(datetime &time1,double &price1,
                                  datetime &time2,double &price2,
                                  datetime &time3,double &price3,
                                  datetime &time4,double &price4,
                                  datetime &time5,double &price5)
  {
//--- 接收最近10柱开盘时间的数组
   datetime temp[];
   ArrayResize(temp,10);
//--- 接收数据
   CopyTime(Symbol(),Period(),TimeCurrent(),10,temp);
//--- 接收当前图表一点的值
   double point=SymbolInfoDouble(Symbol(),SYMBOL_POINT);
//--- 如果第一点的时间没有设置,它则位于最后柱左侧的9个柱
   if(!time1)
      time1=temp[0];
//--- 如果第一点的价格没有设置,则它将用卖价值
   if(!price1)
      price1=SymbolInfoDouble(Symbol(),SYMBOL_BID);
//--- 如果第二点的时间没有设置,它则位于最后柱左侧的7个柱
   if(!time2)
      time2=temp[2];
//--- 如果第二个点的价格没有设置,则低于第一个点移动300点
   if(!price2)
      price2=price1-300*point;
//--- 如果第三点的时间没有设置,它则位于最后柱左侧的5个柱
   if(!time3)
      time3=temp[4];
//--- 如果第三个点的价格没有设置,则低于第一个点移动250点
   if(!price3)
      price3=price1-250*point;
//--- 如果第四点的时间没有设置,它则位于最后柱左侧的3个柱
   if(!time4)
      time4=temp[6];
//--- 如果第四个点的价格没有设置,则低于第一个点移动550点
   if(!price4)
      price4=price1-550*point;
//--- 如果第四点的时间没有设置,它将位于最后的柱
   if(!time5)
      time5=temp[9];
//--- 如果第五个点的价格没有设置,则低于第一个点移动450点
   if(!price5)
      price5=price1-450*point;
  }
//+------------------------------------------------------------------+
//| 脚本程序起始函数                                                   |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- 检查输入参数的正确性
   if(InpDate1<0 || InpDate1>100 || InpPrice1<0 || InpPrice1>100 || 
      InpDate2<0 || InpDate2>100 || InpPrice2<0 || InpPrice2>100 || 
      InpDate3<0 || InpDate3>100 || InpPrice3<0 || InpPrice3>100 || 
      InpDate4<0 || InpDate4>100 || InpPrice4<0 || InpPrice4>100 || 
      InpDate5<0 || InpDate5>100 || InpPrice5<0 || InpPrice5>100)
     {
      Print("Error! Incorrect values of input parameters!");
      return;
     }
//--- 图表窗口的可见柱的数量
   int bars=(int)ChartGetInteger(0,CHART_VISIBLE_BARS);
//--- 价格数组大小
   int accuracy=1000;
//--- 存储要使用的日期和价格值的数组
//--- 设置和改变对象定位点的坐标
   datetime date[];
   double   price[];
//--- 内存分配
   ArrayResize(date,bars);
   ArrayResize(price,accuracy);
//--- 填写日期数组
   ResetLastError();
   if(CopyTime(Symbol(),Period(),0,bars,date)==-1)
     {
      Print("Failed to copy time values! Error code = ",GetLastError());
      return;
     }
//--- 填写价格数组
//--- 找出图表的最高值和最低值
   double max_price=ChartGetDouble(0,CHART_PRICE_MAX);
   double min_price=ChartGetDouble(0,CHART_PRICE_MIN);
//--- 定义变化的价格并填写该数组
   double step=(max_price-min_price)/accuracy;
   for(int i=0;i<accuracy;i++)
      price[i]=min_price+i*step;
//--- 定义绘制艾略特波浪动力的点
   int d1=InpDate1*(bars-1)/100;
   int d2=InpDate2*(bars-1)/100;
   int d3=InpDate3*(bars-1)/100;
   int d4=InpDate4*(bars-1)/100;
   int d5=InpDate5*(bars-1)/100;
   int p1=InpPrice1*(accuracy-1)/100;
   int p2=InpPrice2*(accuracy-1)/100;
   int p3=InpPrice3*(accuracy-1)/100;
   int p4=InpPrice4*(accuracy-1)/100;
   int p5=InpPrice5*(accuracy-1)/100;
//--- 创建艾略特波浪动力
   if(!ElliotWave5Create(0,InpName,0,date[d1],price[p1],date[d2],price[p2],date[d3],price[p3],
      date[d4],price[p4],date[d5],price[p5],InpDegree,InpDrawLines,InpColor,InpStyle,InpWidth,
      InpBack,InpSelection,InpHidden,InpZOrder))
     {
      return;
     }
//--- 重画图表并等待1秒
   ChartRedraw();
   Sleep(1000);
//--- 现在,移动定位点
//--- 循环计数器
   int v_steps=accuracy/5;
//--- 移动第五个定位点
   for(int i=0;i<v_steps;i++)
     {
      //--- 使用下面的值
      if(p5<accuracy-1)
         p5+=1;
      //--- 移动点
      if(!ElliotWave5PointChange(0,InpName,4,date[d5],price[p5]))
         return;
      //--- 检查脚本操作是否已经强制禁用
      if(IsStopped())
         return;
      //--- 重画图表
      ChartRedraw();
     }
//--- 1 秒延迟
   Sleep(1000);
//--- 循环计数器
   v_steps=accuracy/5;
//--- 移动第二个和第三个定位点
   for(int i=0;i<v_steps;i++)
     {
      //--- 使用下面的值
      if(p2<accuracy-1)
         p2+=1;
      if(p3>1)
         p3-=1;
      //--- 切换点
      if(!ElliotWave5PointChange(0,InpName,1,date[d2],price[p2]))
         return;
      if(!ElliotWave5PointChange(0,InpName,2,date[d3],price[p3]))
         return;
      //--- 检查脚本操作是否已经强制禁用
      if(IsStopped())
         return;
      //--- 重画图表
      ChartRedraw();
     }
//--- 1 秒延迟
   Sleep(1000);
//--- 循环计数器
   v_steps=accuracy*4/5;
//--- 移动第一个和第四个定位点
   for(int i=0;i<v_steps;i++)
     {
      //--- 使用下面的值
      if(p1>1)
         p1-=1;
      if(p4<accuracy-1)
         p4+=1;
      //--- 切换点
      if(!ElliotWave5PointChange(0,InpName,0,date[d1],price[p1]))
         return;
      if(!ElliotWave5PointChange(0,InpName,3,date[d4],price[p4]))
         return;
      //--- 检查脚本操作是否已经强制禁用
      if(IsStopped())
         return;
      //--- 重画图表
      ChartRedraw();
     }
//--- 1 秒延迟
   Sleep(1000);
//--- 删除图表对象
   ElliotWave5Delete(0,InpName);
   ChartRedraw();
//--- 1 秒延迟
   Sleep(1000);
//---
  }