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