SortedByValue
- Libraries
- Xiaoyu Huang
- Version: 1.7
- Updated: 7 May 2023
- Activations: 20
This library is used for sorting key and value arrays, we often need to sort values.
like in the python language
sorted(key_value.items(), key = lambda kv:(kv[1], kv[0]))
import function
Example of usage scenarios
1. Grid EA orders are sorted according to the opening price
void SortedByOpenPride() { long OrderTicketBuffer[]; double OpenPriceBuffer[]; for(int i = PositionsTotal()-1; i>=0; i--) { if(m_position.SelectByIndex(i)) { OrderTicketBuffer[i] = long(m_position.Ticket()); OpenPriceBuffer[i] = m_position.PriceOpen(); } } SortedByDouble(OrderTicketBuffer,OpenPriceBuffer); }
The ticket of the top order is OrderTicketBuffer[ArraySize(OrderTicketBuffer)-1];
The ticket of the bottom order is OrderTicketBuffer[0];
2. Sort by currency strength
string key[5]; double value[5]; key[0] = "USD"; key[1] = "EUR"; key[2] = "GBP"; key[3] = "AUD"; key[4] = "JPY"; value[0] = 1.2; value[1] = 2.5; value[2] = 3.3; value[3] = 1.1; value[4] = 0.8; SortedByDouble(key,value);
The strongest currency is key[4], "GBP"
The weakest currency is key[0], "JPY"