APIBridge allows you three levels of risk management, for instance you can see the details here. Although we cannot emphasize more how risk management is essential for profitable trading. However in this article, we will show you how very simple risk management improves profitability using back-testing in TradingView.
Firstly start with any strategy in Tradingview public library, or built-ins library. Similarly for illustration purpose, we are using the built-in Channel Breakout Strategy.
Therefore after applying strategy on chart, click on Strategy Tester to see its performance. In the screenshot below, we can see performance on 3-minute.
Here we can see the equity and draw down curve , our strategy is having accuracy of 39.08%, we need to consider other factors like avg profit per trade. You can see back testing period and trades taken in “LIST TRADES”.
Since our strategy is applied on 3 min chart trading view provides approximately 3 to 5 months back testing (it depend on number of executed trades). In conclusion performance summary can be seen by how our strategy has performed in long side, short side,max profitable trade,max losing trade and many factors.
Therefore we found some possible risky trades in back testing. Our strategy is not intraday; In addition to that some of the disadvantages are:
- Back test shows calculations that we are short on positional basis and it is not possible to be short in equity in positional basis unless you have holdings or you trade in futures.
- Also over night positions may be more risky as we cant restrict the loss.
APPLYING RISK MANAGEMENT
Let us see the effect on this strategy by making it intraday and adding custom stop loss. To do this go to the strategy and click source code, make a copy and use this code.
We add most simple risk management conditions in above code:
- All entry’s are restricted to 9:20 am to 14:30 pm.
- All positions are made intraday so it should square off between 3:20 pm to 3:25 pm.
- Stop loss given as input parameter.
Note that all these 3 conditions you can implement in APIBridge without any coding, see here.
New results with risk management can be seen below:
|CHANNEL STRATEGY WITHOUT RISK MANAGEMENT||CHANNEL STRATEGY WITH RISK MANAGEMENT|
|BACK TEST PERIOD: 5 months CHART TIME FRAME : 3 min||BACK TEST PERIOD: 5 months CHART TIME FRAME :3 min|
|NUMBER OF TRADES: 1026 POINTS PROFIT: 4388 POINTS||NUMBER OF TRADES: 901 POINTS PROFIT: 4610 POINTS|
|AVG PROFIT PER TRADE: 4.28||AVG PROFIT PER TRADE: 5.12|
Here is the code used in above example :
/@version=4 strategy("ChannelBreakOutStrategy", overlay=true) length = input(title="Length", type=input.integer, minval=1, maxval=1000, defval=5) upBound = highest(high, length) downBound = lowest(low, length) //time conditions //INTRADAY s=input(title="INTRA DAY TRADE SESSION",type=input.session,defval="0915-1450") st=time(timeframe.period,s) e=input(title="END SESSION",type=input.session,defval="1515-1520") et=time(timeframe.period,e) symbol=syminfo.ticker //trading custom quantities q=input(title="Trade Quantity",defval=1) q1=1 if(strategy.position_size!=0) q1:=q*2 if(strategy.position_size==0) q1:=q m=" :SYMBOL:"+syminfo.ticker+" :QTY:"+tostring(q1) m1=" :SYMBOL:"+syminfo.ticker+" :QTY:"+tostring(q) if (not na(close[length])) //Restricting entry time strategy.entry("LE", strategy.long, stop=upBound + syminfo.mintick,comment="TYPE:LE"+m,when=st) strategy.entry("SE", strategy.short, stop=downBound - syminfo.mintick,comment="TYPE:SE"+m,when=st) //adding stoploss and target option ut=input(defval=false,title="USE TARGET") us=input(defval=false,title="USE STOPLOSS") tar=input(defval=10.0,title="TARGET IN RS") stop=input(defval=7.0,title="STOP LOSS IN RS") tar:=tar/syminfo.mintick stop:=stop/syminfo.mintick if(ut==true and us==false) strategy.exit(id="LX",from_entry="LE",profit=tar,comment="TYPE:LX"+m1) strategy.exit(id="SX",from_entry="SE",profit=tar,comment="TYPE:SX"+m1) if(us==true and ut==false) strategy.exit(id="LX",from_entry="LE",loss=stop,comment="TYPE:LX"+m1) strategy.exit(id="SX",from_entry="SE",loss=stop,comment="TYPE:SX"+m1) if(ut==true and us==true) strategy.exit(id="LX",from_entry="LE",profit=tar,loss=stop,comment="TYPE:LX"+m1) strategy.exit(id="SX",from_entry="SE",profit=tar,loss=stop,comment="TYPE:SX"+m1) //ADDING SQUAREOFF TIME strategy.close(id="LE",when=et,comment="TYPE:LX"+m1) strategy.close(id="SE",when=et,comment="TYPE:SX"+m1)