View Full Version : Strategy + ATM?
dsraider
04-24-2009, 07:11 PM
Hi,
I would like to set a strategy so that when an event occurs (20/50 crossover) an order is triggered that matches my ATM strategy which is the following:
1. limit order with +8 target and -6 stop
2. break-even set to +1 when price is at +3
3. at +4 ticks from signal, trailing stop is triggered
Any and all help would be greatly appreciated. Thanks in advance.
NinjaTrader_Ben
04-25-2009, 07:49 AM
Hello,
I suggest starting here:
http://www.ninjatrader-support.com/HelpGuideV6/UsingASMStrategies.html
and:
http://www.ninjatrader-support.com/HelpGuideV6/ASMStrategyCreate.html
Also, start with the SampleMACrossOver strategy that comes with NT by default since it already has a crossover trigger coded within it.
Then give it a try and post your code for assistance.
dsraider
04-25-2009, 11:13 AM
Ben, thank you for getting back to me. Please bear in mind that I do not speak code and was hoping to do this all through the wizard. I have come up with the following where "ES 1" is the name of my current ATM Strategy:
// Condition set 1
if (CrossAbove(EMA(20), EMA(50), 1))
{
AtmStrategyCreate(Action.Buy, OrderType.Limit, 0, 0,
TimeInForce.Day, GetAtmStrategyUniqueId(), "ES 1",
GetAtmStrategyUniqueId());
}
}
#region Properties
[Description("FAST")]
[Category("Parameters")]
publicint FAST
{
get { return fAST; }
set { fAST = Math.Max(1, value); }
}
[Description("SLOW")]
[Category("Parameters")]
publicint SLOW
{
get { return sLOW; }
set { sLOW = Math.Max(1, value); }
}
#endregion
}
}
Thanks - Dave
NinjaTrader_Ben
04-25-2009, 06:41 PM
Hello,
Sorry, I didn't realize you were using the Wizard. You can do #1 but you can't do the second two without custom programming. Here are two screen shots that show the first item in the Wizard.
dsraider
04-25-2009, 07:26 PM
Ben,
My mistake. I forgot to mention it. Earlier, you sent me a link stating that you can set an automated trading variable (like a 20/50 crossover) to activate an ATM strategy (thank you for that, by the way). Unfortunately, at least for me, the directions on how to do that aren't clear. Does the code that I've posted accomplish what I want? Am I missing something? A point in the right direction would be an enormous help.
Thanks.
NinjaTrader_Ben
04-26-2009, 09:22 AM
Hello,
The code you posted will create an ATM strategy using a previously saved ATM strategy given a cross over condition that occured one bar pervious.
dsraider
04-26-2009, 09:33 AM
So it works? Oh my God I'm a coding genius! And if I want my ATM strategy to execute upon the following:
20/50 cross above and below
20/200 cross above and below
50/200 cross above and below
Can I do that in the same Strategy or do I have to set them each up separately?
This is an enomous help, Ben. Thank you.
NinjaTrader_Ben
04-26-2009, 05:51 PM
Hello,
Glad to help! I recommend renaming the SampleMACrossOver strategy and inserting your condition and order placement code in it. Get it to work within this strategy first then add and modify your other conditions until it works. You may need to debug it. If you need help debugging please visit this link:
http://www.ninjatrader-support2.com/vb/showthread.php?t=3418
dsraider
04-27-2009, 06:19 AM
Morning Ben,
I was about to continue using the link you sent but unfotunately, the code I posted is not working. Is there something wrong with it?
Thanks.
NinjaTrader_Bertrand
04-27-2009, 06:28 AM
dsraider, please post the code you're currently working with so we can take a look - thanks!
dsraider
04-27-2009, 06:41 AM
// Condition set 1
if (CrossAbove(EMA(20), EMA(50), 1))
{
AtmStrategyCreate(Action.Buy, OrderType.Limit, 0, 0,
TimeInForce.Day, GetAtmStrategyUniqueId(), "ES 1",
GetAtmStrategyUniqueId());
}
}
#region Properties
[Description("FAST")]
[Category("Parameters")]
publicint FAST
{
get { return fAST; }
set { fAST = Math.Max(1, value); }
}
[Description("SLOW")]
[Category("Parameters")]
publicint SLOW
{
get { return sLOW; }
set { sLOW = Math.Max(1, value); }
}
#endregion
}
}
It would not let me post the entire section so hopefully this is the relevant part. All I am looking to do is have an automated strategy that signals a pre-saved ATM Strategy once a certain condition is met (20/50 cross).
Thanks again, Ben.
NinjaTrader_Bertrand
04-27-2009, 06:49 AM
Please make sure you submit the entry limit order at a valid price, yours is 0 in the code (right after the OrderType.Limit).
For a complete sample how to achieve what you want, I'd suggest to review the SampleAtmStrategy installed per default with your NinjaTrader installation.
dsraider
04-27-2009, 02:36 PM
Well, the good is I think it worked, even with 0 as the limit price - it seems to just place a limit order at the current market price.
The bad news is I decided to set calculate on bar to false after, which resulted in several hundred orders and now my computer freezes whenever I try to log on. Is there a way to delete all orders and strategies without connecting so that I may get my computer back when I connect???
Thanks.
P.S. Drinks are on me.
NinjaTrader_Josh
04-27-2009, 02:39 PM
dsraider,
When does it freeze? In the NT splash screen? What does it say for the status on the splash screen? If it is trying to process your trades during the splash screen you can try ctrl+alt+del to abort the process and close NT. Then reopen NT and it should not try to redo it. At this point in time you may want to reset your database to ensure nothing goes wrong. Go to Tools->Options->Misc->Reset DB.
dsraider
04-27-2009, 03:17 PM
Hi Josh,
EVERYTHING in NT freezes the second I connect to AMP. If I reset the database, will I lose the custom Automated Strategies I've created? I'm not sure I could reprogram them if you paid me. By the way, I did this in the simulator and not in the live program. It's the only good decision I've made all day.
Thanks.
NinjaTrader_Josh
04-27-2009, 03:28 PM
dsraider,
When you press Reset DB, you will not lose your ATM templates or your NinjaScript strategies.
What it will remove is this:
1. Historical orders
2. Historical executions
3. Historical ATM strategy data
What will not be removed:
1. ATM strategy templates
2. Historical chart data
3. NinjaScript is not touched
dsraider
04-27-2009, 03:34 PM
Josh, it worked! My computer and I thank you. Maybe I'll just stick to calculate on bar close: true from now on...
Dave
dsraider
04-28-2009, 06:58 AM
Okay, so now the orders fill when they're supposed to but when they do, my ATM Strategy doesn't work right. Here is the relevant coding:
if (CrossAbove(EMA(50), EMA(200), 1))
{
atmStrategyId = GetAtmStrategyUniqueId();
orderId = GetAtmStrategyUniqueId();
AtmStrategyCreate(Action.Buy, OrderType.Market, Low[0], 0, TimeInForce.Day, orderId, "ES 1", atmStrategyId);
My ATM Strategy is named "ES 1" - it has a target of 4, a stop of 6 and a break-even strategy where at +3 ticks, my stop is moved to +1 tick. However, the break-even isn't working, it's not selling at target and my stop is moving up and down on it's own. Do I need an exorcism or different coding?
Thanks.
NinjaTrader_Bertrand
04-28-2009, 07:10 AM
Have you checked the ATM template itself (ES 1) on the simulated feed that it does what you had in mind?
dsraider
04-28-2009, 07:37 AM
Hi Bertrand,
Yes, it seems to work perfectly when I place the trade manually. Once or twice it wouldn't automatically sell upon hitting target but I was told that while live trading is FIFO, the simulator is sometimes not as quick.
Also, please note that I do not have a trailing stop as part of my ATM.
NinjaTrader_Bertrand
04-28-2009, 08:07 AM
dsraider, yes that would depend on your position in the order queue, either sim or in realtime, in illiquid situations it may have to trade through to fill you. I would suggest you create a fresh template with just a target and a stop and no stop strategy and retest this. Or you add your custom template to the 'SampleAtmStrategy' provided per default as NinjaScript strategy and see if that executes as you had in mind.
dsraider
04-28-2009, 09:24 AM
Not perfectly sure if this is what you meant but I took my breakeven out of my ATM and left a target and stop. The cross occured, it shorted, went in my favor a few ticks, then went back to entry and sold, saying "stop filled" even though my stop was 6 ticks behind entry.
Does changing the ATM AFTER Automated Strategies are created cause it to malfunction? I didn't expect the Strategies to have a memory and figured they would just signal whatever configuration of my ATM was current?
NinjaTrader_Josh
04-28-2009, 09:29 AM
dsraider,
If you modify your ATM strategy it will not be effective till your next ATM strategy is activated. Whatever was running beforehand is not influenced.
dsraider
04-28-2009, 10:21 AM
Okay, then any ideas why ATM is changing my stop at will? I obviously can't have this happen in live trading and am anxious to use this automated/ATM setup.
Thanks.
NinjaTrader_Bertrand
04-28-2009, 10:39 AM
dsraider, did you save the ATM strategy after you removed the stopStrategy from it? If not, please consider doing this and saving it to fresh template like ES2 and use this then in your strategy to test.
dsraider
04-28-2009, 10:54 AM
Will do, Bertand. Thanks. Also, "Stop & Target Submission" is set to PerEntryExecution. Should I change it to ByStrategyPosition? I'm not sure if that makes a difference.
Thanks.
NinjaTrader_Bertrand
04-28-2009, 11:03 AM
This should not matter if you test this with one contract only to debug - http://www.ninjatrader-support.com/HelpGuideV6/StrategiesTab.html
dsraider
04-28-2009, 12:06 PM
Okay, tried everything you suggested. A cross occured, ATM went short when it should have. The market bounced a few ticks here and there and then, out of nowhere, my stop (which was 6 points back) jumped to +1 tick and immediately sold, leaving me down 1 tick. Please help before my monitor goes out the window.
Thank you.
NinjaTrader_Bertrand
04-28-2009, 12:17 PM
dsraider, please contact me at support at ninjatrader dot com with your trace and log file from today, I'll need to review where the stop modification comes from - just to doublecheck when you open your ATM template please make sure the stop strategy is set to 'none'. Then save the template and restart the strategy.