myeatrade

MQL4 Reference

MQL4 Predefined variables

For each executable MQL4 program, a number of predefined variables is supported that reflect the state of the current price chart at the launching of a program: an expert, a script, or a custom indicator.

Libraries use variables of the module that has called a library.

To have a safe and quick access to these data, client terminal provides local copies of predefined variables for each launched program separately. These data are updated at every launch of an attached expert or a custom indicator automatically or using the RefreshRates() function call.

Ask

double Ask

The latest known seller’s price (ask price) for the current symbol. The RefreshRates() function must be used to update.

See also MarketInfo().

Sample:

  if(iRSI(NULL,0,14,PRICE_CLOSE,0)<25)
    {
     OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Bid-StopLoss*Point,Ask+TakeProfit*Point,
               "My order #2",3,D'2005.10.10 12:30',Red);
     return;
    }

Bid

double Bid

The latest known buyer’s price (offer price, bid price) of the current symbol. The RefreshRates() function must be used to update.

See also MarketInfo().

Sample:

  if(iRSI(NULL,0,14,PRICE_CLOSE,0)>75)
    {
     OrderSend("EURUSD",OP_SELL,Lots,Bid,3,Ask+StopLoss*Point,Bid-TakeProfit*Point,
               "My Order #2",3,D'2005.10.10 12:30',Red);
     return(0);
    }

Bars

int Bars

Number of bars in the current chart.

See also iBars().

Sample:

  int counter=1;
  for(int i=1; i<=Bars; i++)
    {
     Print(Close[i-1]);
    }

Digits

int Digits

Number of digits after decimal point for the current symbol prices.

See also MarketInfo().

Sample:

Print(DoubleToStr(Close[0], Digits));

Point

double Point

The current symbol point value in the quote currency.

See also MarketInfo().

Sample:

OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point);

Close[ ]

double Close[]

Series array that contains close prices for each bar of the current chart.

Series array elements are indexed in the reverse order, i.e., from the last one to the first one. The current bar which is the last in the array is indexed as 0. The oldest bar, the first in the chart, is indexed as Bars-1.

See also iClose().

Sample:

  int handle = FileOpen("file.csv", FILE_CSV|FILE_WRITE, ";");
  if(handle>0)
    {
     // table column headers recording
     FileWrite(handle, "Time;Open;High;Low;Close;Volume");
     // data recording
     for(int i=0; i<Bars; i++)
       FileWrite(handle, Time[i], Open[i], High[i], Low[i], Close[i], Volume[i]);
     FileClose(handle);
    }

Open[ ]

double Open[]

Series array that contains open prices of each bar of the current chart.

Series array elements are indexed in the reverse order, i.e., from the last one to the first one. The current bar which is the last in the array is indexed as 0. The oldest bar, the first in the chart, is indexed as Bars-1.

See also iOpen().

Sample:

   i = Bars - counted_bars - 1;
   while(i>=0)
     {
      double high  = High[i];
      double low   = Low[i];
      double open  = Open[i];
      double close = Close[i];
      AccumulationBuffer[i] = (close-low) - (high-close);
      if(AccumulationBuffer[i] != 0)
        {
         double diff = high - low;
         if(0==diff)
            AccumulationBuffer[i] = 0;
         else
           {
            AccumulationBuffer[i] /= diff;
            AccumulationBuffer[i] *= Volume[i];
           }
        }
      if(i<Bars-1) AccumulationBuffer[i] += AccumulationBuffer[i+1];
      i--;
     }

High[ ]

double High[]

Series array that contains the highest prices of each bar of the current chart.

Series array elements are indexed in the reverse order, i.e., from the last one to the first one. The current bar which is the last in the array is indexed as 0. The oldest bar, the first in the chart, is indexed as Bars-1.

See also iHigh().

Sample:

//---- maximums counting
   i=Bars-KPeriod;
   if(counted_bars>KPeriod) i=Bars-counted_bars-1;
   while(i>=0)
     {
      double max=-1000000;
      k = i + KPeriod-1;
      while(k>=i)
        {
         price=High[k];
         if(max<price) max=price;
         k--;
        }
      HighesBuffer[i]=max;
      i--;
     }
//----

Low[ ]

double Low[]

Series array that contains the lowest prices of each bar of the current chart.

Series array elements are indexed in the reverse order, i.e., from the last one to the first one. The current bar which is the last in the array is indexed as 0. The oldest bar, the first in the chart, is indexed as Bars-1.

See also iLow().

Sample:

//---- minima counting
   i=Bars-KPeriod;
   if(counted_bars>KPeriod) i=Bars-counted_bars-1;
   while(i>=0)
     {
      double min=1000000;
      k = i + KPeriod-1;
      while(k>=i)
        {
         price=Low[k];
         if(min>price) min=price;
         k--;
        }
      LowesBuffer[i]=min;
      i--;
     }
//----

Time[ ]

datetime Time[]

Series array that contains open time of each bar of the current chart. Data like datetime represent time, in seconds, that has passed since 00:00 a.m. of 1 January, 1970.

Series array elements are indexed in the reverse order, i.e., from the last one to the first one. The current bar which is the last in the array is indexed as 0. The oldest bar, the first in the chart, is indexed as Bars-1.

See also iTime().

Sample:

   for(i=Bars-2; i>=0; i--)
     {
      if(High[i+1] > LastHigh) LastHigh = High[i+1];
      if(Low[i+1] < LastLow)   LastLow  = Low[i+1];
      //----
      if(TimeDay(Time[i]) != TimeDay(Time[i+1]))
        {
         P = (LastHigh + LastLow + Close[i+1])/3;
         R1 = P*2 - LastLow;
         S1 = P*2 - LastHigh;
         R2 = P + LastHigh - LastLow;
         S2 = P - (LastHigh - LastLow);
         R3 = P*2 + LastHigh - LastLow*2;
         S3 = P*2 - (LastHigh*2 - LastLow);
         LastLow  = Open[i];
         LastHigh = Open[i];
        }
      //----
      PBuffer[i]  = P;
      S1Buffer[i] = S1;
      R1Buffer[i] = R1;
      S2Buffer[i] = S2;
      R2Buffer[i] = R2;
      S3Buffer[i] = S3;
      R3Buffer[i] = R3;
     }

Volume[ ]

double Volume[]

Series array that contains tick volumes of each bar of the current chart.

Series array elements are indexed in the reverse order, i.e., from the last one to the first one. The current bar which is the last in the array is indexed as 0. The oldest bar, the first in the chart, is indexed as Bars-1.

See also iVolume().

Sample:

      if(i==0 && time0<i_time+periodseconds)
        {
         d_volume += Volume[0];
         if(Low[0]<d_low)   d_low = Low[0];
         if(High[0]>d_high) d_high = High[0];
         d_close = Close[0];
        }
      last_fpos = FileTell(ExtHandle);
      last_volume = Volume[i];
      FileWriteInteger(ExtHandle, i_time, LONG_VALUE);
      FileWriteDouble(ExtHandle, d_open, DOUBLE_VALUE);
      FileWriteDouble(ExtHandle, d_low, DOUBLE_VALUE);
      FileWriteDouble(ExtHandle, d_high, DOUBLE_VALUE);
      FileWriteDouble(ExtHandle, d_close, DOUBLE_VALUE);
      FileWriteDouble(ExtHandle, d_volume, DOUBLE_VALUE);
This article url: http://www.myeatrade.com/427/

Please login to post comment, if you haven't account you can register free