//+------------------------------------------------------------------+ //| The20sv0.20.mq5 | //| Copyright �2005, TraderSeven | //| TraderSeven@gmx.net | //+------------------------------------------------------------------+ /* * This EA has 2 main parts. * Variation=false * If previous bar opens in the lower 20% of its range and closes in the upper 20% of its range then sell on previous high+10pips. * If previous bar opens in the upper 20% of its range and closes in the lower 20% of its range then buy on previous low-10pips. * Variation=true * The previous bar is an inside bar that has a smaller range than the 3 bars before it. * If todays bar opens in the lower 20% of yesterdays range then buy. * If todays bar opens in the upper 20% of yesterdays range then sell. */ #property copyright "Copyright �2005, TraderSeven" #property link "TraderSeven@gmx.net" //---- 指标版本号 #property version "1.00" //---- 在主窗口中绘图 #property indicator_chart_window //----two buffers are used for calculation and drawing of the indicator #property indicator_buffers 2 //---- 只使用两个绘图 #property indicator_plots 2 //+----------------------------------------------+ //| Bearish indicator drawing parameters | //+----------------------------------------------+ //---- 指标 1 绘制为符号 #property indicator_type1 DRAW_ARROW //---- 熊势指标线使用洋红色 #property indicator_color1 clrMagenta //---- 指标1线宽为2 #property indicator_width1 2 //---- 牛势指标显示标签 #property indicator_label1 "The20sv0.20 Sell" //+----------------------------------------------+ //| 绘制牛势指标的参数 | //+----------------------------------------------+ //---- drawing the indicator 2 as a symbol #property indicator_type2 DRAW_ARROW //---- 牛势指标线使用蓝色 #property indicator_color2 clrBlue //---- 指标2线宽为2 #property indicator_width2 2 //---- 熊势指标显示标签 #property indicator_label2 "The20sv0.20 Buy" //+----------------------------------------------+ //| 声明常数 | //+----------------------------------------------+ #define RESET 0 // 用于把重新计算命令从指标发回到终端的常数 //+----------------------------------------------+ //| 指标输入参数 | //+----------------------------------------------+ input bool Variation=false; input double StopLevel=0.20; // level of triggering input uint Range=10; // distance in points //+----------------------------------------------+ //---- 声明动态数组,将 // 用作指标缓冲区 double SellBuffer[]; double BuyBuffer[]; double PRange; //---- 声明整型变量用于数据起点 int min_rates_total; //+------------------------------------------------------------------+ //| 自定义指标初始化函数 | //+------------------------------------------------------------------+ void OnInit() { //---- initialization of global variables min_rates_total=5; PRange=Range*_Point; //---- 把动态数组设置为指标缓冲区 SetIndexBuffer(0,SellBuffer,INDICATOR_DATA); //---- 转换指标1的绘制起点 PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total); //---- 指标符号 PlotIndexSetInteger(0,PLOT_ARROW,181); //---- indexing elements in the buffer as in time series ArraySetAsSeries(SellBuffer,true); //---- setting values of the indicator that won't be visible on a chart PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0); //---- 把动态数组设置为指标缓冲区 SetIndexBuffer(1,BuyBuffer,INDICATOR_DATA); //---- shifting the starting point of calculation of drawing of the indicator 2 PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,min_rates_total); //---- 指标符号 PlotIndexSetInteger(1,PLOT_ARROW,181); //---- indexing elements in the buffer as in time series ArraySetAsSeries(BuyBuffer,true); //---- setting values of the indicator that won't be visible on a chart PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0); //---- 设置指标显示精确度格式 IndicatorSetInteger(INDICATOR_DIGITS,_Digits); //---- 数据窗口上的名字以及子窗口的标签 string short_name="The20sv0.20"; IndicatorSetString(INDICATOR_SHORTNAME,short_name); //---- } //+------------------------------------------------------------------+ //| 自定义指标迭代函数 | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { //---- 检查柱是否足够用于计算 if(rates_totalrates_total || prev_calculated<=0)// 检查是否为第一次开始计算指标 limit=rates_total-min_rates_total-1; // 计算全部柱的起点索引 else limit=rates_total-prev_calculated; // 计算新柱的起点索引 //---- indexing elements in arrays as in time series ArraySetAsSeries(open,true); ArraySetAsSeries(high,true); ArraySetAsSeries(low,true); ArraySetAsSeries(close,true); //---- 指标计算的主循环 for(int bar=limit; bar>=0 && !IsStopped(); bar--) { SellBuffer[bar]=0.0; BuyBuffer[bar]=0.0; double LastBarsRange=high[bar+1]-low[bar+1]; double Top20=high[bar+1]-LastBarsRange*StopLevel; double Bottom20=low[bar+1]+LastBarsRange*StopLevel; if(!Variation) { if(open[bar+1]>=Top20 && close[bar+1]<=Bottom20 && low[bar]<=low[bar+1]+PRange) BuyBuffer[bar]=low[bar]; if(open[bar+1]<=Bottom20 && close[bar+1]>=Top20 && high[bar]>=high[bar+1]+PRange) SellBuffer[bar]=high[bar]; } else { if((high[bar+4]-low[bar+4])>LastBarsRange && (high[bar+3]-low[bar+3])>LastBarsRange && (high[bar+2]-low[bar+2])>LastBarsRange && high[bar+2]>high[bar+1] && low[bar+2]=Top20) SellBuffer[bar]=high[bar]; } } } //---- return(rates_total); } //+------------------------------------------------------------------+