I need my strategy to define the Quantity for each trade as function of capital at risk (e.i. 1%) and the stop loss I apply (e.i. 0.05 ticks) on each trade in live trading. I am wondering if this code could work:
#region Variables
accountSize = 10000; // initial capital
stopLoss = 0.050; // stop loss in tick size
#endregion
On BarUpdate()
If(Close[0] > Close[1])
{
if(!Historical) AccountSize= GetAccountValue(AccountItem.CashValue) == 0 ? AccountSize : GetAccountValue(AccountItem.CashValue);
positionSize = accountSize x 0.01 / stopLoss;
EnterLongLimit(0,false,(double)positionSize,Low[0],"Buy");
}
Thanks

Comment