![]() |
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Dec 2007
Posts: 365
Thanks: 36
Thanked 28 times in 24 posts
|
Hello,
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? Code:
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);
Last edited by coolmoss; 06-22-2012 at 09:39 AM.
|
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Mar 2012
Location: Denver, CO
Posts: 1,183
Thanks: 130
Thanked 180 times in 179 posts
|
Hello coolmoss,
1.Where are you calling this code? [Example: in OnBarUpdate()] 2.How are you verifying that the delay in between the code? 3.What bar series type are you using? (Example: Minute, Day, Tick) 4.What Print()s have you added to find out how your code is running? 5.Do you see delays if you manually place order? Happy to be of further assistance.
JC
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Dec 2007
Posts: 365
Thanks: 36
Thanked 28 times in 24 posts
|
Hi JC,
1) The posted code is being called from OnBarUpdate. That's all that's used, except for a single line of code in OnPositionUpdate which draws a bit of fixed text. 2) I'm verifying the time delay from the log tab, the log file, and observation in live trading on the longer delays (eg. a 15 second delay is pretty noticable if you happen to be watching screen at the time). 3) Range bars, usually something around 8 ticks wide, COBC = false 4) Could you please suggest where I should locate the print statements in the code I posted. Would it hurt to put a print statement between each "if" section. I don't want to bog things down using too many prints which then muddies up the whole problem. 5) No delays in manual orders. For that matter, just to be clear, the Exits are darn near instantaneous, and the logs bear this out. Just to be clear: these "delays" don't happen all the time, that's what's so screwy. I'd say 1/2 to 1/3 of the reversals occur inside 1 second, the other take anywhere from 5 to 15 seconds or more. And the computer isn't on the edge of it's resources and again, Ninja is doing very minimal stuff. Thanks very much for your help!
Last edited by coolmoss; 06-22-2012 at 10:07 AM.
|
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Mar 2012
Location: Denver, CO
Posts: 1,183
Thanks: 130
Thanked 180 times in 179 posts
|
Hello coolmoss,
Thanks for the information. Could you send me your log and trace files so that I may look into what occurred. You can do this by going to the Control Center-> Help-> Mail to Support. Please reference the following ticket number in the body of the email: ATTN - JC - http://www.ninjatrader-helpdesk.com/...t&reqid=669407 4. First, I would turn TraceOrders = true, see the following link http://www.ninjatrader.com/support/h...raceorders.htm. Then I would put a print before, inside, and after each if statement at first to see how your strategy is being processed. For example: Code:
ExitShort();
Print("After ExitShort() and Time is: "+DateTime.Now);
Please let me know if I can be of further assistance.
JC
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Data Delay | saints | Connecting | 10 | 11-23-2011 10:01 AM |
| Delay execution | dancorcal | Automated Trading | 3 | 06-27-2011 01:04 PM |
| Executions Tab doesn't match Executions log file | brima | Version 7 Beta General Questions & Bug Reports | 9 | 11-03-2010 11:32 AM |
| Execution Delay | Jean-Marc-Molina | Automated Trading | 3 | 11-12-2009 11:41 AM |
| Data delay | nicko9 | Connecting | 8 | 09-14-2007 03:50 AM |