Risk and Money Management errors

Forums ProRealTime English forum ProOrder support Risk and Money Management errors

Viewing 15 posts - 1 through 15 (of 27 total)
  • #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
    ENDIF

    ELSIF MyShortConditions THEN
    IF BandwidthCentage > 2.00 THEN

    SELL 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 Atr

    SET TARGET PROFIT Atr * 1.8

    SET TARGET PROFIT Atr * 1.8

    #178014

    Comment out text lines like “—-Backtest——-” and “——–Risk_Money_Management———-“.

     

    #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
    ENDIF

    ELSIF MyShortConditions THEN
    IF BandwidthCentage > 2.00 THEN

    SELL 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 Atr

    SET TARGET PROFIT Atr * 1.8

    SET TARGET PROFIT Atr * 1.8

    #178075

    You  have to define the CAPITAL you plan to use for your strategy. Add this line BEFORE the start of the Risk Money Management:

    10000 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.

     

     

    #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.

     

    #178122

    This code works the same with and without Risk Managent:

    Uncomment line 25 to disable Risk Management.

    #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.

     

     

     

    #178227

    You 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.

     

     

    #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?

     

    #178379

    Hello , 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.

     

    #178386

    Is 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?

    #178387

    Attached is what I see on backtest of your Algo (spread = 2)

    #178390

    The 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?

     

     

    #178423

    GraHal

    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?

    #178424

    Attached 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.

     

Viewing 15 posts - 1 through 15 (of 27 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login