Hi ! what would be the code to be flat after a big loss (like 5%) ?
I started a new topic since your question had nothing to do with FLATAFTER.
To tell your system to stay flat after a big loss (5% in your case) you have to:
- set a variable so that trading is enabled (say TradeOn = 1) and add this condition to Your_Conditions to start a new trade
- set a variable with your initial Equity
- compare the current strategyprofit agains the previous one AFTER exiting a trade (when OnMarket[1] is true while OnMarket is false)
- if the difference is >= -5% you’ll have to set the above said variable TradeOn = 0 so that no more trades are started till you want (you may want to set further conditions to reenable trading)
- update your equity
.
.
ONCE BigLoss = 0.95 //5% or more has to be considered a big loss
ONCE TradeOn = 1 //Trading enabled by default at launchtime
ONCE Capital = 10000 //Set your initial capital
IF NOT OnMarket AND OnMarket[1] THEN //When a trade is closed ...
IF (Capital + StrategyProfit) <= (Capital * BigLoss) THEN //... check if it's a big loss and ...
TradeOn = 0 //... eventually stop trading
ENDIF
Capital = Capital + StrategyProfit //Update your Equity
ENDIF
.
.
IF Your_Conditions AND TradeOn AND Not OnMarket THEN
.
.
BUY/SELLSHORT .......
.
.
ENDIF
.
.
Hi Robertogozzi !
Thank you for your answer,
I think I found simpler in PRT manual :
//x = maximum loss in euros
IF STRATEGYPROFIT <-x
THEN QUIT
ENDIF
and thats it ! The goal was to cut the system alltogether in case of an emergency. I put a fixed value, but I am sure it is possible to put a pourcentage instead, tell me what you think.
Chears !
The code you found is useful when you want to stay flat after a big loss on the whole equity, so that if you earn 7%, then lose 10% you will keep trading.
My code, instead, even if you have earned, say, 30%, once you have a big loss it stops trading, so that you won’t lose all of your profits!
It’s up to you to set your own strategy that best fits you!
Oh ok, this is a smart one, thank you !
We were just discussing something similar to what you have requested on this thread yesterday:
Backtest sorting by lowest drawdown
Capital = 3000
MaxDrawDownPercentage = 66
Equity = Capital + StrategyProfit
MaxDrawdown = Equity * (MaxDrawDownPercentage/100)
IF OnMarket and ((PositionPrice - low)*CountOfPosition) > MaxDrawDown THEN
Quit
ENDIF
Yeeeah ! I love being here, great community !
Talking about snippets, you could add the one for position sizing, I think it was perfected on the Reiner´s Pathfinder thread, and it is great, just an idea…
Hi
irioton
Please could you add the snippet you mention or any other, then the task is shared?
I’m trying to pull together the google sheet so that snippets can be found, sorted and accessed by anybody all in one place.
Thank You
GraHal
@GraHal, thank you. I’ll add something to that sheet as soon as I can!
Okay, will do, right away !
Money management snippet : OK.