I have read a couple other posts on this topic and it seems it is necessary to unlock the code in Strategy Builder and manually enter the code in NinjaScript in order to cause a strategy to not execute a new trade within (n) of bars since the exit of last trade.
I see the example code give in the help section is...
///////////////////////////////
protected override void OnBarUpdate()
{
if (CurrentBar < BarsRequiredToTrade)
return;
// Only enter if at least 10 bars has passed since our last exit or if we have never traded yet
if ((BarsSinceExitExecution() > 10 || BarsSinceE xitExecution() == -1) && CrossAbove(SMA(10), SMA(20), 1))
EnterLong();
}
///////////////////////////////
My question is just where in my unlocked code precisely should this be entered? Along with the other conditions that must be met before my strategy goes long?
Here is the excerpt of my code for my current conditions...
///////////////////////////////////////////////
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 2)
return;
// Set 1
if ((Close[0] > Close[1])
&& (Close[0] > Close[2])
&& (Momentum1[0] > MomentumInt)
&& (Close[1] > Close[2])
&& (Swing1.SwingHigh[0] < (Close[0] + (-8 * TickSize)) )
&& (ChoppinessIndex1[0] < ChoppyEntry))
{
EnterLong(Convert.ToInt32(DefaultQuantity), "");
}
//////////////////////////////////
Would I just add the "&& ((BarsSinceExitExecution() > 10 || BarsSinceE xitExecution() == -1)" after the other conditions in Set 1?
I did try this example but I got errors so not sure if its my syntax or the placement of the code.
If it is too much work to answer this, I understand. Just please direct me to a helpful link that I might learn to understand how to work with NinjaScript better.
Thanks.
Comment