Implementing a Time Delay and Price Condition for Re-Entry in Trading Strategies

10 Jul 2016
0 comment
0 attachment

This ProBuilder code snippet demonstrates how to implement a trading strategy that waits for a specific number of bars and a price movement condition before placing another trade after a loss. This approach can help in managing risk and avoiding immediate re-entry into the market under unfavorable conditions.


IF c1 AND NOT LongOnMarket THEN
    BUY 2 PERPOINT AT MARKET
ENDIF

//let's add another order while price continue to move lower (more than 10 points) than the last order taken with a condition of 5 bars elapsed since then
IF BARINDEX-TRADEINDEX(1)>20 AND Close-TRADEPRICE(1)>20 AND LongOnMarket THEN
    BUY 2 PERPOINT AT MARKET
ENDIF

The code snippet includes two main conditional statements that control when trades are placed:

  • Initial Trade Condition: The first IF statement checks if a certain condition c1 is true and ensures that there is no long position currently open in the market (NOT LongOnMarket). If both conditions are satisfied, a new trade is initiated by buying 2 points per point at the market price.
  • Re-Entry Condition: The second IF statement adds complexity by introducing a time delay and a price movement condition for re-entry. It checks if:
    • More than 20 bars have passed since the last trade (BARINDEX-TRADEINDEX(1) > 20).
    • The current closing price has moved more than 20 points from the last trade price (Close-TRADEPRICE(1) > 20).
    • A long position is currently open in the market (LongOnMarket).

    If all these conditions are met, another trade is placed to buy 2 points per point at the market price.

This example is useful for understanding how to control trading actions with both time and price conditions, potentially increasing the strategy’s effectiveness by avoiding immediate re-entry into a losing position.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/waiting-after-a-loss/#post-26739

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...