Quote:
|
Originally Posted by yocy1
i would like to write a code for a hedge strategy in one currency and stop open when, for example, buy OP are more then sell OP, so i need to write something like, "if totalorder of OP_BUY > totalorders of OP_SELL" any idea?
|
Code:
int BuyCnt = 0;
int SellCnt = 0;
int BuyStopCnt = 0;
int SellStopCnt = 0;
int BuyLimitCnt = 0;
int SellLimitCnt = 0;
int cnt = OrdersTotal();
for (int i=0; i < cnt; i++)
{
if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
//if (OrderSymbol() != Symbol()) continue;
//if (OrderMagicNumber() != Magic) continue;
int type = OrderType();
if (type == OP_BUY) BuyCnt++;
if (type == OP_SELL) SellCnt++;
if (type == OP_BUYSTOP) BuyStopCnt++;
if (type == OP_SELLSTOP) SellStopCnt++;
if (type == OP_BUYLIMIT) BuyLimitCnt++;
if (type == OP_SELLLIMIT) SellLimitCnt++;
}