Risk and Money Management errors
Forums › ProRealTime English forum › ProOrder support › Risk and Money Management errors
- This topic has 26 replies, 4 voices, and was last updated 3 years ago by jkadda.
-
-
09/21/2021 at 6:58 AM #178010
Hello,
I have added risk and money management to my strategy as shown below but which is resulting in error message attached .
Kindly help to fix the errors , or it may be how i arrange the codes or something else.
—-Backtest——-
MyLongConditions = close CROSSES OVER BollingerDOWN[20]
MyShortConditions = close CROSSES UNDER BollingerUP[20]
MinWidth = 0.006 //max percentage of distance between the two bands
MyBandWidth = BollingerBandWidth[20](close)p = 20
upper = bollingerup[p]
lower = bollingerdown[p]
middle = average[p]
BandwidthAbs= upper-lower
BandwidthCentage= (BandwidthAbs/middle)*100
//Bandwidth% should be adjusted based on securities and timeframes
IF MyLongConditions THEN
IF BandwidthCentage > 0.00 THEN
BUY 1 CONTRACTS AT MARKET
ENDIFELSIF MyShortConditions THEN
IF BandwidthCentage > 2.00 THENSELL AT MARKET
ENDIF
ENDIF
——–Risk_Money_Management———-
// DrawDown calculation
ONCE MinPoint = Capital
ONCE MaxPoint = 0
ONCE MaxRU = 0
ONCE MaxDD = 0
IF StrategyProfit <> 0 THEN
Equity = Capital + StrategyProfit
TempProfit = PositionPerf * PositionPrice / PipSize
TempEquity = Equity + TempProfit
MaxPoint = max(MaxPoint,TempEquity)
DD = MaxPoint – TempEquity
MaxDD = max(MaxDD,DD)
ENDIF
//——————————————
// LARRY WILLIAMS’ formula (+margin)
MinSize = 0.5 //Minimum lot size allowed
Margin = high / 100 * 0.5 //Margin required 0.5%
Risk = 5 //Risk per trade 2%
TempLotSize = max(MinSize,(Equity * Risk / 100) / (MaxDD + Margin))
LotSize = round((TempLotSize * 10) – 0.5) / 10 //only 1 decimal digit allowed
//——————————————
// ATR Profit Target & Stop Loss
Atr = AverageTrueRange[14](Close)
SET STOP LOSS AtrSET TARGET PROFIT Atr * 1.8
SET TARGET PROFIT Atr * 1.8
09/21/2021 at 7:14 AM #178014Comment out text lines like “—-Backtest——-” and “——–Risk_Money_Management———-“.
09/21/2021 at 1:58 PM #178067@Rotertogozzi.
Thanks very much for the information, i have done exactly as you directed but still having the attached error relating to the variable capital.
Hope you can go through the entire code ( especially the Risk management section) to help fix the issues.
//—-Backtest——-
MyLongConditions = close CROSSES OVER BollingerDOWN[20]
MyShortConditions = close CROSSES UNDER BollingerUP[20]
MinWidth = 0.006 //max percentage of distance between the two bands
MyBandWidth = BollingerBandWidth[20](close)p = 20
upper = bollingerup[p]
lower = bollingerdown[p]
middle = average[p]
BandwidthAbs= upper-lower
BandwidthCentage= (BandwidthAbs/middle)*100
//Bandwidth% should be adjusted based on securities and timeframes
IF MyLongConditions THEN
IF BandwidthCentage > 0.00 THEN
BUY 1 CONTRACTS AT MARKET
ENDIFELSIF MyShortConditions THEN
IF BandwidthCentage > 2.00 THENSELL AT MARKET
ENDIF
ENDIF
//——-Risk_Money_Management———-
// DrawDown calculation
ONCE MinPoint = Capital
ONCE MaxPoint = 0
ONCE MaxRU = 0
ONCE MaxDD = 0
IF StrategyProfit <> 0 THEN
Equity = Capital + StrategyProfit
TempProfit = PositionPerf * PositionPrice / PipSize
TempEquity = Equity + TempProfit
MaxPoint = max(MaxPoint,TempEquity)
DD = MaxPoint – TempEquity
MaxDD = max(MaxDD,DD)
ENDIF
//——————————————
// LARRY WILLIAMS’ formula (+margin)
MinSize = 0.5 //Minimum lot size allowed
Margin = high / 100 * 0.5 //Margin required 0.5%
Risk = 5 //Risk per trade 2%
TempLotSize = max(MinSize,(Equity * Risk / 100) / (MaxDD + Margin))
LotSize = round((TempLotSize * 10) – 0.5) / 10 //only 1 decimal digit allowed
//——————————————
// ATR Profit Target & Stop Loss
Atr = AverageTrueRange[14](Close)
SET STOP LOSS AtrSET TARGET PROFIT Atr * 1.8
SET TARGET PROFIT Atr * 1.8
09/21/2021 at 5:54 PM #178075You have to define the CAPITAL you plan to use for your strategy. Add this line BEFORE the start of the Risk Money Management:
1ONCE Capital = 1000010000 is just an example, you have to replace it with the amount that you really would invest to trade this code on a real account.
You can start with a large amount (you can even write 100K or 100M), the reduce it to a correct size after finding out the actual DrawDown.
09/21/2021 at 10:50 PM #178080@Rotertogozzi.,
I have done exactly as you have instructed, please see attached backtest results Before and After adding the Risk management.
Am not able to analyse the results in terms of whether there is improvement or not.
I need your help.
regards.
09/22/2021 at 3:55 PM #178122This code works the same with and without Risk Managent:
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556//——-Risk_Money_Management———-// DrawDown calculationONCE Capital = 10000ONCE MinPoint = CapitalONCE MaxPoint = 0ONCE MaxRU = 0ONCE MaxDD = 0ONCE LotSize = 1IF StrategyProfit <> 0 THENEquity = Capital + StrategyProfitTempProfit = PositionPerf * PositionPrice / PipSizeTempEquity = Equity + TempProfitMaxPoint = max(MaxPoint,TempEquity)DD = MaxPoint - TempEquityMaxDD = max(MaxDD,DD)//——————————————// LARRY WILLIAMS’ formula (+margin)MinSize = 1 //Minimum lot size allowedMargin = high / 100 * 0.5 //Margin required 0.5%Risk = 5 //Risk per trade 2%TempLotSize = max(MinSize,(Equity * Risk / 100) / (MaxDD + Margin))LotSize = round((TempLotSize * 10) - 0.5) / 10 //only 1 decimal digit allowedLotSize = max(MinSize,LotSize)ENDIF//LotSize = 1//——————————————//—-Backtest——-p = 20MyLongConditions = close CROSSES OVER BollingerDOWN[p]MyShortConditions = close CROSSES UNDER BollingerUP[p]//MinWidth = 0.01 //max percentage of distance between the two bandsMyBandWidth = BollingerBandWidth[p](close)upper = bollingerup[p]lower = bollingerdown[p]middle = average[p]BandwidthAbs= upper-lowerBandwidthCentage= (BandwidthAbs/middle)*100//Bandwidth% should be adjusted based on securities and timeframes// ATR Profit Target & Stop LossAtr = AverageTrueRange[14](Close)IF MyLongConditions AND Not OnMarket AND BandwidthCentage > 2.00 THENBUY LotSize CONTRACTS AT MARKETSET STOP LOSS AtrSET TARGET PROFIT Atr * 1.8//SET TARGET PROFIT Atr * 1.8ENDIFIF MyShortConditions AND LongOnMarket AND BandwidthCentage > 2.00 THENSELL AT MARKETENDIF////graph Atr//graph Atr * 1.8//graph StrategyProfit//graph BandwidthCentage//graph LotSize//graph MyLongConditionsUncomment line 25 to disable Risk Management.
09/23/2021 at 12:43 PM #178221@Rotertogozzi
Thanks, i have run the codes in previous message but it appears to give results far worse that what i initially reported about.
Please have a look as attached.
Also is tis possible you explain what i should be expecting the metrics and performance to be after implementing Risk and money management to the strategy.
09/23/2021 at 2:04 PM #178227You don’t need to post again the pics you had already posted. Posting them twice won’t help.
The risk management code simply calculates the number of lots you can trade.
It doesn’t add anything to the conditions to enter and exit a trade. The metric are a calculation of the number of lots you can trade according to:
- your capital
- your risk
- drawdown.
09/23/2021 at 2:40 PM #178233@Rotertogozzi
Thanks very much, but you appear to suggest that i should not pay attention to the backtest results. If that is the case then how you a trader know whether his strategy’s performance is acceptable or not.
In other words if my strategy performance was 100% say for winning, but after adding lot size , capital, risks and drawdown the performance now drops to as low as 35% and drawdown also dropped massively based on backtest results wbat explanation can be given to this scenario?
Is it advisable to ignore these inconsistencies and go ahead with live trading?
09/25/2021 at 1:01 PM #178379Hello , please i will be most grateful to have response to the issues i have explained in previous messages.
I have been doing a lot of googling and research but found no answers and looks as if am completely standing still now.
I urgently need to continue , i dont want to abandon the strategy after putting in so much.
09/25/2021 at 1:23 PM #178386Is it advisable to ignore these inconsistencies and go ahead with live trading?
No, but you can run your Algo on your Demo account under Live running conditions using virtual money.
Have you got / enabled your Demo Account?
09/25/2021 at 1:26 PM #17838709/25/2021 at 2:57 PM #178390The code in you second post was missing the Capital, please add it to make it work and post it again.
I want to test your code exactly as you did. You tested it on AMAZON (alla sessions), 3h TF, 1K units, didn’t you?
09/26/2021 at 8:54 AM #178423GraHal
Please i dont understand your question.
All the screenshots i have been attaching and sending in my messages concerning my strategies and backtesting are all coming from my Demo account, so am a bit confused when you asked “Have you got / enabled your Demo Account?”
Also you seem to agree that it is NOT advisable to ignore these inconsistencies and go ahead with live trading, but the question that still remains is how do we remove the inconsistencies.
Are these inconsistencies general issues with PRT or is just specific to my strategy?
09/26/2021 at 8:59 AM #178424Attached is what I see on backtest of your Algo (spread = 2)
Sorry i dont understand these screenshot, the charts i have been using is different from the one you have. How do i find same chart types and how can i interpret them?
Please can you also go ahead to generate the corresponding backtest for this chart/strategy since the main issues relate to inconsistencies in the backtest results.
Regards.
-
AuthorPosts
Find exclusive trading pro-tools on