Daily loss limit and weekly number of losing trades coding help

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #244172 quote
    tom.clark
    Participant
    New

    I would like to write a piece of code that both limits daily losses to £100 while also capping weekly losses at three trades, at which point the system temporarily stops before resetting and trading the following week. Any help would be greatly appreciated?

    Thankyou

    Tom

    #244253 quote
    robertogozzi
    Moderator
    Master

    There you go:

    ONCE DayGain    = 0
    ONCE WeekGain   = 0
    ONCE DayON      = 1
    ONCE WeekON     = 1
    ONCE WeekLosses = 0
    IF (StrategyProfit - DayGain) <= -100 THEN
       DayON      = 0
       DayGain    = StrategyProfit
       WeekLosses = WeekLosses + 1
       IF WeekLosses = 3 THEN
          WeekON = 0
       ENDIF
    ENDIF
    IF OpenDay <> OpenDay[1] THEN
       DayGain = StrategyProfit
       DayON   = 1
    ENDIF
    IF OpenDayOfWeek < DayOfWeek[1] THEN
       WeekON     = 1
       WeekLosses = 0
    ENDIF
    Sma = average[20,0](close)
    IF DayON AND WeekON AND Not OnMarket THEN
       IF close CROSSES OVER Sma THEN
          BUY 1 CONTRACT AT MARKET
       ELSIF close CROSSES UNDER Sma THEN
          SELLSHORT 1 CONTRACT AT MARKET
       ENDIF
       SET STOP   %LOSS   0.2
       SET TARGET %PROFIT 0.5
    ENDIF
    //graph DayON  coloured("Red")
    //graph WeekON coloured("Blue")
    //graph WeekLosses
    //graph StrategyProfit
    Iván González and tom.clark thanked this post
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

Daily loss limit and weekly number of losing trades coding help


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
tom.clark @tom-clark Participant
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by robertogozzi
11 months, 4 weeks ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 02/21/2025
Status: Active
Attachments: No files
Logo Logo
Loading...