Hi.
I need help to make this possible for a 6min-algo
Pause system X time after Y losses
X= variable in minutes , bars or hours
Y=variable count of losses (1-10)
This one did not work:
positionperf2 = positionperf(1)
graph positionperf
graph positionperf(1) coloured (255,0,0)
if positionperf2<positionperf2[1] then
if (positionperf2 > 0) then
lossrunno = 0
buysignal = barindex
winrunno = (winrunno + 1)
endif
if (positionperf2 < 0) then
winrunno = 0
lossrunno = (lossrunno + 1)
endif
endif
if lossrunno=1 then
distancebuysignal=(Barindex-buysignal)
endif
if lossrunno=1 and (distancebuysignal > x) then
lossrunno=0
endif
if (lossrunno=0) then
If MyConditionLong then
Buy PositionSize CONTRACTS AT MARKET
SET STOP %LOSS sll
ENDIF
If MyConditionShort then
sellshort PositionSize CONTRACTS AT MARKET
SET STOP %LOSS sls
ENDIF
endif
There you go:
ONCE MaxLosses = 2 //Y losses
ONCE PauseBars = 30 //X bars to pause
ONCE Losses = 0
ONCE BarStart = 0
MyLongConditions = close CROSSES OVER average[20,0](close) AND Not OnMarket
MyShortConditions = close CROSSES UNDER average[20,0](close) AND Not OnMarket
IF StrategyProfit > StrategyProfit[1] THEN
Losses = 0
BarStart = 0
ELSIF StrategyProfit < StrategyProfit[1] THEN
Losses = Losses + 1
IF Losses = MaxLosses THEN
BarStart = BarIndex
Losses = 0
ENDIF
ENDIF
IF (BarIndex - BarStart) >= PauseBars THEN
BarStart = 0
ENDIF
IF MyLongConditions AND BarStart = 0 THEN
BUY 1 CONTRACT AT MARKET
ENDIF
IF MyShortConditions AND BarStart = 0 THEN
SELLSHORT 1 CONTRACT AT MARKET
ENDIF
SET STOP pLOSS 100
SET TARGET pPROFIT 300
Thanks robberto. it seems to work on the trades of same direction but not the oposit direction:
See attached
ONCE MaxLosses = 1 //Y losses
ONCE PauseBars = x //X bars to pause
ONCE Losses = 0
ONCE BarStart = 0
IF StrategyProfit > StrategyProfit[1] THEN
Losses = 0
BarStart = 0
ELSIF StrategyProfit < StrategyProfit[1] THEN
Losses = Losses + 1
IF Losses = MaxLosses THEN
BarStart = BarIndex
Losses = 0
ENDIF
ENDIF
IF (BarIndex - BarStart) >= PauseBars THEN
BarStart = 0
ENDIF
if BarStart =0 then
If MyLongCond then
Buy PositionSize CONTRACTS AT MARKET
SET STOP %LOSS sll
ENDIF
If MyShortCond then
sellshort PositionSize CONTRACTS AT MARKET
SET STOP %LOSS sls
ENDIF
endif
I even tried this:
If MyLongCond and BarStart =0 then
Buy PositionSize CONTRACTS AT MARKET
SET STOP %LOSS sll
ENDIF
If MyShortCond and BarStart =0 then
sellshort PositionSize CONTRACTS AT MARKET
SET STOP %LOSS sls
ENDIF
This one works like a charm:
ONCE MaxLosses = 3 //Y losses
ONCE PauseBars = 30 //X bars to pause
ONCE Losses = 0
ONCE BarStart = 0
MyLongCond = close CROSSES OVER average[20,0](close) AND Not OnMarket
MyShortCond = close CROSSES UNDER average[20,0](close) AND Not OnMarket
IF StrategyProfit > StrategyProfit[1] THEN
Losses = 0
BarStart = 0
ELSIF StrategyProfit < StrategyProfit[1] THEN
Losses = Losses + 1
IF Losses = MaxLosses THEN
BarStart = BarIndex
Losses = 0
ENDIF
ENDIF
IF (BarIndex - BarStart) >= PauseBars THEN
BarStart = 0
ENDIF
if BarStart = 0 then
If MyLongCond then
Buy 1 CONTRACTS AT MARKET
SET STOP %LOSS 0.1
ENDIF
If MyShortCond then
sellshort 1 CONTRACTS AT MARKET
SET STOP %LOSS 0.1
ENDIF
endif
graph Losses
graph BarStart
graph StrategyProfit < StrategyProfit[1] coloured("Red")
graph StrategyProfit > StrategyProfit[1] coloured("Green")