Hello,

 use spspercentofequity  insted of spsshares.
 It will do what you want.

 example:
Setpositionsize(2/(riskinPips*Pointvalue)*MarginDeposit,spspercentofequity); 

--- In [email protected], "dralexchambers" <dralexchamb...@...> wrote:
>
> Hi,
> 
> I am writing some backtesting code and have got a bit stuck on the following:
> 
> I base my position size on the distance from entry to initial stop loss. I 
> use 2% of my total equity on any one trade.
> 
> An example to illustrate:
> 
> Contract Value = $10 per pip (this is GBPUSD)
> 
> Entry = 1.6000
> Stop Loss = 1.5900
> Risk in pips = 100
> 
> Current bar account value = $20000
> I risk 2% of current bar account value on this trade
> 
> Therefore, I would like the number of contracts for this trade to be:
> 
> ($10000*2%) = $200 / risk in pips = 2 / contract value = 0.2 contracts
> 
> How do I set my position size or number of contracts to reflect this in AFL?
> 
> MarginDeposit = 1;
> RoundLotSize = 1;
> TickSize = 0.0001;
> PointValue = 10;
> 
> I have been using SetPositionSize(xxxx, spsShares);   --- but don't know how 
> to access current backtester bar account value for the calculation.
> 
> Thanks!
> Alex
>


Reply via email to