Hello, I've been stuck on calculating order quantities for the past 2 weeks. I wrote this simple algorithm that buys NZDUSD every weekday at 10am, placing a stoploss and takeprofit in a 1:2 ratio and waiting until either is hit. The error I get is that instead of algorithm losing only 2% per trade or winning 4%, Average Loss and Average win are very varying. 

Formula for calculating required leverage: 

leverage = 0.02 * self.Securities["NZDUSD"].Close / (self.atr.Current.Value * self.ATRfactor)
where: (self.atr.Current.Value * self.ATRfactor) is calculating stoploss distance from current price using ATR
Formula I derived for calculating order quantity is: Q = (leverage * 1000) / self.Securities["NZDUSD"].Close

where RISKED_AMOUNT = 2% * SetCash(1000) = 0.02 * 1000$ = 20$

If someone could tell me what piece of puzzle I'm missing, I'd be very grateful. 

 

Edit: In case I wasn't clear, I don't need help with strategy, I need help figuring out why quantity calculation which works for me on paper doesn't work in QC.