I am trading on a 3minute time frame and I am using a third party script that provides trend lines. Unfortunately, the third party script is not providing any way I can get data from their trend lines. Basically, I want to do a strategy that will enter a long position and create a profit target and stop loss target of 5 ticks at the open of the next candle after I start the strategy.
For example: I am trading on the 3minute time frame, the current bar has 30second before it closes and the next candle begins. With 30seconds left, I decide that I want to enter long and create a profit target and stop loss of 5ticks. So I want to enable the strategy manually under the "strategies" tab and it will enter the long at the open of the next candle.
I though the below code will work, but it did not work.
namespace NinjaTrader.NinjaScript.Strategies
{
public class FIVEtickLong : Strategy
{
int x=0;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Strategy here.";
Name = "FIVEtickLong";
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;
}
else if (State == State.Configure)
{
SetProfitTarget(CalculationMode.Ticks, 5);
SetStopLoss(CalculationMode.Ticks, 5);
}
}
protected override void OnBarUpdate()
{
if (CurrentBars[0] < 1)
return;
if (BarsInProgress != 0)
{
return;
}
else{
EnterLong(Convert.ToInt32(DefaultQuantity), "");
}
}
}
}
}
Comment