DEV Community

FMZQuant
FMZQuant

Posted on

Multi-Session Predetermined Trading Execution Optimization Strategy

Overview
The Multi-Session Predetermined Trading Execution Optimization Strategy is an automated trading system based on time triggers, allowing traders to execute preset trading instructions at specific times during the trading day. This strategy is particularly suitable for traders who need to capture price dynamics during specific market sessions (such as overnight trading, pre-market, or closing moments). The strategy performs best on a 1-minute timeframe, providing the most precise execution environment for time-accurate trading. The system allows users to set up to three independent trading sessions, each with individually configurable trade direction (buy or sell) and preset take profit and stop loss levels.

Strategy Principles
The core principle of this strategy is based on a precise time-triggering mechanism, implemented through the following key components:

  1. Multi-Session Setup: The strategy supports three independent trading sessions, each with its specific execution time (hour and minute) and trading direction (long or short). Users can control the enabled status of each session through Boolean inputs.

  2. Time-Precise Triggering: The strategy checks the current hour and minute values against the preset three trading sessions. When the time matches, the strategy executes trading instructions according to the user-defined trading direction.

  3. Daily Reset Mechanism: To prevent the strategy from repeatedly executing too many trades on the same day, the system implements a daily reset function. By tracking the current trading day and recording the number of trades executed, it ensures that each trading session executes at most one trade per day.

  4. Risk Management Parameters: The strategy allows users to define take profit and stop loss levels for each trade, as well as the trading volume (lot size) for each order, enabling personalized risk management.

  5. Execution Limits: The system limits execution to a maximum of three trades per trading day (at most one per session), avoiding the risk of overtrading.

Strategy Advantages
Deep analysis of the strategy code reveals the following significant advantages:

  1. High Customizability: Users have complete control over trading sessions, trading direction, take profit and stop loss levels, and trading volume, allowing the strategy to adapt to different market conditions and trading styles.

  2. Time Precision: Running on a 1-minute timeframe ensures high time precision for trade execution, which is crucial for capturing price movements at key market moments.

  3. Automation Efficiency: Once set up, the strategy executes completely automatically, eliminating the need for traders to continuously monitor the market, saving time and energy.

  4. Trade Frequency Control: Through the daily reset mechanism and trade count limitation, the strategy prevents overtrading, reducing trading costs and the risk of emotionally driven decisions.

  5. Market Session Utilization: Particularly suitable for exploiting price patterns in specific market sessions, such as trading opportunities at key moments like market open, close, overnight, and pre-market.

  6. Clear and Concise Code Structure: The strategy code structure is clear, easy to understand and modify, making it convenient for traders to adjust according to their own needs.

Strategy Risks
Despite its many advantages, the strategy also presents the following potential risks:

  1. Fixed Time Risk: Since trade execution is entirely based on preset times, the strategy does not consider current market conditions, price levels, or technical indicators, potentially executing trades in unfavorable market environments.

  2. Market Gap Risk: In rapidly changing markets, especially during market gaps or extreme volatility, fixed stop loss settings may not effectively protect capital.

  3. Parameter Optimization Challenges: Determining the optimal trading sessions and take profit/stop loss levels requires extensive backtesting and market research; improper parameter settings may lead to poor strategy performance.

  4. Time Zone Dependency: The strategy executes based on the chart's time zone (UTC by default); traders need to ensure that time settings correctly correspond to the target market's trading sessions.

  5. Liquidity Risk: May face issues of insufficient liquidity or widened slippage during certain specific time periods (such as market open or close).

Methods to address these risks include:

  • Incorporating market condition filters to add conditional judgments for trade execution
  • Implementing dynamic stop loss mechanisms that adjust stop loss levels based on market volatility
  • Conducting thorough historical backtesting to optimize parameter settings
  • Ensuring time zone settings align with the target market
  • Applying the strategy in markets and time periods with higher trading volume to reduce liquidity risk

Strategy Optimization Directions
Based on in-depth analysis of the strategy code, the following optimization directions are recommended:

  1. Market Condition Filtering: Introduce technical indicators or price pattern filters to ensure trades are only executed under favorable market conditions. For example, adding trend confirmation indicators or volatility filters.

  2. Dynamic Take Profit and Stop Loss: Change fixed take profit and stop loss points to dynamic settings based on market volatility (such as the ATR indicator) to better adapt to different market environments.

  3. Multi-Timeframe Confirmation: Introduce confirmation signals from higher-level timeframes to ensure that the trading direction aligns with trends in larger timeframes.

  4. Trading Volume Optimization: Implement functionality to dynamically adjust trading volume based on account size or market volatility, enhancing the flexibility of capital management.

  5. Entry Price Optimization: Rather than immediately entering the market when time conditions are met, wait for more optimal price levels (such as support or resistance levels) before executing trades.

  6. Additional Exit Strategies: Beyond fixed take profit and stop loss, add alternative exit mechanisms based on time or price patterns, such as trailing stops or forced closing at specific time points.

  7. Inter-Session Correlation: Add conditional logic for subsequent sessions related to the results of previous session trades, creating a more complex and adaptive trading system.

These optimizations can significantly enhance the strategy's adaptability and robustness, especially in volatile market environments. Implementing these improvements will transform the strategy from a simple time-triggered system into a more comprehensive trading system, retaining the advantage of time precision while increasing responsiveness to market conditions.

Summary
The Multi-Session Predetermined Trading Execution Optimization Strategy is a concise yet efficient time-triggered trading system, particularly suitable for capturing trading opportunities during specific market sessions. Through three customizable trading sessions, traders can precisely execute preset trading plans and manage risks through take profit and stop loss settings.

The strategy's main advantages lie in its high time precision, automation efficiency, and customizability, making it an effective tool for capturing price dynamics at key market moments. However, the strategy also faces risks such as fixed-time execution, lack of market condition filtering, and parameter optimization challenges.

By introducing market condition filters, dynamic take profit and stop loss mechanisms, multi-timeframe confirmation, and optimized entry and exit strategies, the strategy can further enhance its robustness and adaptability. These optimizations will help traders better address challenges in different market environments while maintaining the advantage of time precision.

Overall, the Multi-Session Predetermined Trading Execution Optimization Strategy provides a valuable tool for traders who need to execute trades at specific time points, particularly suitable for intraday traders and session closing strategy enthusiasts. With appropriate parameter settings and suggested optimizations, this strategy can become an important component in a trader's toolkit.

Strategy source code

/*backtest
start: 2025-06-22 00:00:00
end: 2025-06-25 11:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"ETH_USDT","balance":50000000}]
*/

// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Babtrader24 - simple strategy 

//@version=6
strategy("BG CloseCandle", overlay=true, default_qty_type=strategy.fixed, default_qty_value=1)

// 📌 Group: Custom Sessions
session1Buy  = input.bool(true,  "Session 1 - Buy ON",  group="Session 1")
session1Sell = input.bool(false, "Session 1 - Sell ON", group="Session 1")
hour1   = input.int(14, "Hour", group="Session 1", inline="t1")
minute1 = input.int(49, "Minute", group="Session 1", inline="t1")

session2Buy  = input.bool(true,  "Session 2 - Buy ON",  group="Session 2")
session2Sell = input.bool(false, "Session 2 - Sell ON", group="Session 2")
hour2   = input.int(00, "Hour", group="Session 2", inline="t2")
minute2 = input.int(59, "Minute", group="Session 2", inline="t2")

session3Buy  = input.bool(true,  "Session 3 - Buy ON",  group="Session 3")
session3Sell = input.bool(false, "Session 3 - Sell ON", group="Session 3")
hour3   = input.int(01, "Hour", group="Session 3", inline="t3")
minute3 = input.int(59, "Minute", group="Session 3", inline="t3")

// 🎯 Group: Trade Settings
tp_ticks = input.int(30, "Take Profit (ticks)", group="Trade Settings")
sl_ticks = input.int(100, "Stop Loss (ticks)", group="Trade Settings")
lot_size = input.int(1, "Lot Size", group="Trade Settings")

// ✅ Time check based on chart's timezone (UTC by default)
isTime1 = (hour == hour1 and minute == minute1)
isTime2 = (hour == hour2 and minute == minute2)
isTime3 = (hour == hour3 and minute == minute3)

// 🔁 Daily Reset
var int traded_today = 0
var int last_day = na
if na(last_day) or dayofmonth != last_day
    traded_today := 0
    last_day := dayofmonth

// ⚙️ Conditional Entries per Session
if traded_today < 3
    if isTime1
        if session1Buy
            strategy.entry("Buy_S1", strategy.long, qty=lot_size)
            strategy.exit("TP/SL_Buy_S1", from_entry="Buy_S1", limit=close + tp_ticks * syminfo.mintick, stop=close - sl_ticks * syminfo.mintick)
            traded_today += 1
        else if session1Sell
            strategy.entry("Sell_S1", strategy.short, qty=lot_size)
            strategy.exit("TP/SL_Sell_S1", from_entry="Sell_S1", limit=close - tp_ticks * syminfo.mintick, stop=close + sl_ticks * syminfo.mintick)
            traded_today += 1

    else if isTime2
        if session2Buy
            strategy.entry("Buy_S2", strategy.long, qty=lot_size)
            strategy.exit("TP/SL_Buy_S2", from_entry="Buy_S2", limit=close + tp_ticks * syminfo.mintick, stop=close - sl_ticks * syminfo.mintick)
            traded_today += 1
        else if session2Sell
            strategy.entry("Sell_S2", strategy.short, qty=lot_size)
            strategy.exit("TP/SL_Sell_S2", from_entry="Sell_S2", limit=close - tp_ticks * syminfo.mintick, stop=close + sl_ticks * syminfo.mintick)
            traded_today += 1

    else if isTime3
        if session3Buy
            strategy.entry("Buy_S3", strategy.long, qty=lot_size)
            strategy.exit("TP/SL_Buy_S3", from_entry="Buy_S3", limit=close + tp_ticks * syminfo.mintick, stop=close - sl_ticks * syminfo.mintick)
            traded_today += 1
        else if session3Sell
            strategy.entry("Sell_S3", strategy.short, qty=lot_size)
            strategy.exit("TP/SL_Sell_S3", from_entry="Sell_S3", limit=close - tp_ticks * syminfo.mintick, stop=close + sl_ticks * syminfo.mintick)
            traded_today += 1
Enter fullscreen mode Exit fullscreen mode

Strategy parameters

The original address: Multi-Session Predetermined Trading Execution Optimization Strategy

Top comments (1)

Collapse
 
quant_fmz_5544836beadc814 profile image
Rebecca Chow

Ah, 'predetermined execution'—because my spontaneous trades always end in tears! This strategy sounds solid, but let’s be real: if it can also predict when I’ll finally stick to a plan, I’m sold. Optimize my trades and my discipline? Now that’s alpha.