脚本: 导出指标值 - 页 2

[删除]  
不起作用。
 
我无法导出 50 期指数 移动平均线的值,有人能帮我吗?
 

在文件夹中搜索文件

C:\Users\XXX\AppData\Roaming\MetaQuotes\Terminal\ZXVVDASDADDEDADS23132\MQL5\Files

 
Automated-Trading:

导出指标值

作者:NFTrader

脚本很不错,但我更希望数据能通过 RTD 服务器直接导入 excel,使用 excel 的 RDTR 功能。你们有这样的计划吗?
 
Automated-Trading:

导出指标值

作者:NFTrader

 
Jose Luis Perez Navarro:
脚本非常好,但我更希望数据能通过 RTD 服务器直接进入 excel,使用 excel 的 RDTR 功能。您有类似的想法吗?
xm.cm real14
 

可以。您需要查看 ...MQL5(Files)路径,那里有 CSV 文件。

我已经修改了保存 OBV(实际成交量)值的方法,只需修改以下代码即可


Indicator_Directory_And_Name="Examples\\OBV";
IndicatorPeriod=VOLUME_REAL;
 
Ecirba:

你好、

谢谢你的工作,但不幸的是,当我运行脚本时,并没有创建任何文件。我更新了脚本,将文件写入 C:/temp/。在调试模式下运行时,我可以看到文件名是正确的,也没有出现任何错误,但就是没有文件。

有什么线索吗?


如果检查 句柄,可能会返回 -1 (无效句柄)。


Print ( "fileHandle Value=", fileHandle);


由于某些原因,MT5 不喜欢您将文件保存在与默认值不同的位置。只需按照原始代码,它就会写入 ...MQL5(文件路径

 

恭喜您的脚本,我正在将 volatilitypivot 标志的值导出到 csv 中,但脚本只正确导出了高值,在应该显示低值的行中出现了错误。

谁能帮帮我?

波动率透视脚本

#property indicator_chart_window
//--- 4 个缓冲区用于计算和绘制指示器
#property indicator_buffers 4
//--- 使用了 4 个绘图
#property indicator_plots   4
//+----------------------------------------------+
//| 看涨指标绘图参数
//+----------------------------------------------+
//--- 将指标 1 画成一条线
#property indicator_type1   DRAW_LINE
//--- 指示线使用蓝色
#property indicator_color1  clrBlue
//--- the indicator 1 line is a dot-dash one
#property indicator_style1  STYLE_DASHDOTDOT
//---指标 1 的行宽等于 2
#property indicator_width1  2
//---- 显示指标标签
#property indicator_label1  "Upper VolatilityPivot"
//+----------------------------------------------+
//| 绘制看跌指标的参数
//+----------------------------------------------+
//--- 将指标 2 画成一条线
#property indicator_type2   DRAW_LINE
//--- 指示线使用 HotPink 颜色
#property indicator_color2  clrHotPink
//----指标 2 行是点-虚线
#property indicator_style2  STYLE_DASHDOTDOT
//---指标 2 行宽等于 2
#property indicator_width2  2
//---- 显示指标标签
#property indicator_label2  "Lower VolatilityPivot"
//+----------------------------------------------+
//| 看涨指标绘图参数
//+----------------------------------------------+
//--- 将指标 3 画成标签
#property indicator_type3   DRAW_ARROW
//--- 指示器使用深空蓝(DeepSkyBlue)颜色
#property indicator_color3  clrDeepSkyBlue
//--- 指示器 3 的宽度等于 4
#property indicator_width3  4
//--- 显示指标标签
#property indicator_label3  "Buy VolatilityPivot"
//+----------------------------------------------+
//| 绘制看跌指标的参数
//+----------------------------------------------+
//--- 绘制指示符 4 作为标签
#property indicator_type4   DRAW_ARROW
//--- 指示器使用红色
#property indicator_color4  clrRed
//---指标 4 宽度等于 4
#property indicator_width4  4
//--- 显示指标标签
#property indicator_label4  "Sell VolatilityPivot"
//+----------------------------------------------+
//| 常量的声明
//+----------------------------------------------+
#define  RESET 0  // 用于向终端返回指标重新计算命令的常数
//+----------------------------------------------+
//| 枚举声明
//+----------------------------------------------+
enum Mode_
  {
   Mode_ATR=0,   //ATR
   Mode_Price    //价格偏差
  };
//+----------------------------------------------+
//| 指标输入参数
//+----------------------------------------------+
input uint   atr_range=100;
input uint   ima_range=10;
input double atr_factor=3;
input Mode_  Mode=Mode_ATR;
input  uint  DeltaPrice=200;
input int    Shift=0;          // 以小节为单位的指标水平移动
//+----------------------------------------------+
//----动态数组的声明
//--- 将用作指示器缓冲区
double ExtMapBufferUp[];
double ExtMapBufferDown[];
double ExtMapBufferUp1[];
double ExtMapBufferDown1[];
//---
double dDeltaPrice;
//--- 为指标句柄声明整数变量
int ATR_Handle;
//--- 为开始数据计算而声明整数变量
int min_rates_total;
//+------------------------------------------------------------------+
//| CMoving_Average 类说明|
//+------------------------------------------------------------------+
#include <SmoothAlgorithms.mqh>
//+------------------------------------------------------------------+
//| 自定义指示器初始化函数
//+------------------------------------------------------------------+ 
int OnInit()
  {
//--- 获取 ATR 指标的句柄
   if(Mode==Mode_ATR)
     {
      min_rates_total=int(atr_range+ima_range)+1;
      ATR_Handle=iATR(NULL,0,atr_range);
      if(ATR_Handle==INVALID_HANDLE)
        {
         Print(" Failed to get handle of the ATR indicator");
         return(INIT_FAILED);
        }
     }
   else
     {
      min_rates_total=3;
      dDeltaPrice=DeltaPrice*_Point;
     }
//--- 将 ExtMapBufferUp[] 动态数组设为指示器缓冲区
   SetIndexBuffer(0,ExtMapBufferUp,INDICATOR_DATA);
//---- 通过 Shift 水平移动指标 1
   PlotIndexSetInteger(0,PLOT_SHIFT,Shift);
//--- 移动绘制指示器的起始位置 1
   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total);
//--- 将缓冲区元素索引为时间序列 
   ArraySetAsSeries(ExtMapBufferUp,true);
//--- 设置图表上不可见的指标值
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);
//--- 将 ExtMapBufferDown[] 动态数组设为指示器缓冲区
   SetIndexBuffer(1,ExtMapBufferDown,INDICATOR_DATA);
//---- 通过 Shift 水平移动指示器 2
   PlotIndexSetInteger(1,PLOT_SHIFT,Shift);
//--- 移动指标 2 绘图计算的起点
   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,min_rates_total);
//--- 将缓冲区元素索引为时间序列 
   ArraySetAsSeries(ExtMapBufferDown,true);
//--- 设置图表上不可见的指标值
   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,EMPTY_VALUE);
//--- 将 ExtMapBufferUp1[] 动态数组设置为指示器缓冲区
   SetIndexBuffer(2,ExtMapBufferUp1,INDICATOR_DATA);
//---- 通过 Shift 水平移动指标 1
   PlotIndexSetInteger(2,PLOT_SHIFT,Shift);
//--- 移动绘制指示器的起始位置 3
   PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,min_rates_total);
//--- 将缓冲区元素索引为时间序列 
   ArraySetAsSeries(ExtMapBufferUp1,true);
//--- 设置图表上不可见的指标值
   PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,EMPTY_VALUE);
//--- 指示符号
   PlotIndexSetInteger(2,PLOT_ARROW,118);
//--- 将 ExtMapBufferDown1[] 动态数组设置为指示器缓冲区
   SetIndexBuffer(3,ExtMapBufferDown1,INDICATOR_DATA);
//---- 通过 Shift 水平移动指示器 2
   PlotIndexSetInteger(3,PLOT_SHIFT,Shift);
//--- 移动绘制指示器的起始位置 4
   PlotIndexSetInteger(3,PLOT_DRAW_BEGIN,min_rates_total);
//--- 将缓冲区元素索引为时间序列 
   ArraySetAsSeries(ExtMapBufferDown1,true);
//--- 设置图表上不可见的指标值
   PlotIndexSetDouble(3,PLOT_EMPTY_VALUE,EMPTY_VALUE);
//--- 指示符号
   PlotIndexSetInteger(3,PLOT_ARROW,118);
//--- 创建名称,并在单独的子窗口和弹出帮助中显示
   IndicatorSetString(INDICATOR_SHORTNAME,"VolatilityPivot");
//--- 确定指标值的准确性
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//--- 初始化结束
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| 自定义指标迭代函数|
//+------------------------------------------------------------------+
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((BarsCalculated(ATR_Handle)<rates_total && Mode==Mode_ATR) || rates_total<min_rates_total) return(RESET);
//--- 本地变量的声明 
   double DeltaStop,Stop;
   static double PrevStop;
   int limit,bar;
//--- 像在时间序列中一样在数组中索引元素 
   ArraySetAsSeries(close,true);
//--- 为条形图重新计算循环计算 "极限 "起始指数
   if(prev_calculated>rates_total || prev_calculated<=0) // 检查指标是否首次开始计算
     {
      limit=rates_total-min_rates_total-1;               // 计算所有条形图的起始指数
      PrevStop=close[limit+1];
     }
   else limit=rates_total-prev_calculated;               // 计算新条形的起始指数
//---
   if(Mode==Mode_Price)
     {
      //--- 主指标计算循环
      for(bar=limit; bar>=0; bar--)
        {
         ExtMapBufferUp1[bar]=EMPTY_VALUE;
         ExtMapBufferDown1[bar]=EMPTY_VALUE;
         DeltaStop=dDeltaPrice;
         //---
         if(close[bar]==PrevStop) Stop=PrevStop;
         else
           {
            if(close[bar+1]<PrevStop && close[bar]<PrevStop) Stop=MathMin(PrevStop,close[bar]+DeltaStop);
            else
              {
               if(close[bar+1]>PrevStop && close[bar]>PrevStop) Stop=MathMax(PrevStop,close[bar]-DeltaStop);
               else
                 {
                  if(close[bar]>PrevStop) Stop=close[bar]-DeltaStop;
                  else Stop=close[bar]+DeltaStop;
                 }
              }
           }
         //---
         if(close[bar]>Stop) ExtMapBufferUp[bar]=Stop; else ExtMapBufferUp[bar]=EMPTY_VALUE;
         if(close[bar]<Stop) ExtMapBufferDown[bar]=Stop; else ExtMapBufferDown[bar]=EMPTY_VALUE;
         if(ExtMapBufferUp[bar+1]==EMPTY_VALUE && ExtMapBufferUp[bar]!=EMPTY_VALUE) ExtMapBufferUp1[bar]=ExtMapBufferUp[bar];
         if(ExtMapBufferDown[bar+1]==EMPTY_VALUE && ExtMapBufferDown[bar]!=EMPTY_VALUE) ExtMapBufferDown1[bar]=ExtMapBufferDown[bar];
         if(bar) PrevStop=Stop;
        }
     }
//---
   if(Mode==Mode_ATR)
     {
      //--- 本地变量的声明 
      double ATR[];
      int to_copy,maxbar;
      //--- 从 SmoothAlgorithms.mqh 文件中声明 CMoving_Average 类变量 
      static CMoving_Average EMA;
      //--- 像在时间序列中一样在数组中索引元素 
      ArraySetAsSeries(ATR,true);
      to_copy=limit+1;
      if(CopyBuffer(ATR_Handle,0,0,to_copy,ATR)<=0) return(RESET);
      maxbar=rates_total-min_rates_total-1;
      //--- 主指标计算循环
      for(bar=limit; bar>=0; bar--)
        {
         ExtMapBufferUp1[bar]=EMPTY_VALUE;
         ExtMapBufferDown1[bar]=EMPTY_VALUE;
         DeltaStop=atr_factor*EMA.EMASeries(maxbar,prev_calculated,rates_total,ima_range,ATR[bar],bar,true);
         //---
         if(close[bar]==PrevStop) Stop=PrevStop;
         else
           {
            if(close[bar+1]<PrevStop && close[bar]<PrevStop) Stop=MathMin(PrevStop,close[bar]+DeltaStop);
            else
              {
               if(close[bar+1]>PrevStop && close[bar]>PrevStop) Stop=MathMax(PrevStop,close[bar]-DeltaStop);
               else
                 {
                  if(close[bar]>PrevStop) Stop=close[bar]-DeltaStop;
                  else Stop=close[bar]+DeltaStop;
                 }
              }
           }
         //---
         if(close[bar]>Stop) ExtMapBufferUp[bar]=Stop; else ExtMapBufferUp[bar]=EMPTY_VALUE;
         if(close[bar]<Stop) ExtMapBufferDown[bar]=Stop; else ExtMapBufferDown[bar]=EMPTY_VALUE;
         //---
         if(ExtMapBufferUp[bar+1]==EMPTY_VALUE && ExtMapBufferUp[bar]!=EMPTY_VALUE) ExtMapBufferUp1[bar]=ExtMapBufferUp[bar];
         if(ExtMapBufferDown[bar+1]==EMPTY_VALUE && ExtMapBufferDown[bar]!=EMPTY_VALUE) ExtMapBufferDown1[bar]=ExtMapBufferDown[bar];
         //---
         if(bar) PrevStop=Stop;
        }
     }
//--- 
   return(rates_total);
  }

csv 错误

 

这个非常有用。

作者是牛人。