You are on page 1of 2

input double lotSize = 0.

001;
input int takeProfit = 77;
input int stopLoss = 20;
input double martingaleMultiplier = 2.2;

double initialLotSize = lotSize;


int consecutiveLosses = 0;

// Fungsi utama untuk mengeksekusi EA


int start() {
double lowestLow = iLowest(Symbol(), PERIOD_D1, iLow, 0, iTime(NULL, PERIOD_D1,
0));
double highestHigh = iHighest(Symbol(), PERIOD_D1, iHigh, 0, iTime(NULL,
PERIOD_D1, 0));
double currentPrice = iClose(Symbol(), PERIOD_D1, 0);

if (currentPrice <= lowestLow) {


// Entry Sell
ExecuteTrade(OP_SELL, lotSize);
} else if (currentPrice >= highestHigh) {
// Entry Buy
ExecuteTrade(OP_BUY, lotSize);
}

return 0;
}

void ExecuteTrade(int tradeType, double tradeLotSize) {


// Tentukan level stop loss dan take profit
double stopLossLevel = 0;
double takeProfitLevel = 0;

if (tradeType == OP_SELL) {
stopLossLevel = iClose(Symbol(), PERIOD_D1, 0) + stopLoss * Point;
takeProfitLevel = iClose(Symbol(), PERIOD_D1, 0) - takeProfit * Point;
} else if (tradeType == OP_BUY) {
stopLossLevel = iClose(Symbol(), PERIOD_D1, 0) - stopLoss * Point;
takeProfitLevel = iClose(Symbol(), PERIOD_D1, 0) + takeProfit * Point;
}

// Buka posisi
int ticket = OrderSend(Symbol(), tradeType, tradeLotSize, iClose(Symbol(),
PERIOD_D1, 0), 3, stopLossLevel, takeProfitLevel, "Trading EA", 0, 0, Green);

// Periksa apakah order dibuka dengan sukses


if (ticket > 0) {
// Order berhasil dibuka
consecutiveLosses = 0;
} else {
// Order gagal dibuka, menerapkan strategi Martingale
consecutiveLosses++;

if (consecutiveLosses > 1) {
lotSize *= martingaleMultiplier;
} else {
lotSize = initialLotSize;
}

// Retry eksekusi perdagangan


ExecuteTrade(tradeType, lotSize);
}
}

You might also like