• EA programming tutorial book of commonly used functions

    read:2023/2/24 18:44:58


    For each executed MQL4 program, a certaforex trading accounts number of variables can be set to easily cope with the price state in the chart: smart trading, script or client indicators.  Information applied to variable models can be handled separately by predefined variables These data are updated after opening by applying the RefreshRates() function   Ask Bars Bid Close  Digits High Low Open Point Time Volume AskdoubleAsk for the latest selling price of the cashback forex currency pair using the RefreshRates() function to update See MarketInfo().  Example: if(iRSI(NULL,0,14,PRICE_CLOSE,0)<25)   {  OrderSend(Symbol(),OP_BUY,Lots,Ask,3, Bid-StopLoss*Point,Ask+TakeProfit*Point,              Myorder#2,3, D2005.10.1012:30,Red);    return;    }  BarsintBars returns the number of bars in the chart see iBars().  Example: intcounter=1; for(inti=1;i<=Bars;i++)   {   Print(close[i-1]);    } BiddoubleBid for the current currency pairs latest buy price using the RefreshRates() function to update See MarketInfo().  Example: if(iRSI(NULL,0,14,PRICE_CLOSE,0)>75)   {  OrderSend(EURUSD,OP_SELL,Lots,Bid,3,Ask +StopLoss*Point,Bid-TakeProfit*Point,             MyOrder#2,3,D 2005.10.1012:30,Red);   return(0);    }  ClosedoubleClose[] series forextradingaccountstype contains the closing price of each bar of the current chart series array elements are forextradingaccountsregister into the inverted order of the order, that is, from the last to the first . The current last bar in the array is indexed at 0 The first bar in the chart is indexed at Bars-1. See iClose().  Example: inthandle=FileOpen(file.csv,FILE_CSV|FILE_WRITE,;); if(handle>0)   {    //table bar Title record   FileWrite(handle,Time;Open;High;Low;Close;Volume);   //Data record   for(inti=0;i< Bars;i++)    FileWrite(handle,Time,Open,High,Low,Close,Volume);   FileClose(handle);  ;  }  DigitsintDigits returns the current currency pairs exchange rate in decimal places see MarketInfo().  Example:Print(DoubleToStr(Close[0],decimal places));  HighdoubleHigh[] series array contains the highest price of each column of the current chart The series array elements are indexed into the reverse order of the order, that is, from the last to the first. The current last column in the array is indexed at 0 The first column in the chart is indexed at Bars-1. See iHigh().  Example://---- maximum i=Bars-KPeriod; if(counted_bars>KPeriod)i=Bars-counted_bars-1; while(i>=0)  & nbsp;{     doublemax=-1000000;      k=i+KPeriod-1;       while(k>=i)        {         price=High[k];     ;    if(max<price)max=price;           k--;           nbsp; }     HighesBuffer=max;      i--;     }//----LowdoubleLow The []series array contains the lowest price for each column of the current chart The series array elements are indexed into the reverse order of the order, i.e., from the last to the first. The current last column in the array is indexed at 0 The first column in the chart is indexed at Bars-1. See iLow().  Example://---- minimum i=Bars-KPeriod; if(counted_bars>KPeriod)i=Bars-counted_bars-1; while(i>=0)  & nbsp;{     doublemin=1000000;     k=i+KPeriod-1;       while(k>=i)        {        price=Low[k];         if(min>price)min=price;         k--;            nbsp; }    LowesBuffer=min;      i--;    }//----   OpendoubleOpen[] series array contains the opening price of each bar of the current chart The series array elements are indexed into the reverse order of the order, i.e. from the last to the first. The current last bar in the array is indexed at 0 The first bar in the chart is indexed at Bars-1. See iOpen().  Example: i=Bars-counted_bars-1; while(i>=0)   {     doublehigh =High;  nbsp;    doublelow =Low;       doubleopen =Open;        ;doubleclose=Close;     AccumulationBuffer=(close-low)-(high-close);     if( AccumulationBuffer!=0)       {      doublediff=high-low;& nbsp;      if(0==diff)                AccumulationBuffer=0;        else           { & nbsp;         AccumulationBuffer/=diff;             nbsp;   AccumulationBuffer*=Volume;             }       & nbsp;  }     if(i<Bars-1)AccumulationBuffer+=AccumulationBuffer[i+1];       ; i--;   } doublePoint returns the point value of the current chart see MarketInfo().  Example:OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point);  datetimeTimedatetimeTime[] series array contains data for each bar opening time of the current chart like datetimeTimedatetimeTime[] series array contains each bar of the current chart opening time data like datetimeTimedatetimeTime presents time in seconds from January 1, 1979 at 00:00  series array elements are indexed into the inverted order of the order, that is, from the last to the first current last bar in the array indexed to 0 the first bar of the chart indexed to Bars-1. See iTime().  Example: 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];       //---- & nbsp;   if(TimeDay(Time)! =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;      LastHigh=Open;    ;     }      //----       PBuffer =P;     nbsp;  S1Buffer=S1;     R1Buffer=R1;       S2Buffer=S2;     ;  R2Buffer=R2;      S3Buffer=S3;      R3Buffer=R3;    }& nbsp;VolumedoubleVolume[] series array contains the current chart of each column tic volume series array elements are indexed into the reverse order of the order, that is, from the last to the first. The current last column in the array is indexed at 0 The first column in the chart is indexed at Bars-1. See iVolume().  Example:     if(i==0&&time0<i_time+periodseconds)          {& nbsp;     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);    nbsp;   last_volume=Volume;      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);