求一段EA源代码,计算持仓同类品种的浮动盈亏
Haihua Luo:
请MT4编程达人指点,帮忙写一段代码。在持仓多个不同货币对不同方向单子的情况下,单独计算出某一货币对所有多单(或空单)累加的浮动盈亏金额,待调用。谢谢。
//+------------------------------------------------------------------+ //| test.mq4 | //| Copyright 2016, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2016, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict input int MagicNumber = 888; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- // 比如当前品种的多单 double profit = 0.0; profit = CalcProfit(Symbol(),OP_BUY,MagicNumber); // 比如当前品种的多单 } //+------------------------------------------------------------------+ double CalcProfit(const string sym,const int ordertype,const int magic) { double sum = 0.0; for(int i=OrdersTotal()-1;i>=0;i--){ if(OrderSelect(i,SELECT_BY_POS)){ if(OrderMagicNumber()==magic&&OrderSymbol()==sym&&OrderType()==ordertype){ sum+=OrderProfit()+OrderCommission()+OrderSwap(); } } } return(sum); }
Ziheng Zhuang:
受教了,谢谢good
请MT4编程达人指点,帮忙写一段代码。在持仓多个不同货币对不同方向单子的情况下,单独计算出某一货币对所有多单(或空单)累加的浮动盈亏金额,待调用。谢谢。