Automating Pending Orders with RSI: A Complete Guide for MetaTrader 4

Mike 2014.08.12 22:46 30 0 0
Attachments

Introduction

Hey traders! Today, we’re diving into an exciting way to manage your trades using the RSI indicator on MetaTrader 4. This handy tool will help you automate pending orders while keeping your risks in check, especially over the weekend. Let’s get started!

Key Features

  1. Automated pending orders utilizing RSI.
  2. Lower risk during weekends and automatically resume trading the following week.
  3. Receive notifications with useful updates straight to your inbox.

Getting Started

Recommendations:

  • 1. Set testmode to true for backtesting, or false for live trading:
extern bool testmode = false; // true for backtest
  • 2. If you’re in test mode, set only one symbol in the trade symbol array. For example:
  • extern string tradesymbol1 = "EURUSDm_802_2802_1602_200_860";
    extern string tradesymbol2 = "";
    // and so on...
  • If you’re in real account mode, set testmode to false and configure the trade symbols like this (use commas to separate symbols and underscores for parameters):
  • extern string tradesymbol1 = "EURUSDm_802_2802_1602_200_860,USDCHFm_506_2606_1506_120_600";
    extern string tradesymbol2 = "USDJPYm_460_2802_1302_100_320";
    // and so on...

    Understanding Symbol Parameters

    The symbol EURUSDm_802_2802_1602_200_860 translates as follows:

    • Symbol: EURUSDm (the m indicates it's for a mini account; adjust this to your own symbol if needed)
    • Pending Pips: 802 (gap for pending orders)
    • Weekend Additional Pips: 2802 (gap adjustment for weekends)
    • Cancel Pips: 1602 (close pending order if the gap exceeds this value)
    • Trailing Stop Loss: 200
    • Virtual Take Profit: 860

    Weekend Management Options

    3. If you'd like to delete pending orders over the weekend, set weekenddelete to true. If you prefer to widen the pending gap and resume trading the next week, set it to false.

    extern bool weekenddelete = false; // true: delete, false: modify

    Setting Weekend Trading Times

    4. Define the weekend start and end times (5 represents Friday, 7 represents Sunday, and times are in GMT, so adjust based on your local time):

    extern int weekendbeginday = 5;
    extern string weekendbegintime = "20:30"; // Friday 20:30
    extern int weekendendday = 7;
    extern string weekendendtime = "23:30"; // Sunday 20:30

    RSI Notifications

    5. List all symbols for which you want to receive RSI value alerts (above 70 or below 30) and periodic reports. Remember to adjust any symbols not applicable to your account type:

    string symbolsstr1 = "AUDJPYm,AUDCADm,AUDCHFm,AUDNZDm,AUDSGDm,AUDUSDm,...";
    // and so on...

    RSI Configuration

    6. Configure the RSI parameters:

    extern int rsitimeframe = PERIOD_H4;
    extern int rsiperiod = 14;
    extern ENUM_APPLIED_PRICE rsiappliedprice = PRICE_CLOSE;
    extern int rsishift = 0;
    extern double rsiupperline = 70;
    extern double rsilowerline = 30;

    Final Notes

    7. Use magicweekendexpiration to identify when weekend mode is activated. If you have a better idea, feel free to share!

    int magicweekendexpiration = 1577836800; // 2020-1-1 0:0:0

    8. Additional notes: If changing to weekend mode fails, the EA will send you an email and keep trying until it succeeds up to MAX_MODIFY_TRY_TIME (default is 100).

    No stop loss is applied, and if the minimum buy or maximum sell order for a symbol exceeds the pending pips, the EA will place another order for that symbol.

    In test mode, if equity falls below 95% of balance, the EA will log this status in a warning file:

    if ((AccountEquity()/AccountBalance()) 

    If you encounter any bugs or have suggestions, please don’t hesitate to reach out!

    List
    Comments 0