OPEN-SOURCE SCRIPT

Martingale Grid Bot

117
Martingale Grid Bot (MGB)
The strategy is designed to test grid trading with a possible increase in the size of each subsequent order based on the martingale principle. The strategy itself does not contain any trade decision logic and is fully driven by external signals coming from indicators used on the chart. A new grid of orders is created when an entry signal is received, provided that there is no active grid.

Warning
Trading with leverage and martingale involves increased risk. This strategy is a rather rough tool and is intended for testing purposes only. The author is not responsible for any possible discrepancies between the strategy results and real trading.

Settings

Direction - Trading direction. Possible values: Long and Short.

Entry Signal Source - Source of the entry signal that initiates the creation of a new order grid. If one of the price sources (open, high, low, close, etc.) is selected, a new grid will be created automatically after the previous grid is fully closed.

Start Time - Date and time when the strategy starts operating. Marked on the chart with a vertical dashed line.

No Repainting Mode - A mode intended to reduce discrepancies between historical and real-time strategy behavior (repainting).
Enabled — a new grid is created only after the bar is closed. The first order can be filled no earlier than on the next bar.
Disabled — in real-time, a new grid can be created immediately upon receiving a signal or after the previous grid is closed by take profit or stop loss.

Attention
For correct real-time operation, recalculation on every tick must be enabled in the strategy settings.

GRID

Grid Depth % - The depth of the order grid, specified as a percentage of the closing price at the moment the grid is created.

Orders Count - The number of orders in the grid. The first order is placed at the current closing price at the time of grid creation.

Martingale Multiplier - Position size multiplier. Each subsequent order in the grid will be increased by this factor. The size of the first order is defined in the strategy settings.

Leverage - Leverage multiplier for margin trading. Used to check available funds when creating grid orders. It is recommended to use it together with the margin parameters in the strategy settings.

Take Profit % - Calculated on each strategy update based on the average entry price. If none of the grid orders have been filled yet, the take-profit level for the first order is displayed on the chart.

Stop Loss % - Calculated from the price of the first grid order and does not change during the strategy operation. Orders whose price exceeds the stop-loss level will be automatically canceled.

TABLE

Show Table - Controls the display of the table with all orders of the current grid. If there is no active grid, no order data is displayed. Text and background colors are determined automatically based on the chart background color.

Order Size - Determines how the grid order size is displayed: in contracts or in currency.

Table Size - Font size in the table.

Timezone - Used to correctly display the order fill time relative to the chart time. The order fill time (status: filled) can be seen by hovering over the corresponding status cell in the table.

VISUAL

Long Entry - Color of the dotted lines representing grid orders when trading long. Also defines the color of the vertical line indicating the strategy start time.

Short Entry - Color of the dotted lines representing grid orders when trading short. Also defines the color of the vertical line indicating the strategy start time.

Take Profit - Color of the solid line representing the take-profit level.

Stop Loss - Color of the solid line representing the stop-loss level.

Thông báo miễn trừ trách nhiệm

Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.