Below, I've posted some code, stripped of all the logic to determine trade signals. The trade signal logic is done (as shown in code comment) inside the if(FirstTickOfBar) section. This code basically reverses a position. So, you can see ExitShort() at the top, and EnterLong() at the bottom. Essentially, the only thing in between is setting variable values and checking market position (except for a small bit of calculation for time and a bit of simple math in one line).
Here's the issue: looking at the log, the time between the ExitShort and EnterLong is often anywhere from 5 seconds to 20 seconds. At first I noticed this on live trading with a broker and assumed the issue was a delay in receiving fill/confirmation messages. So, I ran on sim101 and was still getting at least 5 seconds between the two executions.
I went so far as to strip Ninja down to running just a single chart with the one strategy, same result. On sim101 in particular, it seems like the time should be sub one second for such a simple bit of code.
Any ideas or suggestions?
ExitShort();
if (Position.MarketPosition == MarketPosition.Long) // code after doesn't run because flat
if (Position.MarketPosition == MarketPosition.Long) // code after doesn't run because flat
if (FirstTickOfBar)DrawTextFixed("tag1", chartNote, TextPosition.TopRight);
if(Historical) return;
if(CurrentBar < 60 )
return;
// all logic for trade conditions and variables being set here too
if (Position.MarketPosition == MarketPosition.Flat && enterOkay == true)
{
stopControl = true;
entryOffset = entryOffset1;//setting offset variables based on current setup bar type
iniOffset = iniOffset1;
mdOffset = mdOffset1;
oneDone = oneDone1;
if ((tradeCondition) == true && ToTime(Time[0])>=startTime && ToTime(Time[0])< endTime && Math.Abs(Close[2]-Close[1])<2*BarsPeriod.Value*TickSize && Close[0]>= High[1]+ entryOffset*TickSize && tradeLong == true)
{
orderName = orderLabel;
theoEntry = High[1] + entryOffset*TickSize;//variable to manage stops against theoretical no-slippage entry
stopPrice = Low[1] - iniOffset*TickSize;
SetStopLoss(CalculationMode.Price,stopPrice);//initial stop set to entry plus wiggle room
SetProfitTarget(orderName,CalculationMode.Price,High[1] + entryOffset*TickSize + firstTarget*TickSize);//targets set from strategy setup user parameters
EnterLong(lotSize, orderName);

Comment