Hello, I need a little help here..
How can I edit this code so it will check my today profit on every bar. At the moment this code only trigger is there is an order closed. Appreciate any help..
Thanks
//+------------------------------------------------------------------+
//| Close Condition Type 9C |
//| CHECK ACCOUNT BALANCE then close biggest price different |
//| |
//| select the biggest price different order > current price |
//| if TODAY PROFIT/LOSS (at ACCOUNT HISTORY/AccountProfit) |
//| is bigger > Profit2ExitTodayBalance |
//| then |
//| CLOSE ORDER LOT = PartialCloseLot |
//+------------------------------------------------------------------+
void CheckCloseConditionType9c()
{
int ticket1;
double max_dist;
for (;
{
ticket1 = -1;
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 || type == OP_SELL) == false) continue;
RefreshRates();
if (ticket1 == -1 || MathAbs(Bid - OrderOpenPrice()) > max_dist)
{
ticket1 = OrderTicket();
max_dist = MathAbs(Bid - OrderOpenPrice());
}
}
if (ticket1 == -1) break;
if (BuyCnt+SellCnt <= 1) break; //DO NOT PROCEED IF TOTAL OPEN ORDER IS LESS THAN
//-----
double today_hist_profit = GetTodayProfit(MODE_HISTORY);
if (today_hist_profit <= Profit2ExitTodayBalance) break;
if (OrderSelect(ticket1, SELECT_BY_TICKET))
{
double lot = PartialCloseLot;
if (lot > OrderLots()) lot = OrderLots();
for (i=0; i < RepeatN; i++)
{
RefreshRates();
bool res = OrderClose(OrderTicket(), lot, OrderClosePrice(), Slippage, clClose);
Comment("Order close by Condition type 9c");
Print("Order close by Condition type 9c");
if (res) break;
}
}
}
}
How can I edit this code so it will check my today profit on every bar. At the moment this code only trigger is there is an order closed. Appreciate any help..
Thanks
//+------------------------------------------------------------------+
//| Close Condition Type 9C |
//| CHECK ACCOUNT BALANCE then close biggest price different |
//| |
//| select the biggest price different order > current price |
//| if TODAY PROFIT/LOSS (at ACCOUNT HISTORY/AccountProfit) |
//| is bigger > Profit2ExitTodayBalance |
//| then |
//| CLOSE ORDER LOT = PartialCloseLot |
//+------------------------------------------------------------------+
void CheckCloseConditionType9c()
{
int ticket1;
double max_dist;
for (;
{
ticket1 = -1;
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 || type == OP_SELL) == false) continue;
RefreshRates();
if (ticket1 == -1 || MathAbs(Bid - OrderOpenPrice()) > max_dist)
{
ticket1 = OrderTicket();
max_dist = MathAbs(Bid - OrderOpenPrice());
}
}
if (ticket1 == -1) break;
if (BuyCnt+SellCnt <= 1) break; //DO NOT PROCEED IF TOTAL OPEN ORDER IS LESS THAN
//-----
double today_hist_profit = GetTodayProfit(MODE_HISTORY);
if (today_hist_profit <= Profit2ExitTodayBalance) break;
if (OrderSelect(ticket1, SELECT_BY_TICKET))
{
double lot = PartialCloseLot;
if (lot > OrderLots()) lot = OrderLots();
for (i=0; i < RepeatN; i++)
{
RefreshRates();
bool res = OrderClose(OrderTicket(), lot, OrderClosePrice(), Slippage, clClose);
Comment("Order close by Condition type 9c");
Print("Order close by Condition type 9c");
if (res) break;
}
}
}
}
green pips