forked from vzhomeexperiments/Include
-
Notifications
You must be signed in to change notification settings - Fork 0
/
12_ReadPredictionFromAI.mqh
64 lines (53 loc) · 2.56 KB
/
12_ReadPredictionFromAI.mqh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//+-------------------------------------------------------------------+
//| 12_ReadPredictionFromAI.mqh |
//| Copyright 2018, Vladimir Zhbanko |
//+-------------------------------------------------------------------+
#property copyright "Copyright 2018, Vladimir Zhbanko"
#property link "https://vladdsm.github.io/myblog_attempt/"
#property version "1.001"
#property strict
// function to recieve direction from csv file
// version 1.001 date 05.05.2018
#define TRADE_NONE 0 //Market not siutable for trading e.g. macroeconomic event or not properly defined
#define TRADE_BU 1 //Predicted bull
#define TRADE_BE 2 //Predicted bear
//+-------------------------------------------------------------+//
//Function requires input of the symbol
//+-------------------------------------------------------------+//
/*
User guide:
1. Add global bool variable to EA: e.g.: int MyMarketType;
2. Add function call inside start function to EA: e.g.: MyMarketType = ReadMarketFromCSV(Symbol());
3. Adapt Trading Robot conditions to change trading strategy parameters eg.: see Falcon_C
4. Add include call to this file to EAe.g.: #include <096_ReadMarketTypeFromCSV.mqh>
*/
int ReadPredictionFromAI(string symbol, int chart_period)
{
/*
- Function reads the file eg: AI_M15_DirectionAUDCAD.csv
- It is searching either numeric code or string value containing market type information
*/
//define internal variables needed
int direction = -1; //Variable to store and return the market type
string res = "0"; //Variable to return result of the function
//Read the file
res = ReadFile2(symbol, chart_period);
//Assign market variable based on result
if(res == "-1"){direction = TRADE_NONE; return(direction); }
if(res == "BU"){direction = TRADE_BU; return(direction); }
if(res == "BE"){direction = TRADE_BE; return(direction); }
return(direction); //in anomalous case function will return error '-1'
}
//function that read file from sandbox and get the last character
string ReadFile2(string symbol, int chart_period)
{
int handle;
string str;
handle=FileOpen("AI_M"+IntegerToString(chart_period)+"_Direction"+symbol+".csv",FILE_READ);
if(handle==-1){Comment("Error - file does not exist"); str = "-1"; }
if(FileSize(handle)==0){FileClose(handle); Comment("Error - File is empty"); }
//this will bring the last element
while(!FileIsEnding(handle)) { str=FileReadString(handle); }
FileClose(handle);
return(str);
}