Hi all,
I feel like this should be an easy one but seeing as I’m normally fairly adept on PRT I think I’m either massively overthinking it or its just impossible (ha!) So here goes;
I have a trend following system that on any given day produces trade results heavily inline with previous trades of the same day (Z-score of -31!). Great when it’s profiting, awful when its losing. To combat this I want to stop the system trading for the rest of that trading day (only) after an arbitrary number of losing trades (we’ll use 3 but once I have the code I’ll clearly refine this).
I’m assuming the ideal code would look something like this;
If (TradeDate[Position[3]]=Today and PositionPerf[3]<0)
and (TradeDate[Position[2]]=Today and PositionPerf[2]<0)
and (TradeDate[Position[1]]=Today and PositionPerf[1]<0) Then
EndIf
The issue is of course, that neither a TradeDate function, or Position/Trade number function exists (unless I just can’t find it?). I can of course figure out how to stop it running based on the past three trades being losing trades, however the important part is these trades are only relevant if on the current trading day.
Any ideas or workarounds?
TIA!
OK.. so having just typed that out I’ve thought of a not-that-great workaround..
Noting this is for US markets and 10min candles, so 39 candles per day, I guess I could do the following;
IF (TradeIndex[3]<40 and PositionPerf[3]<0)
and (TradeIndex[2]<40 and PositionPerf[2]<0)
and (TradeIndex[1]<40 and PositionPerf[1]<0) Then
EndIf
Would that work? Can anyone think of any improvements?
TIA!
This code will limit losses (defaults to 3):
ONCE MaxLosingTrades = 3
ONCE Tally = 0
IF IntraDayBarIndex = 0 THEN
Tally = 0
ENDIF
IF StrategyProfit < StrategyProfit[1] THEN
Tally = Tally + 1
ELSIF StrategyProfit > StrategyProfit[1] THEN
Tally = 0
ENDIF
MyLongConditions = close CROSSES OVER Average[20,0](close)
IF MyLongConditions AND Not OnMarket AND (Tally < MaxLosingTrades) THEN
BUY 1 Contract at Market
SET STOP pLOSS 30
SET TARGET pPROFIT 200
ENDIF
//graph Tally
//graph (Tally = MaxLosingTrades) coloured(255,0,0,255)
Comment out line 9 to not require consecutive losses.