This repository has been archived by the owner on Sep 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFanna.mq4
119 lines (108 loc) · 7.65 KB
/
Fanna.mq4
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//——————————CONSTANTS—————————//
const int HINDSIGHT = 48;
const int COOLDOWN = 10000;
const long LEARNING_INTERVAL = 24 * 60 * 60;
const double LOT_SHARE = 0.1;
const double OFFSET = 0.002;
//———————GLOBAL VARIABLES—————//
static datetime g_time_last_learned = 0;
//————————————————————————————//
#property show_inputs
#property strict
enum fanna_instruction_enum {
NONE,
BUILD_DATABASE,
RESET,
TRAIN,
TRADE
};
input fanna_instruction_enum FANNA_INSTRUCTION = NONE;
#define PI double offset, int hindsight, int length, char &pair[], char &interval[], const double &opening_price[], const double &closing_price[], const double &max_price[], const double &min_price[], double &volume[]
#define PIARGS OFFSET, HINDSIGHT, length, pair, interval, opening_price, closing_price, max_price, min_price, volume
#import "Fanna.dll"
int reset_fanna(PI);
int train_fanna(PI);
int build_fanna_database(PI);
double pulse_fanna(PI);
#import
void OnTick(){
if(FANNA_INSTRUCTION == TRADE && OrdersTotal() == 0){
int length = Bars;
double opening_price[], closing_price[], max_price[], min_price[], volume[];
ArrayResize(opening_price, Bars);
ArrayResize(closing_price, Bars);
ArrayResize(max_price, Bars);
ArrayResize(min_price, Bars);
ArrayResize(volume, Bars);
char pair[], interval[];
StringToCharArray(Symbol(), pair);
StringToCharArray(IntegerToString(Period()), interval);
for(int i = 0; i < Bars; ++i){
opening_price[i] = double(Open[i]);
closing_price[i] = double(Close[i]);
max_price[i] = double(High[i]);
min_price[i] = double(Low[i]);
volume[i] = double(Volume[i]);
}
if(TimeCurrent() - g_time_last_learned >= LEARNING_INTERVAL){
build_fanna_database(PIARGS);
train_fanna(PIARGS);
g_time_last_learned = TimeCurrent();
}
double available_lots = (AccountEquity() * AccountLeverage()) / MarketInfo(Symbol(), MODE_LOTSIZE);
double sentiment = pulse_fanna(PIARGS);
PrintFormat("Fanna sentiment: %lf", sentiment);
if(sentiment > 0.75){
// —————————————————————————————Buy———————————————————————————
double
SL = Ask - OFFSET,
TP = Ask + OFFSET;
int buy_order = OrderSend(Symbol(), OP_BUY, available_lots * LOT_SHARE ,Ask , 3, SL, TP, "Buy" ,16384 ,0 ,clrGreen);
}
else if(sentiment < 0.25){
// —————————————————————————————Sell——————————————————————————
double
SL = Bid + OFFSET,
TP = Bid - OFFSET;
int sell_order = OrderSend(Symbol(), OP_SELL, available_lots * LOT_SHARE ,Bid , 3, SL, TP, "Sell" ,16384 ,0 ,clrRed);
}
}
}
int OnInit(){
if(FANNA_INSTRUCTION == NONE){
ExpertRemove();
return(INIT_SUCCEEDED);
}
int length = Bars;
double opening_price[], closing_price[], max_price[], min_price[], volume[];
ArrayResize(opening_price, Bars);
ArrayResize(closing_price, Bars);
ArrayResize(max_price, Bars);
ArrayResize(min_price, Bars);
ArrayResize(volume, Bars);
char pair[], interval[];
StringToCharArray(Symbol(), pair);
StringToCharArray(IntegerToString(Period()), interval);
for(int i = 0; i < Bars; ++i){
opening_price[i] = double(Open[i]);
closing_price[i] = double(Close[i]);
max_price[i] = double(High[i]);
min_price[i] = double(Low[i]);
volume[i] = double(Volume[i]);
}
switch(FANNA_INSTRUCTION){
case BUILD_DATABASE:
build_fanna_database(PIARGS);
ExpertRemove();
break;
case RESET:
reset_fanna(PIARGS);
ExpertRemove();
break;
case TRAIN:
train_fanna(PIARGS);
ExpertRemove();
break;
}
return(INIT_SUCCEEDED);
}