Laboratorium Strategi: Generator Engine Prototype

1. Hasil AI Prompt Generator

Kamu adalah seorang kuantitatif pengembang MQL5 Expert Advisor senior.

Tolong buatkan saya skrip MQL5 EA lengkap berdasarkan spesifikasi strategi berikut:

[SPESIFIKASI STRATEGI]
- Nama Strategi: RSI Oversold + MA Filter
- Aturan Entry (Beli/Sell): 
   1. RSI (Period: 14) Menembus ke bawah (<) 30
   2. SMA (Period: 50) Berada di atas (>) Price Close
- Aturan Exit: Berdasarkan Stop Loss / Take Profit
- Manajemen Risiko: Stop Loss 300, Take Profit 600

[PERSYARATAN KODE]
1. Gunakan library CTrade bawaan MetaTrader 5.
2. Lakukan inisialisasi handle indikator pada OnInit() dan release handle pada OnDeinit().
3. Sertakan penanganan error penempatan order (check return code).

2. Hasil MQL5 Code Generator (.mq5)

//+------------------------------------------------------------------+
//| Auto-generated by Backtest Lab Engine                           |
//+------------------------------------------------------------------+
#property copyright "Backtest Lab"
#include <Trade\Trade.mqh>
CTrade trade;

// Inputs
// Global Handles & Buffers
int handle_rsi_0;
int handle_sma_1;

input group "=== Risk Management ===";
input int      InpStopLoss   = 300; // Stop Loss (Pips)
input int      InpTakeProfit = 600; // Take Profit (Pips)
input double   InpLotSize    = 0.1; // Lot Size



int OnInit() {
    handle_rsi_0 = iRSI(_Symbol, _Period, 14, PRICE_CLOSE);
    if(handle_rsi_0 == INVALID_HANDLE) { Print("Gagal membuat handle RSI"); return(INIT_FAILED); }
    handle_sma_1 = iMA(_Symbol, _Period, 50, 0, MODE_SMA, PRICE_CLOSE);
    if(handle_sma_1 == INVALID_HANDLE) { Print("Gagal membuat handle SMA"); return(INIT_FAILED); }

    return(INIT_SUCCEEDED);
}

void OnDeinit(const int reason) {
    IndicatorRelease(handle_rsi_0);
    IndicatorRelease(handle_sma_1);

}

void OnTick() {
    // Hanya eksekusi pada candle baru / tick valid
    if(PositionsTotal() > 0) return; // Maksimal 1 posisi aktif

    double buf_rsi_0[1];
    if(CopyBuffer(handle_rsi_0, 0, 0, 1, buf_rsi_0) < 1) return;
    double buf_sma_1[1];
    if(CopyBuffer(handle_sma_1, 0, 0, 1, buf_sma_1) < 1) return;

    // Evaluasi Kondisi Entry
    bool buyCondition = (buf_rsi_0[0] < 30.0);

    if(buyCondition) {
        double price = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
        double sl = price - (InpStopLoss * _Point * 10);
        double tp = price + (InpTakeProfit * _Point * 10);
        trade.Buy(InpLotSize, _Symbol, price, sl, tp, "Backtest Lab EA");
    }

}