add spread support for price candle data

This commit is contained in:
Gunther Schulz
2020-02-16 22:17:37 +01:00
parent f27bc3d1d9
commit 1bad67048f
2 changed files with 15 additions and 3 deletions
+10 -2
View File
@@ -215,6 +215,7 @@ void StreamPriceData(){
datetime thisBar = 0; datetime thisBar = 0;
MqlTick tick; MqlTick tick;
MqlRates rates[1]; MqlRates rates[1];
int spread[1];
if( chartTF == "TICK"){ if( chartTF == "TICK"){
if(SymbolInfoTick(symbol,tick) !=true) { /*error processing */ }; if(SymbolInfoTick(symbol,tick) !=true) { /*error processing */ };
@@ -222,6 +223,7 @@ void StreamPriceData(){
} }
else { else {
if(CopyRates(symbol,period,1,1,rates)!=1) { /*error processing */ }; if(CopyRates(symbol,period,1,1,rates)!=1) { /*error processing */ };
if(CopySpread(symbol,period,1,1,spread)!=1) { /*error processing */ };
thisBar=(datetime)rates[0].time; thisBar=(datetime)rates[0].time;
} }
if(lastBar!=thisBar){ if(lastBar!=thisBar){
@@ -238,6 +240,7 @@ void StreamPriceData(){
Data[3] = (double) rates[0].low; Data[3] = (double) rates[0].low;
Data[4] = (double) rates[0].close; Data[4] = (double) rates[0].close;
Data[5] = (double) rates[0].tick_volume; Data[5] = (double) rates[0].tick_volume;
Data[6] = (int) spread[0];
} }
last["status"] = (string) "CONNECTED"; last["status"] = (string) "CONNECTED";
@@ -612,6 +615,7 @@ void HistoryInfo(CJAVal &dataObject){
CJAVal c, d; CJAVal c, d;
MqlRates r[]; MqlRates r[];
int spread[];
string fileName=symbol + "-" + chartTF + ".csv"; // file name string fileName=symbol + "-" + chartTF + ".csv"; // file name
string directoryName="Data"; // directory name string directoryName="Data"; // directory name
string outputFile=directoryName+"//"+fileName; string outputFile=directoryName+"//"+fileName;
@@ -629,6 +633,7 @@ void HistoryInfo(CJAVal &dataObject){
if(dataObject["toDate"].ToInt()!=NULL)Print("4) Date to:"+TimeToString(toDate)); if(dataObject["toDate"].ToInt()!=NULL)Print("4) Date to:"+TimeToString(toDate));
barCount=CopyRates(symbol,period,fromDate,toDate,r); barCount=CopyRates(symbol,period,fromDate,toDate,r);
if(CopySpread(symbol,period, fromDate, toDate, spread)!=1) { /*error processing */ }
if(barCount){ if(barCount){
ActionDoneOrError(ERR_SUCCESS, __FUNCTION__); ActionDoneOrError(ERR_SUCCESS, __FUNCTION__);
@@ -642,7 +647,7 @@ void HistoryInfo(CJAVal &dataObject){
PrintFormat("File path: %s\\Files\\",TerminalInfoString(TERMINAL_DATA_PATH)); PrintFormat("File path: %s\\Files\\",TerminalInfoString(TERMINAL_DATA_PATH));
//--- write the time and values of signals to the file //--- write the time and values of signals to the file
for(int i=0;i<barCount;i++) for(int i=0;i<barCount;i++)
FileWrite(file_handle,r[i].time, ",", r[i].open, ",", r[i].high, ",", r[i].low, ",", r[i].close, ",", r[i].tick_volume); FileWrite(file_handle,r[i].time, ",", r[i].open, ",", r[i].high, ",", r[i].low, ",", r[i].close, ",", r[i].tick_volume, spread[i]);
//--- close the file //--- close the file
FileClose(file_handle); FileClose(file_handle);
PrintFormat("Data is written, %s file is closed", outputFile); PrintFormat("Data is written, %s file is closed", outputFile);
@@ -698,7 +703,7 @@ void HistoryInfo(CJAVal &dataObject){
CJAVal c, d; CJAVal c, d;
MqlRates r[]; MqlRates r[];
int spread[];
int barCount=0; int barCount=0;
ENUM_TIMEFRAMES period=GetTimeframe(chartTF); ENUM_TIMEFRAMES period=GetTimeframe(chartTF);
datetime fromDate=(datetime)dataObject["fromDate"].ToInt(); datetime fromDate=(datetime)dataObject["fromDate"].ToInt();
@@ -714,6 +719,8 @@ void HistoryInfo(CJAVal &dataObject){
} }
barCount=CopyRates(symbol, period, fromDate, toDate, r); barCount=CopyRates(symbol, period, fromDate, toDate, r);
if(CopySpread(symbol,period, fromDate, toDate, spread)!=1) { /*error processing */ }
if(barCount){ if(barCount){
for(int i=0;i<barCount;i++){ for(int i=0;i<barCount;i++){
c[i][0]=(long) r[i].time; c[i][0]=(long) r[i].time;
@@ -722,6 +729,7 @@ void HistoryInfo(CJAVal &dataObject){
c[i][3]=(double) r[i].low; c[i][3]=(double) r[i].low;
c[i][4]=(double) r[i].close; c[i][4]=(double) r[i].close;
c[i][5]=(double) r[i].tick_volume; c[i][5]=(double) r[i].tick_volume;
c[i][6]=(int) spread[i];
} }
d["data"].Set(c); d["data"].Set(c);
} }
+4
View File
@@ -1,3 +1,7 @@
### 16th February 2020
- add support for candle ask/bid price spread
### 11th January 2020 ### 11th January 2020
- add support for multiple datastreams in parallel for any combination of symbols and timeframes independently of the timeframe and symbol of the attached chart - add support for multiple datastreams in parallel for any combination of symbols and timeframes independently of the timeframe and symbol of the attached chart