Open Forex4you Account

Server รัน EA 1000 / ปี

สั่งชื้อคู่มือการโปรแรกม MQL4

Author Topic: ปัญหาการเขียนiCustom  (Read 11077 times)

suttisak

  • Newbie
  • *
  • Posts: 9
ปัญหาการเขียนiCustom
« on: กรกฎาคม 24, 2015, 03:30:44 pm »
ผมพยายามจะเขียนอินดีเองครับ
แต่พอใส่ชาร์ตไปมันแจ้ง error  "  array out of range in 'Phi2.mq4' (89,15)  "

รบกวนแอดมินและท่านผู้รู้แนะนำด้วยครับ

//+------------------------------------------------------------------+
//|                                           
//+------------------------------------------------------------------+
#property copyright
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_minimum 1
#property indicator_maximum 2
#property indicator_level1   1.618
#property indicator_buffers 1
#property indicator_plots   1
//--- plot Label1
#property indicator_label1  "Label1"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1


input string pair = "USDCHF";
input double Phi = 1.618;


//--- indicator buffers
double         Label1Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,Label1Buffer);
    string short_name;
//--- indicator line
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,Label1Buffer);
//--- name for DataWindow and indicator subwindow label
   short_name="Phi";
   IndicatorShortName(short_name);
   SetIndexLabel(0,short_name);
//--- check for input parameter

//---
   SetIndexDrawBegin(0,Phi);
//--- initialization done
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
  {
//---
 int counted_bars=IndicatorCounted();
  if (counted_bars<0)return(-1);
  if(counted_bars>0)counted_bars--;
 
  int pos=Bars-counted_bars;
  Comment(pos+"::::"+counted_bars);
 
//--- counting from 0 to rates_total
   ArraySetAsSeries(Label1Buffer,false);
   ArraySetAsSeries(close,false);

   while(pos>0)
   {
        double a = NormalizeDouble(MarketInfo(NULL,MODE_BID),4);
  double b = NormalizeDouble(MarketInfo(pair,MODE_BID),4);
  double x = (a+b)/a;
  double y = a/b;
  double z = x/y;
//  double phi = 1.618;
 // double zx = z-phi;
  Label1Buffer[pos]=z;
  pos--;
 
   
   }
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+