I'm working on strategy with the next logic:
According the defined conditions I submit EnterLongLimit with defined price.
On every new bar close I check the change of desired EnterLongLimit price
and if it is different from previously submitted price - I change EnterLongLimit order price by submitting new order with the same name.
After entry order filled I submit ExitLongLimit and manage it in the same manner -
if some values change on new bar, I change ExitLongLimit order price.
Stop market order is activated by bar close below some value.
I'm testing strategy part by part on sim account running it on small timeframe
Generally first part of code is next:
namespace NinjaTrader.NinjaScript.Strategies
{
public class SampleCancelOrder : Strategy
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"";
Name = "checkit";
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;
}
}
protected override void OnBarUpdate()
{
if (CurrentBar < BarsRequiredToTrade)
return;
if (Position.MarketPosition == MarketPosition.Flat)
{
if (Condition == true)
{
EnterLongLimit(0, true, 1, LimitPrice, "long limit entry"); //Limit price is lower that current
}
else if (Condition[0] != Condition[1])
{
EnterLongLimit(0, true, 1, NewLimitPrice, "long limit entry"); //Limit price is lower that current
}
}
}
}
Here I got the next issue:
starting the strategy it opens fantom position at the defferent from current price and doesn't submit any realtime order.
I suppose that it must hold EnterLongLimit order with the defined price (lower than current) and change it on every new bar.
But nothing happens.
Please assist
Regards
Comment