Stop trading for the day if losses are too big without QUIT

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #196488 quote
    Raspberri
    Participant
    New

     

    Hi all, I am looking for a way to temporarily stop the strategy from trading once losses have reached a certain amount for a certain amount of time without using QUIT and having to restart the strategy again. The strategy runs on a 5min timeframe.

    The workaround I was trying was to use was to go onto a higher timeframe of 1h and add strategyprofit for the last 3 hours and make “AND NOT pause” a condition to open trades. If strategy profit for the last 3 bars is below a certain number, e.g. -500, it should not open new positions. In my mind, it should then start trading again after a while since strategyprofit[3], [2] and [1] should all be 0.

     

    However, this does not work.

     

    Does anyone know how to solve the issue?

     

    Thanks!

    <!–more–>

    timeframe(1 hour, updateonclose)
    
    SP3 = strategyprofit[3]
    SP2 = strategyprofit[2]
    SP1 = strategyprofit[1]
    SumSP = p1 + p2 + p3
    pause = (SumSP <= -500)
    
    timeframe(default)

     

    <!–more–>

    #196510 quote
    robertogozzi
    Moderator
    Master

    Try this one (it will pause 1 hour after a big loss):

    DEFPARAM CumulateOrders = False
    // 
    timeframe(1 hour, updateonclose)
    ONCE MyProfit = 0
    pause = 0
    IF Not OnMarket THEN
       MyProfit = StrategyProfit
       SumSP    = StrategyProfit - MyProfit[1]
       pause = (SumSP <= -500)
    ENDIF
    //
    timeframe(default)
    IF close CROSSES OVER average[200] AND Not OnMarket AND Not Pause THEN
       BUY AT MARKET
    ENDIF
    SET TARGET pPROFIT 50
    SET STOP   pLOSS   20
    graph pause
    graph SumSP
    Raspberri thanked this post
    #196516 quote
    GraHal
    Participant
    Master

    Link to above added as Log 325 here …

    Snippet Link Library

    robertogozzi and Andres thanked this post
    #196618 quote
    Raspberri
    Participant
    New

    This is exactly what I was looking for – thanks! 🙂

    #196619 quote
    Raspberri
    Participant
    New

    Just a quick question for my understanding: Why are we subtracting MyProfit[1] instead of adding it? If MyProfit is negative, e.g. -100, would using subtraction not lead to SumSP be “higher” than it actually is?

    Example:

    • StrategyProfit of previous 1h close was -500 -> MyProfit = StrategyProfit[1] = -500
    • StrategyProfit = 0
    • SumSP = 0 – -500 = 500 instead of -500?
    #196628 quote
    robertogozzi
    Moderator
    Master

    The two last GRAPH lines will show the answer.

    Raspberri and Andres thanked this post
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.

Stop trading for the day if losses are too big without QUIT


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Raspberri @raspberri Participant
Summary

This topic contains 5 replies,
has 3 voices, and was last updated by robertogozzi
3 years, 7 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 06/30/2022
Status: Active
Attachments: No files
Logo Logo
Loading...