【问题标题】:Calculate Standard Deviation in MQL from a custom built array根据自定义构建的数组计算 MQL 中的标准偏差
【发布时间】:2018-12-15 16:37:15
【问题描述】:

我正在尝试计算两种仪器的价格比率的较低 2SD 和较高 2SD,但是,它给了我 0 个结果。预期结果如下所示。 enter image description here

我试图通过在全局范围内声明数组然后向它添加值来创建一个数组,但是它给了我零作为值,我还尝试手动添加值以检查它是否工作但函数 @987654322 @ 也给了我同样的结果。任何帮助指导我哪里错了都将不胜感激。 这些是我尝试过的代码,但没有给我任何结果。

d[z] = iClose(sym1,0,z)/iClose(sym2,0,z);

c = iStdDevOnArray(iClose(sym1,0,z),0,z,0,0,z);

我正在部署的代码如下。

#property indicator_separate_window
#property indicator_buffers 4
extern string sym1    = "AUDUSD";
extern string sym2    = "NZDUSD";
extern int barcount     = 500;

//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];

//Global Variables
int ArrayIndex;
double ArraySum;
double a = 0;
double b=0;
double c=0;
double lowersd=0;
double highersd=0;


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE,EMPTY,2,clrYellow);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_LINE,EMPTY,2,clrRed);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexStyle(2,DRAW_LINE,EMPTY,2,clrGreen);
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexStyle(3,DRAW_LINE,EMPTY,2,clrPink);
   SetIndexBuffer(3,ExtMapBuffer4);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()


  {
  
//----
   for(int z=0;z<barcount;z++)
  {
  // To calculate the average of the ratio
   a=iClose(sym1,0,z)+a; 
   // Alert(d[0]);
   b=iClose(sym2,0,z)+b;
  // Below are the dummy data to create the chart
   lowersd =  1.04;
   highersd = 1.115;

   }
   
   for(int i=0;i<barcount;i++)
  {

   ExtMapBuffer1[i] = iClose(sym1,0,i)/iClose(sym2,0,i);
   ExtMapBuffer2[i] = (a/b);
   ExtMapBuffer3[i] = lowersd; // these are dummy values i am trying to populate this dynamically using the non working code above.
   ExtMapBuffer4[i] = highersd;
   
   }
   
//----
   return(0);
  
  }

【问题讨论】:

    标签: mql4


    【解决方案1】:

    您可以使用它来首先初始化数组

      double arr[];
      ArrayResize(arr, barcount);
      arr[z] = iClose(sym1,0,z)/iClose(sym2,0,z);
      c=iStdDevOnArray(arr,barcount,barcount,0,MODE_EMA,0);
    

    然后你可以把这个值放到ExtBuffer中

       ExtMapBuffer3[i] = (a/b)-(c*2);
       ExtMapBuffer4[i] = (a/b)+(c*2);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-26
      相关资源
      最近更新 更多