Implementing a Trading Halt After a Significant Loss

25 Aug 2018
0 comment
0 attachment

This ProBuilder code snippet demonstrates how to halt trading activities in an automated trading system after incurring a significant loss, specifically a 5% drop in equity. The code uses conditional statements to monitor and update the trading status based on the equity level after each trade.


ONCE BigLoss = 0.95 //5% or more has to be considered a big loss
ONCE TradeOn = 1 //Trading enabled by default at launchtime
ONCE Capital = 10000 //Set your initial capital

IF NOT OnMarket AND OnMarket[1] THEN //When a trade is closed ...
    IF (Capital + StrategyProfit) <= (Capital * BigLoss) THEN //... check if it's a big loss and ...
        TradeOn = 0 //... eventually stop trading
    ENDIF
    Capital = Capital + StrategyProfit //Update your Equity
ENDIF

IF Your_Conditions AND TradeOn AND Not OnMarket THEN
    BUY/SELLSHORT .......
ENDIF

Explanation of the code:

  • Initialization: Three variables are initialized at the start:
    • BigLoss: Set to 0.95, representing a 5% loss threshold.
    • TradeOn: A boolean flag initialized to 1 (true), allowing trading to commence.
    • Capital: Represents the initial capital, set here as 10000.
  • Trade Closure Check: The first IF condition checks if a trade has just closed (i.e., not currently on the market but was on the market in the previous period).
    • If the total equity after the trade (Capital + StrategyProfit) is less than or equal to 95% of the previous capital (indicating a 5% or more loss), the TradeOn flag is set to 0 (false), halting further trading.
    • The capital is then updated by adding the strategy profit or loss from the last trade.
  • Conditional Trading: The second IF condition allows new trades (either buy or sell short) only if the custom conditions (Your_Conditions) are met, trading is enabled (TradeOn is true), and the system is not currently in a trade.

This approach ensures that the trading system pauses operations after a significant loss, potentially safeguarding against further undesirable drawdowns until conditions are deemed favorable again or manual intervention resets the trading flag.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/stay-flat-after-a-big-loss/#post-65637

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