LinkParticipant
Senior
Wow, the drawdown code is good, but it hasn’t had the desired effect.
Another question:
If in the last 10 operations the winrate is higher than 80%, operate with the usual amount of € pip.
If in the last 10 trades the winrate is less than 80%, trade with half the usual amount of € pip.
I need code … thanks!
There you go:
DEFPARAM CumulateOrders = false
ONCE AllTrades = 0
ONCE WinningTrades = 0
ONCE InitialLots = 2
ONCE LotSize = InitialLots
ONCE Trades = 10 //10 trades in a row over 80%
MyGain = StrategyProfit
// tally each trade
t1 = OnMarket AND Not OnMarket[1] //it's a new trade
t2 = Not OnMarket AND Not OnMarket[1] AND MyGain <> MyGain[1] //detect any 1-bar trade
t3 = ShortOnMarket AND LongOnMarket[1] //it's a new trade (S & R)
t4 = ShortOnMarket[1] AND LongOnMarket //it's a new trade (S & R)
AllTrades = AllTrades + ((t1 OR t2 OR t3 OR t4) AND IsLastBarUpdate)
// tally winning trades
IF MyGain > MyGain[1] THEN
WinningTrades = WinningTrades + 1
ENDIF
// calculate % of winning trades
IF AllTrades > Trades THEN
WinPerCent = WinningTrades * 100 / AllTrades
IF summation[Trades](WinPerCent > 80) = Trades THEN
LotSize = InitialLots //restore initial lotsize
ELSE
LotSize = InitialLots * 0.5 //halve lotsize
ENDIF
ENDIF
ONCE Periods = 10
MyLongConditions = close crosses over average[Periods] AND Not OnMarket
MyShortConditions = close crosses under average[Periods] AND Not OnMarket
IF MyLongConditions THEN
BUY LotSize CONTRACTS AT Market
ELSIF MyShortConditions THEN
SELLSHORT LotSize CONTRACTS AT Market
ENDIF
set target pprofit 200
set stop ploss 2000
Link to Roberto code above added as Log 297 here …
Snippet Link Library
LinkParticipant
Senior
What if we did the same but with an ATR?
If strategyprofit is above ATR, operate with the usual € pip.
If strategyprofit is below ATR, trade with half a € pip.
It’s impossible to compare STRATEGYPROFIT to ATR, they are two different scales.
STRATEGYPROFIT can range from -100K to +100K (or even more), while ATR is a price range (could be from 0 to a few hundreds).
Even if applied to STRATEGYPROFIT, it can be compared to itself, as it normally cannot be compared to CLOSE.