QUIZ BAB 4

1 / 11

Program MQL4 di bawah ini paling tepat untuk bagian "Coding the time conditions (Blue section)" dari sebuah EA.
Apa tujuan dibuatnnya fungsi SetTradingTimeConditions() ?

// Program untuk menentukan kondisi waktu trading

void SetTradingTimeConditions() {

    int currentHour = Hour();

    int currentMinute = Minute();

    

    if ((currentHour >= 8 && currentHour < 16) || (currentHour == 16 && currentMinute < 30)) {

        // Trading time condition met

        Print("It's trading time!");

    } else {

        // Not trading time

        Print("Waiting for trading time...");

    }

}

2 / 11

Program MQL4 di bawah ini paling tepat untuk bagian "Coding the entry conditions (Green section)" dari sebuah EA.

Apa salah satu perintah yang dibuat pada  fungsi CheckMovingAverageCross() ?

 

// Program untuk mengecek persilangan Moving Average

void CheckMovingAverageCross() {

    double maFast = iMA(Symbol(), 0, 14, 0, MODE_SMA, PRICE_CLOSE, 0);

    double maSlow = iMA(Symbol(), 0, 28, 0, MODE_SMA, PRICE_CLOSE, 0);

    

    if (maFast > maSlow) {

        // Masuk posisi Buy

        OrderSend(Symbol(), OP_BUY, 0.1, Ask, 3, 0, 0, "Buy Order", 12345, 0, Green);

    } else if (maFast < maSlow) {

        // Masuk posisi Sell

        OrderSend(Symbol(), OP_SELL, 0.1, Bid, 3, 0, 0, "Sell Order", 12345, 0, Red);

    }

}

3 / 11

Program MQL4 di bawah ini paling tepat untuk bagian "Coding the exit conditions (Red section)" dari sebuah EA.

Apa tujuan dibuatnya variable ‘currentBid’ ?


// Program untuk menambahkan fungsi failsafe dalam menutup order

void AddFailsafeToCloseOrder(int ticket) {

    double currentBid = Bid;

    double stopLoss = OrderStopLoss();

    

    if (currentBid < stopLoss) {

        // Tutup order dengan harga saat ini

        OrderClose(ticket, OrderLots(), currentBid, 3, Red);

    }

}

4 / 11

Apa yang dilakukan oleh program MQL4 di bawah ini?

void TestExpertAdvisor() {

    double accountBalance = AccountBalance();

    

    if (IsTesting()) {

        Print("Testing EA with account balance: ", accountBalance);

    } else {

        Print("Not in testing mode.");

    }

}

5 / 11

Program MQL4 di bawah ini paling tepat untuk bagian "Adding The Moving Average Indicator As A Filter" dari sebuah EA.
Apa maksud dari Close[1] pada program di bawah ini ?

// Program untuk menambahkan Moving Average sebagai filter

void AddMovingAverageFilter() {

    int maPeriod = 14;

    double maValue = iMA(Symbol(), 0, maPeriod, 0, MODE_SMA, PRICE_CLOSE, 0);

    

    if (Close[1] < maValue && Close > maValue) {

        // Syarat untuk melakukan transaksi Buy

        OrderSend(Symbol(), OP_BUY, 0.1, Ask, 3, 0, 0, "Buy Order", 12345, 0, Green);

    } else if (Close[1] > maValue && Close < maValue) {

        // Syarat untuk melakukan transaksi Sell

        OrderSend(Symbol(), OP_SELL, 0.1, Bid, 3, 0, 0, "Sell Order", 12345, 0, Red);

    }

}

6 / 11

Program MQL4 di bawah ini paling tepat untuk bagian "Trading Filter Optimization" dari sebuah EA.
Apa perbedaan fastMA dan slowMA pada program di bawah ini ?

// Program untuk mengoptimalkan filter perdagangan

void OptimizeTradingFilters() {

    int fastMA = 14;

    int slowMA = 28;

    

    double maFast = iMA(Symbol(), 0, fastMA, 0, MODE_SMA, PRICE_CLOSE, 0);

    double maSlow = iMA(Symbol(), 0, slowMA, 0, MODE_SMA, PRICE_CLOSE, 0);

    

    if (maFast > maSlow) {

        // Syarat untuk melakukan transaksi Buy

        OrderSend(Symbol(), OP_BUY, 0.1, Ask, 3, 0, 0, "Buy Order", 12345, 0, Green);

    } else if (maFast < maSlow) {

        // Syarat untuk melakukan transaksi Sell

        OrderSend(Symbol(), OP_SELL, 0.1, Bid, 3, 0, 0, "Sell Order", 12345, 0, Red);

    }

}

7 / 11

Soal 1: Anda sedang mengembangkan sebuah Expert Advisor (EA) untuk sistem trading otomatis. Dalam kondisi pasar yang volatile, Anda ingin memasukkan fungsi pengaman yang dapat menyesuaikan stop loss secara otomatis berdasarkan pergerakan harga saat ini. Buatlah sebuah program MQL4 yang dapat mendeteksi pergerakan harga secara real-time dan mengubah stop loss sesuai dengan kondisi tersebut.Program manakah yang tepat digunakan untuk situasi seperti itu ?

A.

void ManagePortfolio() {

    double accountBalance = AccountBalance();

    double riskPerTrade = 0.02; // Risiko per transaksi dalam persentase modal

    double maxRisk = accountBalance * riskPerTrade;

    

    double volatilities[] = {0.015, 0.012, 0.018}; // Volatilitas masing-masing pasangan mata uang

    double lotSizes[];

    

    for (int i = 0; i < ArraySize(volatilities); i++) {

        lotSizes[i] = maxRisk / (volatilities[i] * 1000); // 1000 adalah nilai per pip untuk pasangan mata uang tertentu

        Print("Lot size for pair ", i, ": ", lotSizes[i]);

    }

}

B.

void TradingStrategy() {

    double maValue = iMA(Symbol(), 0, 14, 0, MODE_SMA, PRICE_CLOSE, 0);

    double rsiValue = iRSI(Symbol(), 0, 14, PRICE_CLOSE, 0);

    

    if (Close[1] < maValue && Close > maValue && rsiValue < 30) {

        // Syarat untuk Buy

        OrderSend(Symbol(), OP_BUY, 0.1, Ask, 3, 0, 0, "Buy Order", 12345, 0, Green);

    } else if (Close[1] > maValue && Close < maValue && rsiValue > 70) {

        // Syarat untuk Sell

        OrderSend(Symbol(), OP_SELL, 0.1, Bid, 3, 0, 0, "Sell Order", 12345, 0, Red);

    }

}

C.

void AdjustStopLoss() {

    double currentBid = Bid;

    double stopLoss = OrderStopLoss();

    

    if (currentBid > stopLoss) {

        // Naikkan stop loss jika harga bergerak naik

        double newStopLoss = currentBid - 100 * Point; // Contoh penyesuaian sebesar 100 pips

        OrderModify(OrderTicket(), OrderOpenPrice(), newStopLoss, OrderTakeProfit(), 0, Green);

    }

}

D.

void AdaptiveTimeFrameEA() {

    int currentTF = Period();

    

    if (currentTF == PERIOD_H1) {

        // Strategi untuk H1

        double maValue = iMA(Symbol(), PERIOD_H1, 14, 0, MODE_SMA, PRICE_CLOSE, 0);

        // ... Lakukan operasi trading untuk H1

    } else if (currentTF == PERIOD_D1) {

        // Strategi untuk D1

        double maValue = iMA(Symbol(), PERIOD_D1, 14, 0, MODE_SMA, PRICE_CLOSE, 0);

        // ... Lakukan operasi trading untuk D1

    }

}

E.

void AnalyzeTradingResults() {

    double totalProfit = 0;

    double totalLoss = 0;

    int totalTrades = 0;

    

    for (int i = 0; i < OrdersHistoryTotal(); i++) {

        if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {

            if (OrderType() == OP_BUY) {

                totalProfit += OrderProfit();

            } else if (OrderType() == OP_SELL) {

                totalLoss += OrderLoss();

            }

            totalTrades++;

        }

    }

    

    double averageProfit = totalProfit / totalTrades;

    double averageLoss = totalLoss / totalTrades;

    

    Print("Average Profit per trade: ", averageProfit);

    Print("Average Loss per trade: ", averageLoss);

}

8 / 11

Soal 2: Sebagai seorang trader forex, Anda memiliki strategi trading berbasis analisis teknikal menggunakan kombinasi Moving Average dan Relative Strength Index (RSI). Buatlah sebuah EA menggunakan MQL4 yang tidak hanya memasukkan kedua indikator tersebut sebagai filter untuk entry dan exit, tetapi juga mampu mengoptimalkan parameter-parameter indikator tersebut secara otomatis berdasarkan kondisi pasar terkini.

A.

void ManagePortfolio() {

    double accountBalance = AccountBalance();

    double riskPerTrade = 0.02; // Risiko per transaksi dalam persentase modal

    double maxRisk = accountBalance * riskPerTrade;

    

    double volatilities[] = {0.015, 0.012, 0.018}; // Volatilitas masing-masing pasangan mata uang

    double lotSizes[];

    

    for (int i = 0; i < ArraySize(volatilities); i++) {

        lotSizes[i] = maxRisk / (volatilities[i] * 1000); // 1000 adalah nilai per pip untuk pasangan mata uang tertentu

        Print("Lot size for pair ", i, ": ", lotSizes[i]);

    }

}

B.

void TradingStrategy() {

    double maValue = iMA(Symbol(), 0, 14, 0, MODE_SMA, PRICE_CLOSE, 0);

    double rsiValue = iRSI(Symbol(), 0, 14, PRICE_CLOSE, 0);

    

    if (Close[1] < maValue && Close > maValue && rsiValue < 30) {

        // Syarat untuk Buy

        OrderSend(Symbol(), OP_BUY, 0.1, Ask, 3, 0, 0, "Buy Order", 12345, 0, Green);

    } else if (Close[1] > maValue && Close < maValue && rsiValue > 70) {

        // Syarat untuk Sell

        OrderSend(Symbol(), OP_SELL, 0.1, Bid, 3, 0, 0, "Sell Order", 12345, 0, Red);

    }

}

C.

void AdjustStopLoss() {

    double currentBid = Bid;

    double stopLoss = OrderStopLoss();

    

    if (currentBid > stopLoss) {

        // Naikkan stop loss jika harga bergerak naik

        double newStopLoss = currentBid - 100 * Point; // Contoh penyesuaian sebesar 100 pips

        OrderModify(OrderTicket(), OrderOpenPrice(), newStopLoss, OrderTakeProfit(), 0, Green);

    }

}

D.

void AdaptiveTimeFrameEA() {

    int currentTF = Period();

    

    if (currentTF == PERIOD_H1) {

        // Strategi untuk H1

        double maValue = iMA(Symbol(), PERIOD_H1, 14, 0, MODE_SMA, PRICE_CLOSE, 0);

        // ... Lakukan operasi trading untuk H1

    } else if (currentTF == PERIOD_D1) {

        // Strategi untuk D1

        double maValue = iMA(Symbol(), PERIOD_D1, 14, 0, MODE_SMA, PRICE_CLOSE, 0);

        // ... Lakukan operasi trading untuk D1

    }

}

E.

void AnalyzeTradingResults() {

    double totalProfit = 0;

    double totalLoss = 0;

    int totalTrades = 0;

    

    for (int i = 0; i < OrdersHistoryTotal(); i++) {

        if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {

            if (OrderType() == OP_BUY) {

                totalProfit += OrderProfit();

            } else if (OrderType() == OP_SELL) {

                totalLoss += OrderLoss();

            }

            totalTrades++;

        }

    }

    

    double averageProfit = totalProfit / totalTrades;

    double averageLoss = totalLoss / totalTrades;

    

    Print("Average Profit per trade: ", averageProfit);

    Print("Average Loss per trade: ", averageLoss);

}

9 / 11

Soal 3: Anda telah merancang EA yang dapat memperdagangkan beberapa pasangan mata uang secara simultan di MetaTrader 4. Bagaimana Anda akan mengelola risiko dan alokasi modal antara berbagai pasangan mata uang yang diperdagangkan? Buatlah program MQL4 yang memungkinkan pengelolaan portofolio trading dengan mengatur lot size berdasarkan volatilitas masing-masing pasangan mata uang.

A.

void ManagePortfolio() {

    double accountBalance = AccountBalance();

    double riskPerTrade = 0.02; // Risiko per transaksi dalam persentase modal

    double maxRisk = accountBalance * riskPerTrade;

    

    double volatilities[] = {0.015, 0.012, 0.018}; // Volatilitas masing-masing pasangan mata uang

    double lotSizes[];

    

    for (int i = 0; i < ArraySize(volatilities); i++) {

        lotSizes[i] = maxRisk / (volatilities[i] * 1000); // 1000 adalah nilai per pip untuk pasangan mata uang tertentu

        Print("Lot size for pair ", i, ": ", lotSizes[i]);

    }

}

B.

void TradingStrategy() {

    double maValue = iMA(Symbol(), 0, 14, 0, MODE_SMA, PRICE_CLOSE, 0);

    double rsiValue = iRSI(Symbol(), 0, 14, PRICE_CLOSE, 0);

    

    if (Close[1] < maValue && Close > maValue && rsiValue < 30) {

        // Syarat untuk Buy

        OrderSend(Symbol(), OP_BUY, 0.1, Ask, 3, 0, 0, "Buy Order", 12345, 0, Green);

    } else if (Close[1] > maValue && Close < maValue && rsiValue > 70) {

        // Syarat untuk Sell

        OrderSend(Symbol(), OP_SELL, 0.1, Bid, 3, 0, 0, "Sell Order", 12345, 0, Red);

    }

}

C.

void AdjustStopLoss() {

    double currentBid = Bid;

    double stopLoss = OrderStopLoss();

    

    if (currentBid > stopLoss) {

        // Naikkan stop loss jika harga bergerak naik

        double newStopLoss = currentBid - 100 * Point; // Contoh penyesuaian sebesar 100 pips

        OrderModify(OrderTicket(), OrderOpenPrice(), newStopLoss, OrderTakeProfit(), 0, Green);

    }

}

D.

void AdaptiveTimeFrameEA() {

    int currentTF = Period();

    

    if (currentTF == PERIOD_H1) {

        // Strategi untuk H1

        double maValue = iMA(Symbol(), PERIOD_H1, 14, 0, MODE_SMA, PRICE_CLOSE, 0);

        // ... Lakukan operasi trading untuk H1

    } else if (currentTF == PERIOD_D1) {

        // Strategi untuk D1

        double maValue = iMA(Symbol(), PERIOD_D1, 14, 0, MODE_SMA, PRICE_CLOSE, 0);

        // ... Lakukan operasi trading untuk D1

    }

}

E.

void AnalyzeTradingResults() {

    double totalProfit = 0;

    double totalLoss = 0;

    int totalTrades = 0;

    

    for (int i = 0; i < OrdersHistoryTotal(); i++) {

        if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {

            if (OrderType() == OP_BUY) {

                totalProfit += OrderProfit();

            } else if (OrderType() == OP_SELL) {

                totalLoss += OrderLoss();

            }

            totalTrades++;

        }

    }

    

    double averageProfit = totalProfit / totalTrades;

    double averageLoss = totalLoss / totalTrades;

    

    Print("Average Profit per trade: ", averageProfit);

    Print("Average Loss per trade: ", averageLoss);

}

10 / 11

Soal 4: Saat menguji EA Anda dengan data historis, Anda menemukan bahwa performanya cenderung menurun pada periode tertentu. Bagaimana Anda akan melakukan analisis untuk menemukan faktor-faktor yang mempengaruhi performa tersebut? Buatlah sebuah program MQL4 yang dapat melakukan analisis statistik terhadap hasil trading dari EA Anda untuk mengidentifikasi kondisi pasar yang menguntungkan dan tidak menguntungkan.

A.

void ManagePortfolio() {

    double accountBalance = AccountBalance();

    double riskPerTrade = 0.02; // Risiko per transaksi dalam persentase modal

    double maxRisk = accountBalance * riskPerTrade;

    

    double volatilities[] = {0.015, 0.012, 0.018}; // Volatilitas masing-masing pasangan mata uang

    double lotSizes[];

    

    for (int i = 0; i < ArraySize(volatilities); i++) {

        lotSizes[i] = maxRisk / (volatilities[i] * 1000); // 1000 adalah nilai per pip untuk pasangan mata uang tertentu

        Print("Lot size for pair ", i, ": ", lotSizes[i]);

    }

}

B.

void TradingStrategy() {

    double maValue = iMA(Symbol(), 0, 14, 0, MODE_SMA, PRICE_CLOSE, 0);

    double rsiValue = iRSI(Symbol(), 0, 14, PRICE_CLOSE, 0);

    

    if (Close[1] < maValue && Close > maValue && rsiValue < 30) {

        // Syarat untuk Buy

        OrderSend(Symbol(), OP_BUY, 0.1, Ask, 3, 0, 0, "Buy Order", 12345, 0, Green);

    } else if (Close[1] > maValue && Close < maValue && rsiValue > 70) {

        // Syarat untuk Sell

        OrderSend(Symbol(), OP_SELL, 0.1, Bid, 3, 0, 0, "Sell Order", 12345, 0, Red);

    }

}

C.

void AdjustStopLoss() {

    double currentBid = Bid;

    double stopLoss = OrderStopLoss();

    

    if (currentBid > stopLoss) {

        // Naikkan stop loss jika harga bergerak naik

        double newStopLoss = currentBid - 100 * Point; // Contoh penyesuaian sebesar 100 pips

        OrderModify(OrderTicket(), OrderOpenPrice(), newStopLoss, OrderTakeProfit(), 0, Green);

    }

}

D.

void AdaptiveTimeFrameEA() {

    int currentTF = Period();

    

    if (currentTF == PERIOD_H1) {

        // Strategi untuk H1

        double maValue = iMA(Symbol(), PERIOD_H1, 14, 0, MODE_SMA, PRICE_CLOSE, 0);

        // ... Lakukan operasi trading untuk H1

    } else if (currentTF == PERIOD_D1) {

        // Strategi untuk D1

        double maValue = iMA(Symbol(), PERIOD_D1, 14, 0, MODE_SMA, PRICE_CLOSE, 0);

        // ... Lakukan operasi trading untuk D1

    }

}

E.

void AnalyzeTradingResults() {

    double totalProfit = 0;

    double totalLoss = 0;

    int totalTrades = 0;

    

    for (int i = 0; i < OrdersHistoryTotal(); i++) {

        if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {

            if (OrderType() == OP_BUY) {

                totalProfit += OrderProfit();

            } else if (OrderType() == OP_SELL) {

                totalLoss += OrderLoss();

            }

            totalTrades++;

        }

    }

    

    double averageProfit = totalProfit / totalTrades;

    double averageLoss = totalLoss / totalTrades;

    

    Print("Average Profit per trade: ", averageProfit);

    Print("Average Loss per trade: ", averageLoss);

}

11 / 11

Soal 5: Anda ingin mengembangkan EA yang tidak hanya mampu beroperasi pada satu time frame (TF) tertentu, tetapi juga dapat menyesuaikan diri dengan perubahan TF secara dinamis berdasarkan kondisi pasar. Buatlah sebuah program MQL4 yang dapat mendeteksi perubahan TF dan mengoptimalkan parameter-parameter strategi trading secara otomatis untuk TF yang baru.

A.

void ManagePortfolio() {

    double accountBalance = AccountBalance();

    double riskPerTrade = 0.02; // Risiko per transaksi dalam persentase modal

    double maxRisk = accountBalance * riskPerTrade;

    

    double volatilities[] = {0.015, 0.012, 0.018}; // Volatilitas masing-masing pasangan mata uang

    double lotSizes[];

    

    for (int i = 0; i < ArraySize(volatilities); i++) {

        lotSizes[i] = maxRisk / (volatilities[i] * 1000); // 1000 adalah nilai per pip untuk pasangan mata uang tertentu

        Print("Lot size for pair ", i, ": ", lotSizes[i]);

    }

}

B.

void TradingStrategy() {

    double maValue = iMA(Symbol(), 0, 14, 0, MODE_SMA, PRICE_CLOSE, 0);

    double rsiValue = iRSI(Symbol(), 0, 14, PRICE_CLOSE, 0);

    

    if (Close[1] < maValue && Close > maValue && rsiValue < 30) {

        // Syarat untuk Buy

        OrderSend(Symbol(), OP_BUY, 0.1, Ask, 3, 0, 0, "Buy Order", 12345, 0, Green);

    } else if (Close[1] > maValue && Close < maValue && rsiValue > 70) {

        // Syarat untuk Sell

        OrderSend(Symbol(), OP_SELL, 0.1, Bid, 3, 0, 0, "Sell Order", 12345, 0, Red);

    }

}

C.

void AdjustStopLoss() {

    double currentBid = Bid;

    double stopLoss = OrderStopLoss();

    

    if (currentBid > stopLoss) {

        // Naikkan stop loss jika harga bergerak naik

        double newStopLoss = currentBid - 100 * Point; // Contoh penyesuaian sebesar 100 pips

        OrderModify(OrderTicket(), OrderOpenPrice(), newStopLoss, OrderTakeProfit(), 0, Green);

    }

}

D.

void AdaptiveTimeFrameEA() {

    int currentTF = Period();

    

    if (currentTF == PERIOD_H1) {

        // Strategi untuk H1

        double maValue = iMA(Symbol(), PERIOD_H1, 14, 0, MODE_SMA, PRICE_CLOSE, 0);

        // ... Lakukan operasi trading untuk H1

    } else if (currentTF == PERIOD_D1) {

        // Strategi untuk D1

        double maValue = iMA(Symbol(), PERIOD_D1, 14, 0, MODE_SMA, PRICE_CLOSE, 0);

        // ... Lakukan operasi trading untuk D1

    }

}

E.

void AnalyzeTradingResults() {

    double totalProfit = 0;

    double totalLoss = 0;

    int totalTrades = 0;

    

    for (int i = 0; i < OrdersHistoryTotal(); i++) {

        if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {

            if (OrderType() == OP_BUY) {

                totalProfit += OrderProfit();

            } else if (OrderType() == OP_SELL) {

                totalLoss += OrderLoss();

            }

            totalTrades++;

        }

    }

    

    double averageProfit = totalProfit / totalTrades;

    double averageLoss = totalLoss / totalTrades;

    

    Print("Average Profit per trade: ", averageProfit);

    Print("Average Loss per trade: ", averageLoss);

}

Your score is

The average score is 36%

0%