-
Notifications
You must be signed in to change notification settings - Fork 11
/
TakeProfitStopLoss.mqh
161 lines (150 loc) · 5.42 KB
/
TakeProfitStopLoss.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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
//+------------------------------------------------------------------+
//| TakeProfitStopLoss.mqh |
//| Copyright 2020, khantanvir |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, khantanvir"
#property link "https://www.mql5.com"
#property strict
//+------------------------------------------------------------------+
//| defines |
//+------------------------------------------------------------------+
// #define MacrosHello "Hello, world!"
// #define MacrosYear 2010
//+------------------------------------------------------------------+
//| DLL imports |
//+------------------------------------------------------------------+
// #import "user32.dll"
// int SendMessageA(int hWnd,int Msg,int wParam,int lParam);
// #import "my_expert.dll"
// int ExpertRecalculate(int wParam,int lParam);
// #import
//+------------------------------------------------------------------+
//| EX5 imports |
//+------------------------------------------------------------------+
// #import "stdlib.ex5"
// string ErrorDescription(int error_code);
// #import
//+------------------------------------------------------------------+
double TPLong(string MySymbol, double LotSize, double ProfitTarget)
{
//---
string QuoteCurrency = StringSubstr(MySymbol, 3);
string BaseCurrency = StringSubstr(MySymbol, 0, 3);
double TP;
if(QuoteCurrency == "USD")
{
double TradingUSD = Ask;
TP = TradingUSD + 1 / (100000 * LotSize) * ProfitTarget;
}
else
if(BaseCurrency == "USD")
{
double TradingUSD = 1;
TP = (TradingUSD + 1 / (100000 * LotSize) * 1) * Ask;
}
else
{
double TradingUSD = MarketInfo("USD"+QuoteCurrency, MODE_ASK);
if(TradingUSD == 0)
{
TradingUSD = 1 / MarketInfo(QuoteCurrency+"USD", MODE_ASK);
}
TP = (Ask / TradingUSD + 1 / (100000 * LotSize) * ProfitTarget) * TradingUSD ;
}
return (TP);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double TPShort(string MySymbol, double LotSize, double ProfitTarget)
{
//---
string QuoteCurrency = StringSubstr(MySymbol, 3);
string BaseCurrency = StringSubstr(MySymbol, 0, 3);
double TP;
if(QuoteCurrency == "USD")
{
double TradingUSD = Bid;
TP = TradingUSD - 1 / (100000 * LotSize) * ProfitTarget;
}
else
if(BaseCurrency == "USD")
{
double TradingUSD = 1;
TP = (TradingUSD - 1 / (100000 * LotSize) * 1) * Bid;
}
else
{
double TradingUSD = MarketInfo("USD"+QuoteCurrency, MODE_BID);
if(TradingUSD == 0)
{
TradingUSD = 1 / MarketInfo(QuoteCurrency+"USD", MODE_BID);
}
TP = (Bid / TradingUSD - 1 / (100000 * LotSize) * ProfitTarget) * TradingUSD ;
}
return (TP);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double SLLong(string MySymbol, double LotSize, double StopLoss)
{
//---
string QuoteCurrency = StringSubstr(MySymbol, 3);
string BaseCurrency = StringSubstr(MySymbol, 0, 3);
double SL;
if(QuoteCurrency == "USD")
{
double TradingUSD = Ask;
SL = TradingUSD - 1 / (100000 * LotSize) * StopLoss;
}
else
if(BaseCurrency == "USD")
{
double TradingUSD = 1;
SL = (TradingUSD - 1 / (100000 * LotSize) * StopLoss) * Ask;
}
else
{
double TradingUSD = MarketInfo("USD"+QuoteCurrency, MODE_ASK);
if(TradingUSD == 0)
{
TradingUSD = 1 / MarketInfo(QuoteCurrency+"USD", MODE_ASK);
}
SL = (Ask / TradingUSD - 1 / (100000 * LotSize) * StopLoss) * TradingUSD ;
}
return (SL);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double SLShort(string MySymbol, double LotSize, double StopLoss)
{
//---
string QuoteCurrency = StringSubstr(MySymbol, 3);
string BaseCurrency = StringSubstr(MySymbol, 0, 3);
double SL;
if(QuoteCurrency == "USD")
{
double TradingUSD = Bid;
SL = TradingUSD + 1 / (100000 * LotSize) * StopLoss;
}
else
if(BaseCurrency == "USD")
{
double TradingUSD = 1;
SL = (TradingUSD + 1 / (100000 * LotSize) * StopLoss) * Bid;
}
else
{
double TradingUSD = MarketInfo("USD"+QuoteCurrency, MODE_BID);
if(TradingUSD == 0)
{
TradingUSD = 1 / MarketInfo(QuoteCurrency+"USD", MODE_BID);
}
SL = (Bid / TradingUSD + 1 / (100000 * LotSize) * StopLoss) * TradingUSD ;
}
return (SL);
}
//+------------------------------------------------------------------+