I start to learn mql5 today. It is a difficult for me . so I decided to write mql4 in mt5. and I start this project.
#property library#property copyright"Copyright 2018, MetaQuotes Software Corp."#property link"https://www.mql5.com"#property version"1.00"//#include <Indicators\indicator.mqh>//#include <K\predefinedVar.mqh>KPreVar var;//+------------------------------------------------------------------+//| My function |//+------------------------------------------------------------------+// int MyCalculator(int value,int value2) export// {// return(value+value2);// }//+------------------------------------------------------------------+class KPreVar
{
protected:
private:
int m_handle;
bool copyRates(int a_index=0,string a_sym=NULL,ENUM_TIMEFRAMES a_tf=PERIOD_CURRENT);
bool copyTime(int a_index=0,string a_sym=NULL,ENUM_TIMEFRAMES a_tf=PERIOD_CURRENT);
bool copyTicks(string a_sym=NULL);
MqlRates m_rates[1];
MqlTick m_ticks[1];
datetime m_time[1];
public:
KPreVar(void){};
~KPreVar(void){};
//Open //Series array that contains open prices of each bar of the current chartdouble open(int a_index=0,string a_sym=NULL,ENUM_TIMEFRAMES a_tf=PERIOD_CURRENT){copyRates(a_index,a_sym,a_tf);return m_rates[0].open;};
//Close //Series array that contains close prices for each bar of the current chartdouble close(int a_index=0,string a_sym=NULL,ENUM_TIMEFRAMES a_tf=PERIOD_CURRENT){copyRates(a_index,a_sym,a_tf);return m_rates[0].close;};
//High //Series array that contains the highest prices of each bar of the current chartdouble high(int a_index=0,string a_sym=NULL,ENUM_TIMEFRAMES a_tf=PERIOD_CURRENT){copyRates(a_index,a_sym,a_tf);return m_rates[0].high;};
//Low //Series array that contains the lowest prices of each bar of the current chartdouble low(int a_index=0,string a_sym=NULL,ENUM_TIMEFRAMES a_tf=PERIOD_CURRENT){copyRates(a_index,a_sym,a_tf);return m_rates[0].low;};
int spread(int a_index=0,string a_sym=NULL,ENUM_TIMEFRAMES a_tf=PERIOD_CURRENT){copyRates(a_index,a_sym,a_tf);return m_rates[0].spread;};
//Volume//Series array that contains tick volumes of each bar of the current chartlong tick_volume(int a_index=0,string a_sym=NULL,ENUM_TIMEFRAMES a_tf=PERIOD_CURRENT){copyRates(a_index,a_sym,a_tf);return m_rates[0].tick_volume;};
long real_volume(int a_index=0,string a_sym=NULL,ENUM_TIMEFRAMES a_tf=PERIOD_CURRENT){copyRates(a_index,a_sym,a_tf);return m_rates[0].real_volume;};
//Time //Series array that contains open time of each bar of the current chartdatetime time(int a_index=0,string a_sym=NULL,ENUM_TIMEFRAMES a_tf=PERIOD_CURRENT){copyTime(a_index,a_sym,a_tf);return m_time[0];};
//Ask //The latest known seller's price (ask price) of the current symboldoubleAsk(string a_sym=NULL){copyTicks(a_sym);return m_ticks[0].ask;};
//Bid //The latest known buyer's price (offer price, bid price) of the current symboldoubleBid(string a_sym=NULL){copyTicks(a_sym);return m_ticks[0].bid;};
};
//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+/*
Bars //Number of bars in the current chart
Digits//Number of digits after decimal point for the current symbol prices
Point //The current symbol point value in the quote currency
*/bool KPreVar::copyRates(int a_index=0,string a_sym=NULL,ENUM_TIMEFRAMES a_tf=PERIOD_CURRENT)
{
a_sym = (a_sym == NULL)? Symbol() : a_sym;
a_tf = (a_tf == PERIOD_CURRENT)? Period() : a_tf;
//ArraySetAsSeries(rates,true);int copied=CopyRates(a_sym,a_tf,a_index,1,m_rates);
bool ret=(copied>0)? true: false;
return ret;
}
bool KPreVar::copyTime(int a_index=0,string a_sym=NULL,ENUM_TIMEFRAMES a_tf=PERIOD_CURRENT)
{
a_sym = (a_sym == NULL)? Symbol() : a_sym;
a_tf = (a_tf == PERIOD_CURRENT)? Period() : a_tf;
//ArraySetAsSeries(rates,true);int copied=CopyTime(a_sym,a_tf,a_index,1,m_time);
bool ret=(copied>0)? true: false;
return ret;
}
bool KPreVar::copyTicks(string a_sym=NULL)
{
a_sym = (a_sym == NULL)? Symbol() : a_sym;
//ArraySetAsSeries(rates,true);int copied=CopyTicks(a_sym,m_ticks,COPY_TICKS_ALL);
bool ret=(copied>0)? true: false;
return ret;
}
although I tried to solve this problem by my own way but still want to learn how others get a MA price by the standard lib.
Maybe they use this function
Main
Returns the buffer element by the specified index.
double Main( intindex// index )
//+------------------------------------------------------------------+//| Access to buffer of "Moving Average" |//+------------------------------------------------------------------+double CiMA::Main(constint index) const
{
CIndicatorBuffer *buffer=At(0);
//--- checkif(buffer==NULL)
return(EMPTY_VALUE);
//---return(buffer.At(index));
}
//+------------------------------------------------------------------+//| Access to data in the specified position |//+------------------------------------------------------------------+double CArrayDouble::At(constint index) const
{
//--- checkif(index<0 || index>=m_data_total)
return(DBL_MAX);
//--- resultreturn(m_data[index]);
}
because the help file write it can Access to data.
but what I got is always like below. what's wrong? or where I can got a example code?
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
I start to learn mql5 today. It is a difficult for me . so I decided to write mql4 in mt5. and I start this project.
by these class I can use Ask Open and iMA as in mql4.
I tried to use standard library but failed to get iMA result.
CObject
CArray
CArrayObj
CSeries
CIndicator
CiMA
although I tried to solve this problem by my own way but still want to learn how others get a MA price by the standard lib.
Maybe they use this function
Main
Returns the buffer element by the specified index.
double Main(
int index // index
)
because the help file write it can Access to data.
but what I got is always like below. what's wrong? or where I can got a example code?
2018.04.08 23:19:03.833 test_Script (EURUSD,M30) 1.797693134862316e+308
In help file I got code like this . where I hope can find some example code write "//--- use element " OOh my Dog!!