Implementing Multi-Time Frame Strategy for Opening and Closing Orders Within the Same Bar

25 Jan 2019
0 comment
0 attachment

This code snippet demonstrates how to use Multi-Time Frame (MTF) analysis in ProBuilder to open and close trading orders within the same bar. The example uses a higher time frame (1 hour) to decide on opening a position and a lower time frame (1 minute) to close the position, all within the same hour.

Timeframe (1h,UpdateOnClose)
If MyConditions Then
    Buy at market
Endif
Timeframe (default)
If LongOnMarket and OpenMinute = 59 Then
    Sell At Market
Endif

Explanation of the Code:

  • Timeframe (1h,UpdateOnClose): This line sets the script to use a 1-hour time frame for the following conditions. The UpdateOnClose parameter ensures that the trading decisions are based on the closing prices of the 1-hour bars.
  • If MyConditions Then: This conditional statement checks if certain predefined conditions (MyConditions) are met. These conditions should be defined elsewhere in your script and could include various technical indicators or price patterns.
  • Buy at market: If the conditions are met, this command triggers a market order to buy. This order is executed at the next available price in the market.
  • Timeframe (default): After the buy order, the script returns to the default time frame, which is typically the time frame of the chart the script is applied to.
  • If LongOnMarket and OpenMinute = 59 Then: This condition checks if there is an open long position and if the current minute is the 59th minute of the hour. The OpenMinute variable should be defined to capture the minute part of the current time.
  • Sell At Market: If the above condition is true, it triggers a market order to sell, aiming to close the position at the end of the hour.

This approach allows traders to leverage different time frames to optimize entry and exit points within a single trading session, potentially enhancing trading strategies by taking advantage of more precise timing and price movements.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/how-to-open-and-close-in-1-bar/#post-146272

Visit Link
What is a Snippet? A snippet is a small, reusable chunk of code designed to solve specific tasks quickly. Think of it as a shortcut that helps you achieve your coding goals without reinventing the wheel. How to Use: Simply copy the snippet and paste it into your project where needed. Don't forget to tweak it to fit your context. Snippets are not just time-savers; they're also learning tools to help you become a more efficient coder.
robertogozzi Master
Roberto https://www.ots-onlinetradingsoftware.com
Author’s Profile

Comments

Search Snippets

Showing some results...
Sorry, no result found!

Snippets Categories

global
35
indicator
133
strategy
171

Recent Snippets

How to Create a Simple MTF Trend Dashboard with EMA and SMA
indicator
This indicator builds a compact multi-timeframe (MTF) dashboard that shows whether price is trading above or below a [...]
How to Display Per-Bar Volume Accumulation in Real Time (Intrabar Updates)
global
This snippet tracks and displays the current bar’s accumulated volume while the bar is still forming, instead of only [...]
Ticks Counter: Count Tick Updates Per Bar on Tick or Time Charts
global
This snippet counts how many tick updates have occurred for the current bar by incrementing a per-bar counter on each [...]
How to Build a Step-Based Trailing Stop That Moves to Break-Even First
strategy
This snippet implements a step trailing stop that advances in fixed increments once price reaches predefined profit [...]
Utilizing Arrays to Track and Compare Indicator Values Within the Same Bar in ProBuilder
indicator
This ProBuilder code snippet demonstrates how to use arrays to compare the values of an indicator (RSI in this case) [...]
Logo Logo
Loading...