Implementing a Breakeven Strategy Using Multiple Timeframes in ProBuilder

07 Apr 2019
0 comment
0 attachment

This code snippet demonstrates how to implement a breakeven strategy using multiple timeframes in ProBuilder. The strategy sets a stop loss to breakeven when a certain profit target is reached during a trade.

defparam cumulateorders=false
//declare the strategy on the 1 hour timeframe
timeframe(1 hour, updateonclose)
myrsi = rsi[14]
buycondition = myrsi crosses over 50
//orders management on the 1 minute timeframe
timeframe(1 minute, default)
//create an order at market if the RSI has crosses the level 50 on the 1 hour timeframe
if buycondition then
   buy 10 contract at market
   //if not order on market, reset the breakeven status
   set stop loss 0
endif
//check if the current order has made 15 points of profit
if longonmarket and close-tradeprice>=15*pointsize then
   set stop breakeven
endif

The code snippet above is structured to manage trades using two different timeframes: one hour for signal generation and one minute for order management. Here’s a step-by-step explanation:

  • Defining Order Accumulation: defparam cumulateorders=false ensures that each order is treated independently without accumulation.
  • Setting the Primary Timeframe: timeframe(1 hour, updateonclose) sets the strategy to operate on a one-hour timeframe, updating at the close of each candle.
  • RSI Calculation: myrsi = rsi[14] calculates the 14-period Relative Strength Index (RSI), which is used to generate buy signals.
  • Buy Condition: buycondition = myrsi crosses over 50 defines the condition to enter a trade, which triggers when the RSI crosses above 50.
  • Switching to Management Timeframe: timeframe(1 minute, default) switches the script to a one-minute timeframe for managing orders.
  • Order Execution: If the buy condition is met, buy 10 contract at market executes a market order for 10 contracts.
  • Initial Stop Loss: set stop loss 0 initially sets the stop loss to zero, effectively not having a stop loss until modified.
  • Setting Breakeven: The condition if longonmarket and close-tradeprice>=15*pointsize then set stop breakeven checks if the trade is in profit by at least 15 points. If true, it adjusts the stop loss to the breakeven point.

This example illustrates how to use multiple timeframes to manage trades more dynamically, particularly useful in fast-moving markets.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/breakeven-avec-ut-inferieure-a-la-strategie/#post-210582

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.
Nicolas Master
I created ProRealCode because I believe in the power of shared knowledge. I spend my time coding new tools and helping members solve complex problems. If you are stuck on a code or need a fresh perspective on a strategy, I am always willing to help. Welcome to the community!
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...