Implementing Multi-Timeframe Stoploss Adjustment in ProBuilder

08 Oct 2018
0 comment
0 attachment

This ProBuilder script demonstrates how to adjust a stoploss to breakeven in a multi-timeframe trading strategy. The code snippet provided below shows how to manage orders on two different timeframes: the 1-hour timeframe for the trading signal and the 1-minute timeframe for order management, specifically for moving the stoploss to breakeven once a certain profit target is achieved.

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
endif

//if not order on market, reset the breakeven status
if not onmarket then
   ibreakeven=0
endif

//check if the current order has made 15 points of profit
if longonmarket and close-tradeprice>=15*pointsize then
   ibreakeven=1
endif

//put stoploss at open price + 5 points if ibreakeven=1
if ibreakeven=1 then
   sell at tradeprice+5*pointsize stop
endif

graph ibreakeven

Explanation of the Code:

  • Defining Strategy Parameters: The script starts by setting defparam cumulateorders=false to ensure that orders do not stack up and each order is treated individually.
  • Setting the Timeframe for Signal: The timeframe(1 hour, updateonclose) function sets the primary trading signals to be generated based on the 1-hour chart, updating only at the close of each 1-hour candle.
  • Generating Buy Signal: A buy signal is generated when the 14-period RSI (Relative Strength Index) crosses over 50 on the 1-hour chart.
  • Order Execution on the 1-Minute Timeframe: The script then switches to a 1-minute timeframe for finer control over order execution. If the buy condition from the 1-hour chart is met, it executes a market order to buy 10 contracts.
  • Resetting Breakeven Status: If there are no open market orders, the breakeven status is reset to 0.
  • Checking for Profit to Adjust Stoploss: The script checks if the current long position has gained at least 15 points. If so, it sets the breakeven flag to 1.
  • Adjusting Stoploss: If the breakeven flag is set, the stoploss is adjusted to 5 points above the trade entry price, effectively moving the stoploss to a breakeven point plus a small buffer.
  • Graphing the Breakeven Status: Finally, the breakeven status is graphed for visual confirmation.

This code snippet is a practical example of how to implement a multi-timeframe strategy in ProBuilder, focusing on dynamic stoploss management based on real-time profit conditions.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/move-sl-during-current-candle/#post-79130

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 Legend
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
135
strategy
171

Recent Snippets

A multi indicator Dashboard for ProRealTime
indicator
This snippet creates a compact on-chart dashboard that aggregates multiple indicator states into a single, readable [...]
How to Track Up/Down Cumulative Volume Inside Each Candle (Tick Volume Delta)
indicator
This snippet separates the real-time, intra-candle volume into up-volume and down-volume based on whether the last [...]
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 [...]
Logo Logo
Loading...