SortedByValue
- 程序库
- Xiaoyu Huang
- 版本: 1.7
- 更新: 7 五月 2023
- 激活: 20
这个库用于key 和 value 数组进行排序, 我们常常需要对值进行排序。
像python语言里面的
sorted(key_value.items(), key = lambda kv:(kv[1], kv[0]))
导入函数
#import "SortedByValue.ex5" bool SortedByDouble(long &key[],double &value[]); bool SortedByDouble(string &key[],double &value[]); bool SortedByInteger(long &key[],long &value[]); bool SortedByInteger(string &key[],long &value[]); bool SortedByDateTime(long &key[],datetime &value[]); bool SortedByDateTime(string &key[],datetime &value[]); #import
使用场景例子
1.网格EA订单根据开仓价格排序
void SortedByOpenPride() { long OrderTicketBuffer[]; double OpenPriceBuffer[]; for(int i = 0; i<=PositionsTotal(); i++) { if(m_position.SelectByIndex(i)) { OrderTicketBuffer[i] = ulong(m_position.Ticket()); OpenPriceBuffer[i] = m_position.PriceOpen(); } } SortedByDouble(OrderTicketBuffer,OpenPriceBuffer); }
最上层订单的ticket为OrderTicketBuffer[ArraySize(OrderTicketBuffer)-1];
最下层订单的ticket为OrderTicketBuffer[0];
2. 货币强弱排序
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);
最强的货币为key[4],“GBP”
最弱的货币为key[0], “JPY”