How to map trade server symbol names to user symbol names

 

How can I get my code to implement the symbol map from input while getting signals from telegram. I want the broker's suffixes to not be an issue.

This snippets tries to get the map ready from input during initialization.

void init_filters()
{
    string pair[];
    StringSplitTrim(tradables,",", pair);
    for(int i=0; i<ArraySize(pair); i++)
    {
        string symbol=Instrument(FindW(pair[i]), pair[i]);
        if(symbol!="") tradable_pairs+=" , " + symbol;
    }
    StringSplitTrim(untradables,",", pair);
    for(int i=0; i<ArraySize(pair); i++)
    {
        string symbol=Instrument(FindW(pair[i]), pair[i]);
        if(symbol!="") non_tradable_pairs+=" , " + symbol;
    }
    //Symbol mapping.
    StringSplitTrim(symbol_map,",", pair);
    for(int i=0; i<ArraySize(pair); i++)
    {
        string symbol=Instrument(FindW(pair[i]), pair[i]);
        if(symbol!="")
        {
            int key_index=ArraySize(pair_key);
            ArrayResize(pair_key, key_index+1);
            int attribute_index=ArraySize(pair_attribute);
            ArrayResize(pair_attribute, attribute_index+1);
            pair_key[key_index]=symbol;
            pair_attribute[attribute_index]=pair[i];
        }
    }
    //
}

Then here tries to replace texts for easy reading and processing of signal parameters.

    ...
    int m=ArraySize(pair_key);
    while(--m>=0) 
    {
        string attributes[];
        StringSplitTrim(pair_attribute[m],"-",attributes);
        ReplaceFromList(msg, attributes,pair_key[m]);
    }
    
//--
    
    msg = StringReplace2(msg,"  "," ");
    //bot.SendMessage(bot.user_chat,msg);
    return msg;
}

string ReplaceFromList(string msg, string &list[], string replacement)
{
    int items = ArraySize(list);
    for(int i=0; i<items; i++)
    {
        msg = StringReplace2(msg,StringTrim(list[i]),replacement);
    }
    return msg;
}

The rest of the code is attached here.

 
Chukwudozie Thankgod:

How can I get my code to implement the symbol map from input while getting signals from telegram. I want the broker's suffixes to not be an issue.

This snippets tries to get the map ready from input during initialization.

Then here tries to replace texts for easy reading and processing of signal parameters.

The rest of the code is attached here.

Assuming that both you and the signal provider are trading forex or CFD's and you want to remove the suffixes of the provider:

StringSubstr("provider's symbol", 0, 6);

This turns EURUSD-FX into EURUSD.

Documentation on MQL5: String Functions / StringSubstr
Documentation on MQL5: String Functions / StringSubstr
  • www.mql5.com
Extracts a substring from a text string starting from the specified position. Parameters string_value [in]  String to extract a substring from...
 
Ryan L Johnson #:

Assuming that both you and the signal provider are trading forex or CFD's and you want to remove the suffixes of the provider:

This turns EURUSD-FX into EURUSD.

Yeah but consider a case where a signal provider issues a trade call on cable (gbpusd) or uses some other names on it. I need to make sure the provider's symbol name gets replaced by it's real name as indicated on input. E.g 
Cable - gbpusd, bitcoin - btcusd : from input
Gets formatted as symbol: GBPUSDmicro alternative names: cable, gbpusd.
Then goes on to replace the alternative names if found in signal with the real broker symbol name.
 
Chukwudozie Thankgod #:
Yeah but consider a case where a signal provider issues a trade call on cable (gbpusd) or uses some other names on it. I need to make sure the provider's symbol name gets replaced by it's real name as indicated on input. E.g 
Cable - gbpusd, bitcoin - btcusd : from input
Gets formatted as symbol: GBPUSDmicro alternative names: cable, gbpusd.
Then goes on to replace the alternative names if found in signal with the real broker symbol name.
Symbol details allow some fuzzy search to match symbol names.

In FX you could use the margin and profit currency to make an educated guess on matching names. Try using these to build a symbol name which you now can try to match with the user input.

For names like cable or kiwi you will need some internal list for matching.
 
Chukwudozie Thankgod:

How can I get my code to implement the symbol map from input while getting signals from telegram. I want the broker's suffixes to not be an issue.

This snippets tries to get the map ready from input during initialization.

Then here tries to replace texts for easy reading and processing of signal parameters.

The rest of the code is attached here.

During initialization, loop through all broker symbols using SymbolsTotal() and SymbolName() , and match the base names like 'EURUSD' by checking if StringFind(full, clean) == 0 . This way, you can automatically map real symbols with suffixes