|
@@ -23,28 +23,6 @@ struct msgDetails
|
|
|
|
|
|
|
|
msgDetails od[MaxOrders];
|
|
msgDetails od[MaxOrders];
|
|
|
|
|
|
|
|
-struct new_trade_store
|
|
|
|
|
- {
|
|
|
|
|
- ulong ticket; // Ticket
|
|
|
|
|
- int order_type; // OrderType
|
|
|
|
|
- double lot; // Lot
|
|
|
|
|
- double stop_loss; // StopLoss
|
|
|
|
|
- double take_profit; // TakeProfit
|
|
|
|
|
- double price; // Price
|
|
|
|
|
- string symbol; // Symbol
|
|
|
|
|
- int chatId; // ChatId
|
|
|
|
|
- string trade_type; // Trade Type (Trade Type: Tp1, Tp2, Tp3.... Tpn)
|
|
|
|
|
-
|
|
|
|
|
- new_trade_store()
|
|
|
|
|
- {
|
|
|
|
|
- ticket = -1;
|
|
|
|
|
- chatId=-1;
|
|
|
|
|
- trade_type = "";
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- };
|
|
|
|
|
-new_trade_store newTradeStore[MaxOrders];
|
|
|
|
|
-
|
|
|
|
|
input string Settings = " ------------- General Settings ------------- "; //_
|
|
input string Settings = " ------------- General Settings ------------- "; //_
|
|
|
input int magic_no = 333; // Magic no
|
|
input int magic_no = 333; // Magic no
|
|
|
input string symbolMatch = "GOLD:XAUUSD,BitCoin:BTCUSD"; // Symbol Mapping (Telegram:MT5)
|
|
input string symbolMatch = "GOLD:XAUUSD,BitCoin:BTCUSD"; // Symbol Mapping (Telegram:MT5)
|
|
@@ -59,20 +37,15 @@ input double lotSize = 0.1;
|
|
|
string url1 = "http://127.0.0.1";
|
|
string url1 = "http://127.0.0.1";
|
|
|
string header = "Content-Type: application/json\r\nAccept: application/json\r\n";
|
|
string header = "Content-Type: application/json\r\nAccept: application/json\r\n";
|
|
|
|
|
|
|
|
-int getme_result;
|
|
|
|
|
-
|
|
|
|
|
string symbolChart[];
|
|
string symbolChart[];
|
|
|
string symbolSnd[];
|
|
string symbolSnd[];
|
|
|
string symbolsListUserInput[];
|
|
string symbolsListUserInput[];
|
|
|
uchar sym1[];
|
|
uchar sym1[];
|
|
|
uchar sym2[];
|
|
uchar sym2[];
|
|
|
-datetime ea_start_time = 0;
|
|
|
|
|
int last_message_id = INT_MIN;
|
|
int last_message_id = INT_MIN;
|
|
|
int OnInit()
|
|
int OnInit()
|
|
|
{
|
|
{
|
|
|
//--- create timer
|
|
//--- create timer
|
|
|
- ea_start_time = TimeCurrent();
|
|
|
|
|
-
|
|
|
|
|
ushort u_sep = StringGetCharacter(",",0);
|
|
ushort u_sep = StringGetCharacter(",",0);
|
|
|
StringSplit(symbolMatch,u_sep,symbolsListUserInput);
|
|
StringSplit(symbolMatch,u_sep,symbolsListUserInput);
|
|
|
ArrayResize(symbolChart,0);
|
|
ArrayResize(symbolChart,0);
|
|
@@ -218,31 +191,6 @@ string GET_function(string url,string headers)
|
|
|
//+------------------------------------------------------------------+
|
|
//+------------------------------------------------------------------+
|
|
|
//| |
|
|
//| |
|
|
|
//+------------------------------------------------------------------+
|
|
//+------------------------------------------------------------------+
|
|
|
-void seperatingDataOnint(int index, string data)
|
|
|
|
|
- {
|
|
|
|
|
-
|
|
|
|
|
- string message = getJsonStringValue(data,"message",4,"\"");
|
|
|
|
|
- int message_id = (int)getJsonStringValue(data,"message_id",4,"\"");
|
|
|
|
|
-
|
|
|
|
|
- if(checkExistingTrade(message_id) == false)
|
|
|
|
|
- {
|
|
|
|
|
- Print(" ================ OnInit New Trade Message Found ================");
|
|
|
|
|
- StringReplace(message,"~","#");
|
|
|
|
|
- StringToLower(message);
|
|
|
|
|
- Print("Message is ", message);
|
|
|
|
|
- for(int i=0; i < MaxOrders; i++)
|
|
|
|
|
- {
|
|
|
|
|
- if(od[i].msgid == -1)
|
|
|
|
|
- {
|
|
|
|
|
- od[i].msgid = message_id;
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-//+------------------------------------------------------------------+
|
|
|
|
|
-//| |
|
|
|
|
|
-//+------------------------------------------------------------------+
|
|
|
|
|
bool checkExistingTrade(int message_id)
|
|
bool checkExistingTrade(int message_id)
|
|
|
{
|
|
{
|
|
|
for(int i=0; i < MaxOrders; i++)
|
|
for(int i=0; i < MaxOrders; i++)
|
|
@@ -302,73 +250,6 @@ string trim(string text)
|
|
|
//+------------------------------------------------------------------+
|
|
//+------------------------------------------------------------------+
|
|
|
//| |
|
|
//| |
|
|
|
//+------------------------------------------------------------------+
|
|
//+------------------------------------------------------------------+
|
|
|
-void seperatingData(int index, string data)
|
|
|
|
|
- {
|
|
|
|
|
-// Print(" Data: ", data);
|
|
|
|
|
- string message = getJsonStringValue(data,"message",4,"\"");
|
|
|
|
|
- int message_id = (int)getJsonStringValue(data,"message_id",4,"\"");
|
|
|
|
|
-
|
|
|
|
|
- string isReplyValue = getJsonStringValue(data,"is_reply",4,"\"");
|
|
|
|
|
- int reply_to_msg_id = (int)getJsonStringValue(data,"reply_to_msg_id",4,"\"");
|
|
|
|
|
-
|
|
|
|
|
- if(isReplyValue == "False")
|
|
|
|
|
- {
|
|
|
|
|
- if(checkExistingTrade(message_id) == false)
|
|
|
|
|
- {
|
|
|
|
|
- Print(" --------------- New Trade Message Found ----------------- ", " Message Id: ", message_id);
|
|
|
|
|
- StringReplace(message,"~","#");
|
|
|
|
|
- StringReplace(message,"##", "#");
|
|
|
|
|
- StringToLower(message);
|
|
|
|
|
- message = removeExtraSpaces(message);
|
|
|
|
|
- Print("Message is ",message);
|
|
|
|
|
- addtoMessageStructure(message_id,message);
|
|
|
|
|
-
|
|
|
|
|
- string result[];
|
|
|
|
|
- string tempResult[];
|
|
|
|
|
- int indexTemp = 0;
|
|
|
|
|
-
|
|
|
|
|
- StringSplit(message,'#',tempResult);
|
|
|
|
|
-
|
|
|
|
|
- for(int i=0; i<ArraySize(tempResult); i++)
|
|
|
|
|
- {
|
|
|
|
|
- //result[i] = StringTrimLeft(result[i]);
|
|
|
|
|
- //result[i] = StringTrimRight(result[i]);
|
|
|
|
|
- //Print("Temp Result : ", tempResult[i], " index is: ", i);
|
|
|
|
|
- if(HasAlphanumeric(tempResult[i]))
|
|
|
|
|
- {
|
|
|
|
|
- //Print(" contains alphanumeric characters.");
|
|
|
|
|
- ArrayResize(result,ArraySize(result)+1);
|
|
|
|
|
- result[indexTemp] = tempResult[i];
|
|
|
|
|
- indexTemp++;
|
|
|
|
|
- }
|
|
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
- //Print(" does not contain alphanumeric characters.");
|
|
|
|
|
- //ArrayResize(indexToDelete,ArraySize(indexToDelete)+1);
|
|
|
|
|
- //indexToDelete[indexTemp] = i;
|
|
|
|
|
- //indexTemp++;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- message(result,message,message_id);
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if(isReplyValue == "True")
|
|
|
|
|
- {
|
|
|
|
|
- if(checkExistingTrade(message_id) == false)
|
|
|
|
|
- {
|
|
|
|
|
- Print(" --------------- New Replied Message Found ----------------- ", " Message Id: ", message_id, " Reply Message Id: ", reply_to_msg_id);
|
|
|
|
|
- StringToLower(message);
|
|
|
|
|
- Print("Message is ",message);
|
|
|
|
|
- addtoMessageStructure(message_id,message);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-//+------------------------------------------------------------------+
|
|
|
|
|
-//| |
|
|
|
|
|
-//+------------------------------------------------------------------+
|
|
|
|
|
void execute_functionality_on_new_message(int i)
|
|
void execute_functionality_on_new_message(int i)
|
|
|
{
|
|
{
|
|
|
|
|
|
|
@@ -500,8 +381,7 @@ void message(string &result[], string message, int message_id)
|
|
|
symbol = symbolMapping(symbol);
|
|
symbol = symbolMapping(symbol);
|
|
|
|
|
|
|
|
double sl = 0;
|
|
double sl = 0;
|
|
|
- double tpStore[]; // = result[0];
|
|
|
|
|
- int tpIndex = 0;
|
|
|
|
|
|
|
+ double tp = 0; // = result[0];
|
|
|
for(int i=0 ; i < ArraySize(result); i++)
|
|
for(int i=0 ; i < ArraySize(result); i++)
|
|
|
{
|
|
{
|
|
|
// result[i] = StringTrimLeft(result[i]);
|
|
// result[i] = StringTrimLeft(result[i]);
|
|
@@ -512,7 +392,7 @@ void message(string &result[], string message, int message_id)
|
|
|
string tempSl[];
|
|
string tempSl[];
|
|
|
result[i] = trimString(result[i]);
|
|
result[i] = trimString(result[i]);
|
|
|
//Print(" Sl String: ", result[i]);
|
|
//Print(" Sl String: ", result[i]);
|
|
|
- StringSplit(result[i], ' ', tempSl);
|
|
|
|
|
|
|
+ StringSplit(result[i], ':', tempSl);
|
|
|
if(ArraySize(tempSl) >= 2)
|
|
if(ArraySize(tempSl) >= 2)
|
|
|
sl = (double) tempSl[1];
|
|
sl = (double) tempSl[1];
|
|
|
Print("Sl : ", sl);
|
|
Print("Sl : ", sl);
|
|
@@ -522,31 +402,24 @@ void message(string &result[], string message, int message_id)
|
|
|
// Print("Tp : ", result[i], " index is: ", i);
|
|
// Print("Tp : ", result[i], " index is: ", i);
|
|
|
string tempTp[];
|
|
string tempTp[];
|
|
|
result[i] = trimString(result[i]);
|
|
result[i] = trimString(result[i]);
|
|
|
- StringSplit(result[i], ' ', tempTp);
|
|
|
|
|
|
|
+ StringSplit(result[i], ':', tempTp);
|
|
|
//double tp = (double) tempTp[1];
|
|
//double tp = (double) tempTp[1];
|
|
|
-
|
|
|
|
|
- ArrayResize(tpStore,ArraySize(tpStore)+1);
|
|
|
|
|
if(ArraySize(tempTp) >= 2)
|
|
if(ArraySize(tempTp) >= 2)
|
|
|
- tpStore[tpIndex] = (double) tempTp[1];
|
|
|
|
|
- Print("Tp : ", tpStore[tpIndex]);
|
|
|
|
|
- tpIndex++;
|
|
|
|
|
|
|
+ tp = (double) tempTp[1];
|
|
|
|
|
+ Print("Tp : ", tp);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- Print("Side:", direction, " Symbol: ", symbol, " Tp Array Size: ", ArraySize(tpStore), " Message Id: ", message_id);
|
|
|
|
|
- for(int i = 0 ; i < ArraySize(tpStore) ; i++)
|
|
|
|
|
- {
|
|
|
|
|
- Print("Side:", direction, " Symbol: ", symbol, " Tp: ", tpStore[i], " Sl: ", sl, " Message Id: ", message_id);
|
|
|
|
|
- if(direction == buy)
|
|
|
|
|
- {
|
|
|
|
|
- placeBuyTrade(symbol, tpStore[i], sl, message_id, lotSize);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ Print("Side:", direction, " Symbol: ", symbol, " Tp: ", tp, " Sl: ", sl, " Message Id: ", message_id);
|
|
|
|
|
|
|
|
- if(direction == sell)
|
|
|
|
|
- {
|
|
|
|
|
- placeSellTrade(symbol, tpStore[i], sl, message_id, lotSize);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if(direction == buy)
|
|
|
|
|
+ {
|
|
|
|
|
+ placeBuyTrade(symbol, tp, sl, message_id, lotSize);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if(direction == sell)
|
|
|
|
|
+ {
|
|
|
|
|
+ placeSellTrade(symbol, tp, sl, message_id, lotSize);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|