I need help putting together the correct ninjascript for my position sizing concept.
- I would like to use 2% of my account value per trade (see below).
- Divide that amount by the distance to my exit.
- My exit is set at 3x ATR 20 period (see below)
I have highlighted in red where I believe I should be setting the "qtyToTrade".
Please help! Thank you.
double qtyToTrade;
int positionSize;
qtyToTrade = AccountSize * 0.02 / Margin [0];
positionSize = (int)qtyToTrade;
// Condition set 1
if (CrossAbove(Close, MAEnvelopes(1.5, 3, 20).Upper, 1)
&& SMA(10)[0] > SMA(40)[0])
{
EnterLong(positionSize, "enter long");
SetStopLoss(CalculationMode.Price,Position.AvgPric e - ATR(20)[0]*3);
}

, you still have to account for that unlikely boundary condition, where your ATR(20) is zero, in order for your code to be robust.
Comment