EA programming tutorial Daquan common functions
For each executed MQL4 program, a certain number of variable settings can easily respond to the price state in the chart.
Expert Advisors, scripts or client indicators.
The data is applied to a variable model.
It can be handled separately by predefined variables.
This data is updated by applying the RefreshRates () function after it is turned on.
Ask
Bars
Bid
Close
Digits
High
Low
Open
Point
Time
Volume
Ask
double Ask
The latest selling price for the current currency pair. Use 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,
"My order #2",3,D'2005.10.10 12:30',Red);
return;
}
Bars
int Bars
Returns the number of bars in the chart.
See iBars ().
Example:
int counter=1;
for(int i=1; i<=Bars; i++)
{
Print (close [i-1]);
}
Bid
double Bid
The latest buy price for the current currency pair. Use 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,
"My Order #2",3,D'2005.10.10 12:30',Red);
return(0);
}
Close
double Close[]
The series array contains the closing price of each bar on the current chart.
The array elements of the series are ordered in reverse order, i.e. from last to first. The current last bar in the array has an index of 0. The index of the first bar in the chart is Bars-1.
See iClose ().
Example:
int handle = FileOpen("file.csv", FILE_CSV|FILE_WRITE, ";");
if(handle0)
{
//table column title record
FileWrite(handle, "Time;Open;High;Low;Close;Volume");
//data logging
for(int i=0; i FileWrite(handle, Time, Open, High, Low, Close, Volume); FileClose(handle); } Digits int Digits Returns the exchange rate of the current currency pair to decimal places See MarketInfo (). Example: Print (DoubleToStr (Close [0], decimal place)); High double High[] The series array contains the highest price for each bar on the current chart. The array elements of the series are ordered in reverse order, i.e. from last to first. The current last bar in the array has an index of 0. The index of the first bar in the chart is Bars-1. See iHigh (). Example: //---- maximum i=Bars-KPeriod; if(counted_barsKPeriod) i=Bars-counted_bars-1; while(i=0) { double max=-1000000; k = i + KPeriod-1; while(k=i) { price=High[k]; if(max k--; } HighesBuffer=max; i--; } //---- Low double Low[] The series array contains the lowest price for each bar on the current chart. The array elements of the series are ordered in reverse order, i.e. from last to first. The current last bar in the array has an index of 0. The index of the first bar in the chart is Bars-1. See iLow (). Example: //---- minimum i=Bars-KPeriod; if(counted_barsKPeriod) i=Bars-counted_bars-1; while(i=0) { double min=1000000; k = i + KPeriod-1; while(k=i) { price=Low[k]; if(minprice) min=price; k--; } LowesBuffer=min; i--; } //---- Open double Open[] The series array contains the opening price of each bar on the current chart. The array elements of the series are ordered in reverse order, i.e. from last to first. The current last bar in the array has an index of 0. The index of the first bar in the chart is Bars-1. See iOpen (). Example: i = Bars - counted_bars - 1; while(i=0) { double high = High; double low = Low; double open = Open; double close = Close; AccumulationBuffer = (close-low) - (high-close); if(AccumulationBuffer != 0) { double diff = high - low; if(0==diff) AccumulationBuffer = 0; else { AccumulationBuffer /= diff; AccumulationBuffer *= Volume; } } if(i i--; } double Point Returns the point value of the current chart See MarketInfo (). Example: OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point); datetime Time datetime Time[] The series array contains the opening time of each bar for the current chart. The data is presented as datetime, in seconds from 0:00 on January 1, 1979. The array elements of the series are ordered in reverse order, that is, from the last to the first. The current last bar has an index of 0 in the array. The index of the first bar in the chart is 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]; //---- 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; S1Buffer = S1; R1Buffer = R1; S2Buffer = S2; R2Buffer = R2; S3Buffer = S3; R3Buffer = R3; } Volume double Volume[] The series array contains the volume of each column of the current chart. The array elements of the series are ordered in reverse order, i.e. from last to first. The current last bar in the array has an index of 0. The index of the first bar in the chart is Bars-1. See iVolume (). Example: if(i==0 && time0 { d_volume += Volume[0]; if(Low[0] if(High[0]d_high) d_high = High[0]; d_close = Close[0]; } last_fpos = FileTell(ExtHandle); 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); Please indicate the source: https://www.daoctech.com/fxoutrade/1990.html Disclaimer: The content of this article does not represent the views of the Institute of Foreign Exchange. The content is for reference only and does not constitute investment advice. Investors operate accordingly at their own risk.
