Home » Strategy Functions » Understanding the strategy.risk.max_intraday_filled_orders() Function in Pine Script

Understanding the strategy.risk.max_intraday_filled_orders() Function in Pine Script

Photo of author
Published on

This tutorial delves into the intricacies of strategy.risk.max_intraday_filled_orders()  function, offering a comprehensive guide to implementing it effectively in your trading scripts.

Syntax

strategy.risk.max_intraday_filled_orders(count, alert_message) → void

Arguments

  • count (simple int): Mandatory. Specifies the maximum number of filled orders per day.
  • alert_message (simple string): Optional. Customizes the message shown in alerts when the maximum order limit is reached.

Example and Analysis

To elucidate the functionality of strategy.risk.max_intraday_filled_orders(), consider the following example script:

//@version=5
strategy("Demo: Max Intraday Filled Orders", shorttitle="MIFO Demo", overlay=true)
strategy.risk.max_intraday_filled_orders(10) // Sets the filled orders limit to 10 per day

if open > close
    strategy.entry("OrderBuy", strategy.long)
if open < close
    strategy.entry("OrderSell", strategy.short)
Example

Code Walkthrough

  1. Strategy Definition: The script initiates with strategy(), defining the strategy’s name and some basic parameters.
  2. Applying the Risk Rule: strategy.risk.max_intraday_filled_orders(10) sets a limit of 10 filled orders per day. This means that after 10 orders have been filled, the strategy will not execute any more orders for the remainder of the trading day.
  3. Trading Logic: The script includes basic trading conditions based on the relationship between the open and close prices of a bar:
  • If the opening price is higher than the closing price, a buy order (OrderBuy) is placed.
  • Conversely, if the opening price is lower than the closing price, a sell order (OrderSell) is issued.

Key Features and Takeaways

  • Risk Management: This function is an essential tool for managing the number of transactions, helping to avoid excessive trading and potential losses in volatile conditions.
  • Custom Alert Messages: The optional alert_message argument allows for personalized alert configurations, enhancing the strategy’s integration with the TradingView alert system.
  • Flexibility: The function’s application spans across different chart resolutions, adapting its behavior based on the chart’s timeframe.

In conclusion, the strategy.risk.max_intraday_filled_orders() function is a powerful feature in Pine Script for controlling trading activity and managing risk within a trading strategy. 

Leave a Comment