no-image

How to implement “Successive Loss Stop Mode”

◎ Functional specifications

  • The total EA is acquired from the trading history of the MT4, and if the total loss exceeds the set total loss, the corresponding EA is stopped (for example, if the total loss exceeds 10 yen, the relevant EA is stopped).

◎ Detailed specifications

XNUMX. Variable declaration

// Total loss

extern double LimitLoss = -100000;

XNUMX. Function definition

double checkOrderHistoryTotal () {

int j;
double profit = 0;
double totalProfit = 0;

for (j = 0; j <OrdersHistoryTotal (); j ++) {

// Select trading history.
if (OrderSelect (j, SELECT_BY_POS, MODE_HISTORY) == false) return (false);

// Get only the settlement part from the trading history
if (OrderSymbol () == Symbol () && (OrderType () == OP_BUY || OrderType () == OP_SELL)) {

// get profit and loss
profit = OrderProfit ();

// Add to the total profit and loss.
totalProfit = totalProfit + profit;
Print (“totalProfit =”, totalProfit, ”“, ”profit =”, profit);
}
}

return (totalProfit);
}

XNUMX. Described in the OnTick function

double tl = checkOrderHistoryTotal ();

// If the total profit / loss exceeds the total loss, the processing is terminated. ?
if (tl> LimitLoss) {
// safety
return;
}

Translate »