NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > Application Technical Support > Automated Trading

Automated Trading Support for automated trading systems using NinjaScript. Support for our ATI (Automated Trading Interface) used to link an external application such as TradeStation and eSignal to NinjaTrader.

Reply
 
Thread Tools Display Modes
Old 05-15-2007, 09:28 AM   #1
scriabinop23
Senior Member
 
Join Date: May 2007
Posts: 112
Thanks: 0
Thanked 0 times in 0 posts
Default strategy/auto trade problem: stops/etc. initiate upon starting of strategy

Here's the odd situation:
Upon adding a strategy and STARTING it with the following initialize portion, the following profittarget limit order and stoploss order get sent to my broker. But there is no trigger and the actual buy doesn't occur. The scripts backtest properly. They just do this strange behavior -sometimes- upon starting the script. Anyway to make sure the contigent orders only enter when the conditions are met for my long order?

Whats fascinating is that in the control center, upon starting the strategy, it says it establishes a long position for X contracts, but does it without sending the actual order and without the actual trigger being met. I know this because i have some debug print statements to an output window that go with my long order section.

Any ideas?

protectedoverridevoid Initialize()
{
SetProfitTarget(
"LongHammer", CalculationMode.Ticks, ProfitTarget);
/// SetStopLoss("", CalculationMode.Ticks, StopLoss, false);
SetTrailStop("LongHammer", CalculationMode.Ticks, StopLoss, false);
Add((Bollinger(
2, 14)));
CalculateOnBarClose =
true;
}
scriabinop23 is offline  
Reply With Quote
Old 05-15-2007, 10:07 AM   #2
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

This is expected behaviour.

- When you start a strategy, a current position based on historical data is calculated. (Lets say 1 long)
- NinjaTrader will never submit an order to open a historical position
- The trader must (if it makes sense) manually sync their brokerage account to the strategy position by placing a manual order in the Order tab of the control center
- NinjaTrader will optionally submit pending orders live

You can control if a strategy submits pending orders live or not via option settings. See this part of our Help Guide.

http://www.ninjatrader-support.com/H...tegiesTab.html
NinjaTrader_Ray is offline  
Reply With Quote
Old 05-15-2007, 10:12 AM   #3
scriabinop23
Senior Member
 
Join Date: May 2007
Posts: 112
Thanks: 0
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by NinjaTrader_Ray View Post
This is expected behaviour.

- When you start a strategy, a current position based on historical data is calculated. (Lets say 1 long)
- NinjaTrader will never submit an order to open a historical position
- The trader must (if it makes sense) manually sync their brokerage account to the strategy position by placing a manual order in the Order tab of the control center
- NinjaTrader will optionally submit pending orders live

You can control if a strategy submits pending orders live or not via option settings. See this part of our Help Guide.

http://www.ninjatrader-support.com/H...tegiesTab.html

So basically clicking 'wait until flat before executing live' will do what i want and ignore the historical condition? (only waiting for new entries going forward?)

Or does wait until flat mean I actually have 0 position on the account previous to running the strategy?
scriabinop23 is offline  
Reply With Quote
Old 05-15-2007, 10:22 AM   #4
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

It will complete any open historical trade and once your strategy goes flat, then it will start executing live.
NinjaTrader_Ray is offline  
Reply With Quote
Old 05-15-2007, 10:24 AM   #5
scriabinop23
Senior Member
 
Join Date: May 2007
Posts: 112
Thanks: 0
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by scriabinop23 View Post
So basically clicking 'wait until flat before executing live' will do what i want and ignore the historical condition? (only waiting for new entries going forward?)

Or does wait until flat mean I actually have 0 position on the account previous to running the strategy?

so attempted to test this and chose 'wait until flat before executing live'. It appears the stops/limits didn't appear, but yet it shows a position is on in Strategy listing, when there isn't on the actual acct. Anyway to make it appear 'neutral' upon initation [so new signals that occur after commencement of the strategy aren't missed]?
scriabinop23 is offline  
Reply With Quote
Old 05-15-2007, 10:39 AM   #6
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

This is correct behaviour.

Signals will not be missed. The strategy will execute just like it does in backtest (historically) and once the strategy is flat (based on your logic) only then will new signals be executed live.

If you don't want your strategy to perform any historical calculations, then add this code to your OnBarUpdate() method.

Code:
if (Historical)
    return;
Keep in mind, the above code will not backtest.
NinjaTrader_Ray is offline  
Reply With Quote
Old 05-15-2007, 10:46 AM   #7
scriabinop23
Senior Member
 
Join Date: May 2007
Posts: 112
Thanks: 0
Thanked 0 times in 0 posts
Default

what are the other side effects of not having historical calculations?


Also... does the closing of an actually unexecuted trade (based on historical data) that runs at startup go into P&L history for analysis of performance? Or is that P&L based only on executed trades / true P&L?
scriabinop23 is offline  
Reply With Quote
Old 05-15-2007, 12:43 PM   #8
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

There are no negative implications.

PnL displayed in the Control Center window Performance tab is calculated from live executions, not historical.
NinjaTrader_Ray is offline  
Reply With Quote
Old 05-15-2007, 01:03 PM   #9
scriabinop23
Senior Member
 
Join Date: May 2007
Posts: 112
Thanks: 0
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by NinjaTrader_Ray View Post
There are no negative implications.

PnL displayed in the Control Center window Performance tab is calculated from live executions, not historical.

excellent.. am learning this software quick, thanks to you guys.
very helpful.
scriabinop23 is offline  
Reply With Quote
Old 05-15-2007, 01:20 PM   #10
scriabinop23
Senior Member
 
Join Date: May 2007
Posts: 112
Thanks: 0
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by NinjaTrader_Ray View Post
There are no negative implications.

PnL displayed in the Control Center window Performance tab is calculated from live executions, not historical.

Which brings me to another question.. how do you clear the P&L from live executions which are not simulated? (ie i am using my IB paper trading acct versus live, and want to clear test data).
scriabinop23 is offline  
Reply With Quote
Old 05-15-2007, 01:28 PM   #11
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

The only thing you can do is reset the entire database which will wipe out all executions from all accounts.

Tools > Options > Misc > Reset DB
NinjaTrader_Ray is offline  
Reply With Quote
Old 05-29-2007, 11:19 PM   #12
scriabinop23
Senior Member
 
Join Date: May 2007
Posts: 112
Thanks: 0
Thanked 0 times in 0 posts
Default

Am having a new quirk related to this issue:

When I start the strategy at night, it denotes an existing long entry from the time of the last session's entry, but at the current ask price upon system initation, even if the position shows properly exited at last session's close in the graph. ie, it would show an unclosed entry at 7.763 (current ask price) at 11:06am in my debug, even though the graph itself of the security shows a price of 7.688 as the actual historical entry at 11:06am. Current time of system initiation (from the previous night to the next morning) is 10:21pm, and current price of security is 7.763.


I have my session rules set to have session time frame from 6:00am-11:30am, and my system itself is programmed not to enter between other than in that time frame (and in some cases, not even enter after 11:15am, etc).

I have a debug line output every period iteration from the system, and the historical runthrough doesn't show the 'exit at close' order, even though it appears on the graph itself of the same security. This explains why the system shows an already 'open' position upon running.

Any ideas here?
Last edited by scriabinop23; 05-29-2007 at 11:22 PM.
scriabinop23 is offline  
Reply With Quote
Old 05-30-2007, 09:25 AM   #13
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

Hi,

Unfortunately I am having a hard time understanding the issue. I have read your post several times and I am not sure I would be on the right path.

At a high level, could you comment what behaviour you are seeing? I can then dig deeper by asking guided questions.

Thanks in advance for your cooperation.
NinjaTrader_Ray is offline  
Reply With Quote
Old 05-30-2007, 09:47 AM   #14
scriabinop23
Senior Member
 
Join Date: May 2007
Posts: 112
Thanks: 0
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by NinjaTrader_Ray View Post
Hi,

Unfortunately I am having a hard time understanding the issue. I have read your post several times and I am not sure I would be on the right path.

At a high level, could you comment what behaviour you are seeing? I can then dig deeper by asking guided questions.

Thanks in advance for your cooperation.
Where should I email you the screenshots which show the problem. It is kind of tough to explain ... Makes sense when you see it.
scriabinop23 is offline  
Reply With Quote
Old 05-30-2007, 12:29 PM   #15
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

Send to ray at ninjatrader dot com.
NinjaTrader_Ray is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Auto start strategy? ct Automated Trading 13 08-31-2011 03:07 AM
add stop strategy to existing trade bmaltz Automated Trading 5 11-30-2006 04:07 AM
Add / Change Stop Strategy During Trade longtex Miscellaneous Support 3 05-16-2006 08:19 AM
Multiple stops at different prices on same strategy? richfitton Miscellaneous Support 5 02-02-2005 02:15 AM
Changing Strategy after opening a trade craigsn Miscellaneous Support 1 12-13-2004 07:59 AM


All times are GMT -6. The time now is 01:13 PM.