-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTradersPostExample.mq5
66 lines (53 loc) · 2.44 KB
/
TradersPostExample.mq5
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
//+------------------------------------------------------------------+
//| TradersPostExample.mq5 |
//| TradersPost, Inc |
//| https://traderspost.io |
//+------------------------------------------------------------------+
#property copyright "TradersPost, Inc"
#property link "https://traderspost.io"
#property version "1.00"
#property strict
#include <TradersPostWebhookRequest.mqh>
input string Webhook_URL = "https://webhooks.traderspost.io/trading/webhook/...";
TradersPostWebhookRequest webhookRequest(Webhook_URL);
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit() {
Print("TradersPost Example EA initialized.");
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick() {
static bool orderSent = false;
if (!orderSent) {
// include the built-in JSON serializer
TPJSON json;
// Build your properties according to the webhook documentation: https://docs.traderspost.io/docs/core-concepts/webhooks#request-body
// The ticker is hard-coded here because StoneX futures tickers do not match TradersPost futures tickers.
json["ticker"] = "NQZ2024";
json["action"] = "buy";
json["quantity"] = 1;
// Add take profit and stop loss
json["takeProfit"]["percent"] = 5.0;
json["stopLoss"]["percent"] = 2.5;
// Convert JSON object to string
string jsonPayload = json.Serialize();
// Send the serialized JSON request
bool result = webhookRequest.SendRequest(jsonPayload);
if (result) {
Print("Buy order sent for NQZ2024.");
orderSent = true; // Only send once
} else {
Print("Failed to send the buy order.");
orderSent = true;
}
}
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason) {
}