View Full Version : Prior Bar High Or Low OCO Order
jstockman
08-17-2007, 10:39 PM
Guys,
I know this has already been done in this forum. Buy I can't find it. I have done all the seraches I know. Can anyone help. I am very new at programming C# but ok at cut and paste by example.
I want to do an OCO order to buy or sell short the prior bar as compared to current bar, only have one position open at a time, and set a profit and stop loss bracket around the trade.
Any help would be appreciated.
Thanking you in advance.
jstockman
NinjaTrader_Dierk
08-17-2007, 10:56 PM
Unfortunately we are unable to implement actual strategies for bandwidth reasons. But maybe the community can contribute.
We will enhance the list of sample strategies shortly.
jstockman
08-18-2007, 01:29 PM
Unfortunately we are unable to implement actual strategies for bandwidth reasons. But maybe the community can contribute.
We will enhance the list of sample strategies shortly.
Dierk,
What do you mean by bandwidth reasons?
jstockman
NinjaTrader_Ray
08-18-2007, 01:43 PM
It means that our current policy is to provide application level support and are unable to provide support at a level where we provide sample code upon request or analyze user code.
Thanks for understanding.
jstockman
08-18-2007, 05:11 PM
It means that our current policy is to provide application level support and are unable to provide support at a level where we provide sample code upon request or analyze user code.
Thanks for understanding.
Ray,
How do you suggest we get answers then if we can't find it on the forum?
jstockman
NinjaTrader_Ray
08-18-2007, 05:27 PM
You can get answers to product questions in our forum.
We will absolutely provide answers to questions related to the operation of our product. To help in the area of programming logic, we are doing the following:
- Developing a comprehensive reference sample library
- Developing a "NinjaScript" online live training course
- Hiring more NinjaScript support engineers
This is all work in progress and we hope to have these additional resources available to the community sooner than later.
Thanks for understanding.
jstockman
08-19-2007, 11:51 AM
You can get answers to product questions in our forum.
We will absolutely provide answers to questions related to the operation of our product. To help in the area of programming logic, we are doing the following:
- Developing a comprehensive reference sample library
- Developing a "NinjaScript" online live training course
- Hiring more NinjaScript support engineers
This is all work in progress and we hope to have these additional resources available to the community sooner than later.
Thanks for understanding.
Ray,
That gives me future hope. Press On!
jstockman
NinjaTrader_Josh
08-19-2007, 11:54 AM
jstockman there are two ways to proceed with what you are trying to accomplish. You can use ATM strategies or you can use things like EntriesPerDirection and EntriesHandling to achieve the effect you want.
For the ATM strategy approach:
This link will help you on coding your entries http://www.ninjatrader-support.com/HelpGuideV6/ASMStrategyCreate.html.
This one shows you how to cancel previous orders http://www.ninjatrader-support.com/HelpGuideV6/AsmStrategyActive.html.
This one shows you how to modify previous orders instead of canceling it http://www.ninjatrader-support.com/HelpGuideV6/helpguide.html.
With ATM strategy, you create the entry and then you can manually manage the stop/profit targets from within any order entry windows.
Check out the Video library section on ATM strategies on how to maximize its efficiency http://www.ninjatrader-support.com/HelpGuideV6/helpguide.html?VideoLibrary.
For the non-ATM approach:
You can use things like EnterLong/EnterShort with this method. What you want to do in the Initialize() section of your code is add two lines.
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;Basically what those two lines are doing is forcing NinjaTrader to ignore all additional entry conditions if you already have a position. You can review the exact method of using them with these two links http://www.ninjatrader-support.com/HelpGuideV6/MaxEntriesPerDirection.html
http://www.ninjatrader-support.com/HelpGuideV6/MaxEntryHandling.html
Please note that EntriesPerDirection and EntryHandling DO NOT affect ATM strategies. For ATM strategies you might need to add some programming checks to insure you don't enter while you have a position open. I believe you can use something like this to check if you have a position open or not.
Position.MarketPosition==MarketPosition.Flat I am not 100% sure if that will work on ATM strategies, but you can give it a try. You can also have Position.MarketPosition checked against MarketPosition.Long and MarketPosition.Short if you have a need for that.
Personally I have not experimented much with the ATM strategy approach, but it might be more suitable if you want to manually manage your positions after your strategy enters them. In the non-ATM approach you will need to manually program ExitLong() and ExitShort() at where you want the profit target and where you want the stop loss to be.
I hope this helps jstockman. If you are still having problems why don't you post up your strategy and I'll take a look and see if I can give you any pointers?
jstockman
08-19-2007, 12:17 PM
uacvax,
Thank-you for the help. I want to take a look at TRO Trillion using this method.
jstockman
NinjaTrader_Josh
08-19-2007, 12:38 PM
I've only heard about the TRO Trillion strategy. Never really looked deep into it. Please let me know how it goes.
jstockman
09-06-2007, 02:31 PM
jstockman there are two ways to proceed with what you are trying to accomplish. You can use ATM strategies or you can use things like EntriesPerDirection and EntriesHandling to achieve the effect you want.
For the ATM strategy approach:
This link will help you on coding your entries http://www.ninjatrader-support.com/HelpGuideV6/ASMStrategyCreate.html.
This one shows you how to cancel previous orders http://www.ninjatrader-support.com/HelpGuideV6/AsmStrategyActive.html.
This one shows you how to modify previous orders instead of canceling it http://www.ninjatrader-support.com/HelpGuideV6/helpguide.html.
With ATM strategy, you create the entry and then you can manually manage the stop/profit targets from within any order entry windows.
Check out the Video library section on ATM strategies on how to maximize its efficiency http://www.ninjatrader-support.com/HelpGuideV6/helpguide.html?VideoLibrary.
For the non-ATM approach:
You can use things like EnterLong/EnterShort with this method. What you want to do in the Initialize() section of your code is add two lines.
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;Basically what those two lines are doing is forcing NinjaTrader to ignore all additional entry conditions if you already have a position. You can review the exact method of using them with these two links http://www.ninjatrader-support.com/HelpGuideV6/MaxEntriesPerDirection.html
http://www.ninjatrader-support.com/HelpGuideV6/MaxEntryHandling.html
Please note that EntriesPerDirection and EntryHandling DO NOT affect ATM strategies. For ATM strategies you might need to add some programming checks to insure you don't enter while you have a position open. I believe you can use something like this to check if you have a position open or not.
Position.MarketPosition==MarketPosition.Flat I am not 100% sure if that will work on ATM strategies, but you can give it a try. You can also have Position.MarketPosition checked against MarketPosition.Long and MarketPosition.Short if you have a need for that.
Personally I have not experimented much with the ATM strategy approach, but it might be more suitable if you want to manually manage your positions after your strategy enters them. In the non-ATM approach you will need to manually program ExitLong() and ExitShort() at where you want the profit target and where you want the stop loss to be.
I hope this helps jstockman. If you are still having problems why don't you post up your strategy and I'll take a look and see if I can give you any pointers?
Josh,
Please confirm my thinking.
I can create an ATM strategy using the wizard. When I want engage this ATM strategy I use the above command. (Or is it just the opposite). I create the above strategy and then somehow using the Superdom ( which will show me the trade postion) I manage it manually?
Thanks for the clarification.
jstockman:)
NinjaTrader_Josh
09-06-2007, 04:34 PM
Are you referring to the NinjaScript Strategy Wizard? I do not believe you can automatically create ATM strategies straight from that wizard, but you can definitely use the wizard to create your strategy and then add in the ATM strategy stuff.
What happens when you run your NinjaScript strategy with ATM strategies coded inside is it will execute orders that you will be able to manually manage through any of NinjaTrader's order management windows (e.g. SuperDOM).
jstockman
09-06-2007, 07:04 PM
Are you referring to the NinjaScript Strategy Wizard? I do not believe you can automatically create ATM strategies straight from that wizard, but you can definitely use the wizard to create your strategy and then add in the ATM strategy stuff.
What happens when you run your NinjaScript strategy with ATM strategies coded inside is it will execute orders that you will be able to manually manage through any of NinjaTrader's order management windows (e.g. SuperDOM).
Josh,
I get it!
Is there a way around limitations on EntriesPerDirection etc.?
"ATM Strategies operate in real-time only and will not execute on historical data thus they
.Executions resulting from an ATM Strategy that is created from within a NinjaScript
automated strategy will not plot on a chart during real-time operation
.Strategy set up parameters such as EntriesPerDirection, EntryHandling, ExitOnClose do not
apply when calling the AtmStrategyCreate() method"
jstockman:)
NinjaTrader_Josh
09-06-2007, 11:16 PM
What you could try is just pass around a variable that is 1 when you already have an ATM position open and 0 when it is flat. Basically just have an if statement checking if this variable is 1 or 0 and only allow for a new AtmStrategyCreate() when it is 0.
You can use GetAtmStrategyMarketPosition() to determine if you have an ATM strategy position open or not. Just pass along the AtmStrategyId to it and you should be good to go.
http://www.ninjatrader-support.com/HelpGuideV6/ASMStrategyPosition.html
jstockman
09-08-2007, 01:28 PM
Josh,
Thank-you for pointing me in the right direction. I have just read the docs in NT regarding this area. Looks pretty straight forward. The stategy I am heading for is found in the Tradestation Forum under Trillion Dollar. Using daily bars I look to go long on first current bar that crosses above prior day high or go short if crosses below prior days low. The trick is to have one position open either long or short depending what broke open first. TRO sets his profit about 5 and stop about 7. It is kind of backwards to what all the books teach. But the stats bear out good percentages for the trade.
I'll keep you posted.
Regards,
jstockman:)
jstockman
09-09-2007, 07:48 PM
Josh,
As you have guessed I am a newbie at Ninja Script. I do have some experience on TradeStation Easy Language. None with C#. Help!
I am getting compilation errors on "GetATMStrategyUniqueId". When I go to the docs for this thing it says I am suppose to
Examples
protected override void OnBarUpdate()
{ string orderId }.
I put this into the attached an with "Unknown" for the string. I got more errors.
Query
Do I have to add Protected override void OnBarUpdate() on each command or just the section dealing with ATM strategies?
What is this unique ID and how do I get rid of these errors.
Thanking you in advance.
jstockman:)
NinjaTrader_Josh
09-09-2007, 08:00 PM
Hi jstockman
Your error is because you capitalized some of the letters. It is not "GetATMStrategyUniqueId()" it is "GetAtmStrategyUniqueId()". The "tm" in "Atm" are not capitalized.
The OnBarUpdate() is the section in which you want to put your logic. You don't put it on every entry condition. Whatever is inside the OnBarUpdate() is the algorithm that NinjaTrader will run through every time a bar is updated. It will start from the top and run through till the end of OnBarUpdate(). Does that make sense?
jstockman
09-10-2007, 05:09 PM
Hi jstockman
Your error is because you capitalized some of the letters. It is not "GetATMStrategyUniqueId()" it is "GetAtmStrategyUniqueId()". The "tm" in "Atm" are not capitalized.
The OnBarUpdate() is the section in which you want to put your logic. You don't put it on every entry condition. Whatever is inside the OnBarUpdate() is the algorithm that NinjaTrader will run through every time a bar is updated. It will start from the top and run through till the end of OnBarUpdate(). Does that make sense?
Josh,
Thank-you. I guess NT needs to clean up its docs. This is a copy job from the AtmStrategyCreate() under the help menu
// Check for valid condition and create an ATM Strategy
if (Close[0] > SMA(20)[0])
AtmStrategyCreate(Action.Buy, OrderType.Market, 0, 0,
TimeInForce.Day, GetATMStrategyUniqueId(), "MyTemplate",
GetAtmStrategyUniqueId());
By the by, the code did compile. Thank-you again
jstockman:)
NinjaTrader_Ray
09-10-2007, 08:09 PM
Thanks for pointing out the typo in the DOC.