I am working on a strategy to enter a long position once the price drops by -20 ticks from the the highest bar. I have done some working on it and accomplished to enter the long position but there is an error it only enters the long position but when that bar closes not when the condition in the strategy meets.
I'm encountering an issue with the entry into the long position. It seems to be entering at -30 ticks, regardless of the condition I set.
For instance, I set the condition to -20 ticks as expected, but it enters at -30 ticks. I also tried various tick numbers like -24, -26, -28, and -30, but the entry still occurs after -30 ticks. When I set numbers greater than -30 (e.g., -36, -38, -40), it doesn’t enter the long position at all. My point is that the system should allow entry when any desired number is set in the condition, whether it’s -20, -25, -35, etc.
Below are the steps i followed to build the strategy:
In the first condition set, set the current high series to the value of the previous bar (to carry it forward). Don't add any conditions to this set.
In the second condition set, add a condition comparing Misc > Current bar, select Equals as the center comparison operator, on the right select Misc > Numeric value > 1.
In the actions, select Misc > Set CurrentHighSeries, click 'set' in the CurrentHighSeries field, select Price > High.
In the third condition set, add a condition comparing the Price > High with bars ago 1, Greater, Price > High with bars ago 2.
In the same (third) condition set, add another condition comparing Price > High with bars ago 0, Greater, Price > High with bars ago 1
In the actions, select Misc > Set CurrentHighSeries, click 'set' in the CurrentHighSeries field, select Price > High.
In the forth condition set, add a condition comparing the Price > Close, select Less as the center comparison operator, on the right select Misc > Custom Series > CurrentHighSeries, and set the Offset Type to Ticks and use -20 as the Value.
Add an action, select Order management > Enter long position
and here is my code:
{
public class Buyafterdrop : Strategy
{
private Series<double> CurrentHighSeries;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Strategy here.";
Name = "Buyafterdrop";
Calculate = Calculate.OnBarClose;
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;
IsExitOnSessionCloseStrategy = true;
ExitOnSessionCloseSeconds = 30;
IsFillLimitOnTouch = false;
MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
OrderFillResolution = OrderFillResolution.Standard;
Slippage = 0;
StartBehavior = StartBehavior.WaitUntilFlat;
TimeInForce = TimeInForce.Gtc;
TraceOrders = false;
RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
StopTargetHandling = StopTargetHandling.PerEntryExecution;
BarsRequiredToTrade = 20;
// Disable this property for performance gains in Strategy Analyzer optimizations
// See the Help Guide for additional information
IsInstantiatedOnEachOptimizationIteration = true;
TargetPrice = 1;
}
else if (State == State.Configure)
{
}
else if (State == State.DataLoaded)
{
CurrentHighSeries = new Series<double>(this);
SetProfitTarget(CalculationMode.Ticks, 28);
SetStopLoss(CalculationMode.Ticks, 40);
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 2)
return;
CurrentHighSeries[1] = 0;
// Set 2
if (CurrentBars[0] == 1)
{
CurrentHighSeries[0] = High[0];
}
// Set 3
if ((High[1] > High[2])
&& (High[0] > High[1]))
{
CurrentHighSeries[0] = High[0];
}
// Set 4
if (Close[0] < (CurrentHighSeries[0] + (-20 * TickSize)) )
{
EnterLong(2, "");
}
}
}
}
Thanks!

. This means that all conditions are only checked when each bar completes, rather than intrabar
Comment