Go Back   NinjaTrader Support Forum > NinjaTrader 8 > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

NinjaTrader
Reply
 
Thread Tools Display Modes
Old 02-08-2017, 02:50 PM   #16
traderpards
Senior Member
 
Join Date: Nov 2010
Location: Longmont, CO
Posts: 169
Thanks: 53
Thanked 28 times in 23 posts
Default

I still have Wait Until Flat as my start behavior.

Yes, I'm under the impression that in order to prevent the error and have my strategy shut down from under me that I have to transition the historical order to a real time order. So I'm still doing that for the entries only and not for the targets and stops. And it's fine until one of the profit targets are hit - the framework doesn't put the stops and targets. Just when one of the profit targets are hit does it put the targets and stops, when it should not for historical orders.

You forgot to either confirm or refute that placing those targets and stop on the trade after the first target is hit is a problem or not.
traderpards is offline  
Reply With Quote
Old 02-09-2017, 09:33 AM   #17
NinjaTrader_PatrickH
NinjaTrader Customer Service
 
NinjaTrader_PatrickH's Avatar
 
Join Date: Jul 2011
Location: Denver, CO
Posts: 10,317
Thanks: 744
Thanked 1,743 times in 1,679 posts
Default

Quote:
Originally Posted by traderpards View Post
You forgot to either confirm or refute that placing those targets and stop on the trade after the first target is hit is a problem or not.
Thank you for your response, traderpards,

This should not be something that occurs without your own logic performing such a function.

I would recommend debugging your script further to determine how these orders are generating their own protective orders.

Please let me know if you have any questions.
NinjaTrader_PatrickH is offline  
Reply With Quote
Old 02-09-2017, 11:42 AM   #18
traderpards
Senior Member
 
Join Date: Nov 2010
Location: Longmont, CO
Posts: 169
Thanks: 53
Thanked 28 times in 23 posts
Default

No Patrick, my script is not to blame. Think about it for a second. Look at the screen shot I sent. The last historical entry is an entry (3). When I first refreshed the chart with the strategy, we got that historical trade and there were no trade flags - the framework knew about them but they were in the background. Then when the first target was hit, the framework "uncovered" them; that is, the framework placed those on the chart from its historical record and turned the historical trades stops into live trade stops. In other words, before the historical trade target was hit, they were in the background and considered historical targets. After that first target was hit, the remaining two targets (and the stop) became live targets. You can see in the screenshot that it's a quantity of 2 on the stop loss associated with two profit targets.

If it were my strategy, there would be three there. It's that simple. The reason there is only two left is because the framework detected that one of the profit targets were hit and the framework uncovered the others, or exposed them, or did whatever it did to make them live stops and targets that would turn into a live, unwanted trade when hit. There is only one place in my strategy where protective orders are put, and that's in OnBarUpdate() where the trade is triggered and it's always a quantity of two, not three. I do not put a profit target or a stop loss anywhere in my code except in a call made in OnBarUpdate. Besides, that trade is historical - even if I wanted to put a stop loss and a profit target on a historical trade, I'm not sure how you do that, not that I'd want to and I wouldn't think you even can. This is happening within your framework.

This is a problem in the framework and by now I was hoping you'd admit it instead of trying to dodge it. You say it "should not" happen, but it is - just see the screen shot where I showed you that it's happening. I would recommend you try to reproduce it and see if it can't be fixed.

I can't help but wonder if the requirement to "transition historical trades into live trades," which I'm doing on the entries and not the targets and stop, wasn't some kludge to try to fix something else. (I wonder that because you already know it's a historical trade in your data structures so why does the user have to do something special? Why don't you guys just do whatever transitioning is necessary?)
traderpards is offline  
Reply With Quote
Old 02-09-2017, 04:11 PM   #19
NinjaTrader_PatrickH
NinjaTrader Customer Service
 
NinjaTrader_PatrickH's Avatar
 
Join Date: Jul 2011
Location: Denver, CO
Posts: 10,317
Thanks: 744
Thanked 1,743 times in 1,679 posts
Default

Hello traderpards,

Thank you for your response.

I can go through the code and test it out to provide a possible solution. Do you have an updated version you could send me?
NinjaTrader_PatrickH is offline  
Reply With Quote
Old 02-09-2017, 04:36 PM   #20
traderpards
Senior Member
 
Join Date: Nov 2010
Location: Longmont, CO
Posts: 169
Thanks: 53
Thanked 28 times in 23 posts
Default

Yeah... You're not going to find a possible solution - I think it needs fixing - but if you want to look anyway...

I'd send you my base class that's kind of a trade manager I use to easily make strategies but it's pretty big and I know you guys don't like working with something that large. I'll make something similar to what I'm using, test it to make sure it does what I'm claiming, which it will and then I'll send it to you. I may need a couple of days though.
Last edited by traderpards; 02-09-2017 at 10:00 PM.
traderpards is offline  
Reply With Quote
Old 02-09-2017, 09:45 PM   #21
traderpards
Senior Member
 
Join Date: Nov 2010
Location: Longmont, CO
Posts: 169
Thanks: 53
Thanked 28 times in 23 posts
Default Reproduced

...and you don't even have to wade through 10,000 lines of code. (It turned out to be not as much of a pain as I thought it would.)

Steps to reproduce:

1. Download GC 02-17 data - however much you need for last week.
2. Unzip the strategy
3. Connect to Market Replay and go to Jan 23rd, 10:00 pm.
4. Load the strategy and turn on Chart Trader
5. At 4:54 am, the morning of Jan 24th, a short trade triggers
6. Hang tight until 12:02 pm when the first profit target is hit.
7. Stop the Market Replay as soon after the first profit target is hit and before the 2nd profit target is hit. You don't have much of a gap in there - the 2nd one gets hit quickly. (your screen should look like Screen Shot #1.)
8. In the control center, Positions tab, Flatten everything or Close.
9. Reload the strategy - this loads that trade you stopped at as a historical trade. So far, so good - this is what you'd expect for a historical trade.
10. Run the strategy until the 2nd target is hit.
11. Observe the trade flags on the screen. (Screen shot #2)
12. So, what I did since I don't think the third target will get hit naturally is I dragged the third target up halfway up that current bar and let the price action take it out. When the price action does take out that target you'll notice that a live trade is triggered long with no protective orders. (Screen shot #3)

That to me is a problem... Right?

Note: So this reproduced it this way. But I'll bet you don't need to wait until the first profit target is hit. It will probably reproduce if you stop the strategy, close the trade after the entry, restart the strategy and then you'll see it put the two flags on the chart for the two orders that are left after the first target is hit.

The ideal solution would be to make it so transitioning stops and targets works, I would think. (I tried it but I forgot what doing that led to.)
Attached Images
File Type: png Screenshot 1.png (49.4 KB, 9 views)
File Type: png ScreenShot2.png (58.7 KB, 8 views)
File Type: png Screenshot 3.png (61.8 KB, 8 views)
Attached Files
File Type: zip MACross-RealTimeTransitioning.zip (3.8 KB, 6 views)
Last edited by traderpards; 02-09-2017 at 10:01 PM.
traderpards is offline  
Reply With Quote
Old 02-16-2017, 12:01 PM   #22
NinjaTrader_PatrickH
NinjaTrader Customer Service
 
NinjaTrader_PatrickH's Avatar
 
Join Date: Jul 2011
Location: Denver, CO
Posts: 10,317
Thanks: 744
Thanked 1,743 times in 1,679 posts
Default

Hello traderpards,

Thank you for your response.

I cannot reproduce that behavior, I do see similar entries and exits. However, I do not have the No Gap bars. Can you replicate this without using custom bar types?

I look forward to your response.
NinjaTrader_PatrickH is offline  
Reply With Quote
Old 02-17-2017, 11:56 AM   #23
traderpards
Senior Member
 
Join Date: Nov 2010
Location: Longmont, CO
Posts: 169
Thanks: 53
Thanked 28 times in 23 posts
Default

You can reproduce this on any time frame, I would think. I just did it on plain ole stock Range bars (18). The thing to look for historically is it hitting all three targets. Then you run it until it hits the first target, restart the strategy and watch it put the flags on the third target when it hits the second target and then watch it enter a live trade once it hits the third target.

The key is step #8, where you must flatten everything or close the current trade on the chart. You need to do that because in a real scenario, you won't have that trade in the background. Somehow that affects how you get the trading flags on the chart which tells you that you are about to launch a trade in the opposite direction, I think. I think that because it didn't reproduce for me when I tried it but then I realized that I didn't delete the active trade when I restarted the strategy after the first target was hit. Once I did that, then presto, it reproduced just like it did with those other bars.

The screenshots are for GC 02-17 on Jan 20th. Range 18 bars.
Screenshot 1 - Stop the strategy here after the first target is hit and restart and this is about what you get
Screenshot 2 - After the second target is hit, you get the flags on the third target.
Screenshot 3 - After the third target is hit, it gives you a trade in the opposite direction, which is what you don't want.
Attached Images
File Type: png Screenshot 1 (2).png (58.4 KB, 9 views)
File Type: png Screenshot 2.png (64.1 KB, 6 views)
File Type: png Screenshot 3.png (75.6 KB, 6 views)
traderpards is offline  
Reply With Quote
Old 02-24-2017, 09:51 AM   #24
NinjaTrader_PatrickH
NinjaTrader Customer Service
 
NinjaTrader_PatrickH's Avatar
 
Join Date: Jul 2011
Location: Denver, CO
Posts: 10,317
Thanks: 744
Thanked 1,743 times in 1,679 posts
Default

Hello traderpards,

Thank you for your patience.

I wanted to let you know I can in fact reproduce this in multiple testing scenarios. We are investigating further to find the cause of this and I will update you here when I have details.
NinjaTrader_PatrickH is offline  
Reply With Quote
The following user says thank you to NinjaTrader_PatrickH for this post:
Old 06-19-2017, 11:01 AM   #25
traderpards
Senior Member
 
Join Date: Nov 2010
Location: Longmont, CO
Posts: 169
Thanks: 53
Thanked 28 times in 23 posts
Default

I think this is fixed. I didn't see anything in the release notes that would indicate that it is fixed because I didn't get an issue number from you and none of the issues listed there sound like this one. But I forgot to turn CL over to the newest contract on Friday and since I'm done for today, I turned it over and there is a trade in progress on my strategy when I refreshed the chart. The first target got filled live and I don't see any stop and target flags generated after the first target was hit, which is what causes the unwanted trade in the opposite direction. So... thanks!!
traderpards is offline  
Reply With Quote
The following user says thank you to traderpards for this post:
Old 06-19-2017, 12:07 PM   #26
NinjaTrader_PatrickH
NinjaTrader Customer Service
 
NinjaTrader_PatrickH's Avatar
 
Join Date: Jul 2011
Location: Denver, CO
Posts: 10,317
Thanks: 744
Thanked 1,743 times in 1,679 posts
Default

Hello traderpards,

Thank you for your update on this matter.

Please let me know if we may be of further assistance.
NinjaTrader_PatrickH 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
Chart and real executiuons not matching performance tab for real time strategy trade _Cujo Platform Technical Support 5 08-09-2016 01:52 PM
The strategy does not trade in real time bonnies Platform Technical Support 1 10-15-2015 02:30 PM
Last Trade Profit or Loss Adjusts Strategy Parameter In Real Time kroeran Strategy Development 1 04-18-2015 05:03 PM
Tracking real time unrealized profit on each trade birdog Platform Technical Support 1 03-08-2013 12:50 PM
Determine trade size in real-time and backtest tomace Strategy Development 2 04-29-2009 04:43 PM


All times are GMT -6. The time now is 02:47 AM.

Futures, foreign currency and options trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing ones financial security or lifestyle. Only risk capital should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results. View Full Risk Disclosure.

CFTC Rules 4.41 - Hypothetical or Simulated performance results have certain limitations, unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under-or-over compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.

This website is hosted and operated by NinjaTrader, LLC (“NT”), a software development company which owns and supports all proprietary technology relating to and including the NinjaTrader trading platform. NT is an affiliated company to NinjaTrader Brokerage (“NTB”), which is a NFA registered introducing broker (NFA #0339976) providing brokerage services to traders of futures and foreign exchange products. This website is intended for educational and informational purposes only and should not be viewed as a solicitation or recommendation of any product, service or trading strategy. No offer or solicitation to buy or sell securities, securities derivative or futures products of any kind, or any type of trading or investment advice, recommendation or strategy, is made, given, or in any manner endorsed by any NT affiliate and the information made available on this Web site is not an offer or solicitation of any kind. Specific questions related to a brokerage account should be sent to your broker directly. The content and opinions expressed on this website are those of the authors and do not necessarily reflect the official policy or position of NT or any of its affiliates. 

Vendors along with their websites, products and services, collectively referred to as (“Vendor Content”), are independent persons or companies that are in no manner affiliated with NT or any if its affiliates. NT or any of its affiliates are not responsible for, do not approve, recommend or endorse any Vendor Content referenced on this website and it’s your sole responsibility to evaluate Vendor Content. Please be aware that any performance information provided by a vendor should be considered hypothetical and must contain the disclosures required by NFA Rule 2-29(c). If you are interested in learning more about, or investigating the quality of, any such Vendor Content you must contact the vendor, provider or seller of such Vendor Content. No person employed by, or associated with, NT or any of its affiliates is authorized to provide any information about any such Vendor Content. Visit the CFTC resources for education regarding the industry and signs of fraud.