Mastering Stoch: A Smart Trading System for MetaTrader 5

Mike 2017.01.26 18:09 30 0 0
Attachments

Author of the IdeaCollector, MQL5 Code Authorbarabashkakvn.

Today, let’s dive into a nifty trading system that leverages pending Sell Limit and Buy Limit orders. One of its unique features is that it automatically removes all orders and closes positions at 23:59. This makes it a great tool for traders looking to streamline their end-of-day processes.

How Pending Orders Work

Here’s a quick overview of how the system calculates prices for pending orders:

double temp_h = iHigh(1);
double temp_l = iLow(1);
double temp_c = iClose(1);
double H4, L4;
H4 = (((temp_h - temp_l) * 1.1) / 2.0) + temp_c;
L4 = temp_c - ((temp_h - temp_l) * 1.1) / 2.0;

As you can see, it’s a straightforward calculation that helps determine the optimal entry points for both buy and sell orders.

Executing Orders

Now, let’s break down how the system executes these orders. If it's not the same day of the week and there are no active Sell Limit orders, it will try to place one:

if (db != str1.day_of_week && s == 0) {
    if (!m_trade.SellLimit(Lots, H4, Symbol(),
        H4 + ExtStopLoss * Point,
        H4 - ExtTakeProfit * Point, 0, 0, "H4"))
        GlobalVariableSet("SELLLIMIT", 0);
    else {
        GlobalVariableSet("SELLLIMIT", 1);
        GlobalVariableSet("DateS", str1.day_of_week);
    }
}

The same logic applies for placing Buy Limit orders. If there are no active Buy Limit orders, it will attempt to create one:

if (db != str1.day_of_week && b == 0) {
    if (!m_trade.BuyLimit(Lots, L4, Symbol(),
        L4 - ExtStopLoss * Point,
        L4 + ExtTakeProfit * Point, 0, 0, "L4"))
        GlobalVariableSet("BUYLIMIT", 0);
    else {
        GlobalVariableSet("BUYLIMIT", 1);
        GlobalVariableSet("DateB", str1.day_of_week);
    }
}

End-of-Day Cleanup

At 23:59, the system checks for any pending orders or open positions. If any exist, it will delete them:

if (total_pos > 0 && str1.hour == 23 && str1.min == 59)
    DeleteAllPositions();

if (total_orders > 0 && str1.hour == 23 && str1.min == 59)
    DeleteAllOrders();

This ensures that you're not left holding onto any trades as the day wraps up. It’s a smart way to manage risk!

Best Practices

For optimal performance, it’s recommended to use this system on the H1 timeframe.

Stoch tester

Happy trading, and may the pips be with you!

List
Comments 0