I've just started working with NinjaScript to build an automated trading bot for a strategy I've been trading manually. I have some programming experience, years ago, and I figured the easiest way to jump start this project was to construct as much as I could of the strategy in the Strategy Wizard, then when I hit the limits of what I can do in the Wizard, unlock the code and program it manually from there.
I'm trying to add a feature whereby my strategy keeps a certain number of bars between trade entries.
I tried doing this by adding this condition in the Strategy Wizard:
BarsSinceEntry() >= EntryDistance
where EntryDistance is a user defined input with default value 6.
This resulted in the following code:
protected override void OnBarUpdate()
{
// Condition set 1
if (EMA(MA1Shortperiod)[0] > EMA(MA1Longperiod)[0]
&& RSI(RSIperiod, 3).Avg[0] > RSIbuylevel
&& ToTime(Time[0]) > ToTime(9, 0, 0)
&& ToTime(Time[0]) < ToTime(13, 59, 0)
&& Position.MarketPosition != MarketPosition.Short
&& BarsSinceEntry() >= EntryDistance)
{
EnterLongLimit(DefaultQuantity, Close[0], "LongEntry"); }
So, what is the right way to do this?
Thanks
Phil

Comment