![]() |
|
|||||||
| 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. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Junior Member
Join Date: Jul 2011
Posts: 8
Thanks: 0
Thanked 0 times in 0 posts
|
I am trying to modify the Simple Moving Crossover strategy. I need to do the following to the basic strategy.
1. Add a limit entry (long or short) that triggers at crossover that has the ability to enter several ticks above or below the crossover entry point. 2. Add a automatic market exit (long or short) that triggers at next crossover. 3. If the limit entry was not taken (not reached) then the entry/exit cycle would be cancled and renewed at the next crossover. I would like to use this in backtesting. Thanks, I have tried but failed to do this. |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Apr 2010
Location: Denver, CO, USA
Posts: 4,770
Thanks: 158
Thanked 562 times in 553 posts
|
Hello,
Thank you for your post and welcome to our forums! Would you be able to post a snippet of the code you have tried that did not work? This should help us identify what was not working and help you get the results you are expecting. I look forward to assisting you further.
Matthew
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Jul 2011
Posts: 8
Thanks: 0
Thanked 0 times in 0 posts
|
I just used the SMA crossover stratgey supplied in Ninjatrader and unsucessfully tried to modify it. Then I gave up and returned it to normal and asked for help and started studying the help guides for strategies.
|
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Apr 2010
Location: Denver, CO, USA
Posts: 4,770
Thanks: 158
Thanked 562 times in 553 posts
|
Here is a basic example of the SampleMA modified to help get you started.
For your first requirement, we specify a limit order by using EnterLongLimit() or EnterShortLimit(). I have specified a price of 5 ticks from the current value of the slow SMA. You can change this to meet your needs. Code:
if (CrossAbove(SMA(Fast), SMA(Slow), 1))
EnterLongLimit(SMA(Slow)[0] - 5 * TickSize);
else if (CrossBelow(SMA(Fast), SMA(Slow), 1))
EnterShortLimit(SMA(Slow)[0] + 5 * TickSize);
Code:
if (Position.MarketPosition == MarketPosition.Long && CrossBelow(SMA(Fast), SMA(Slow), 1))
{
ExitLong();
}
else if (Position.MarketPosition == MarketPosition.Short && CrossAbove(SMA(Fast), SMA(Slow), 1))
{
ExitShort();
}
http://www.ninjatrader.com/support/f...ad.php?t=19169
Matthew
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Junior Member
Join Date: Jul 2011
Posts: 8
Thanks: 0
Thanked 0 times in 0 posts
|
Thanks, let me give it a spin.
Do I have to insert this into the existing SMA strategy (if so, where) or does this serve as a stand alone? Thanks so much. |
|
|
|
|
|
#6 |
|
NinjaTrader Customer Service
Join Date: Apr 2010
Location: Denver, CO, USA
Posts: 4,770
Thanks: 158
Thanked 562 times in 553 posts
|
You can make a copy of the existing SampleMACrossovers by going to Tools--> Edit NinjaScript--> Indicators--> open the SampleMACrossovers
From the code, please right click on this window and select "Save As" and give it a new name. Then you can freely edit and modify this script.
Matthew
NinjaTrader Customer Service |
|
|
|
|
|
#7 |
|
Junior Member
Join Date: Jul 2011
Posts: 8
Thanks: 0
Thanked 0 times in 0 posts
|
Thanks....
|
|
|
|
|
|
#8 |
|
NinjaTrader Customer Service
Join Date: Apr 2010
Location: Denver, CO, USA
Posts: 4,770
Thanks: 158
Thanked 562 times in 553 posts
|
If this gets too complicated, I would recommend starting with the Strategy Wizard.
Please see our Help Guide articles on How to use the Strategy Wizard as well as NinjaScript Strategies. More information on these subjects can be found below: There is also a 2 hour long Strategy Development Webinar conducted by our Product Manager Josh Peng hosted on the popular online trading community Big Mike Trading.com: http://www.bigmiketrading.com/webina...y_development/
Matthew
NinjaTrader Customer Service |
|
|
|
|
|
#9 |
|
Junior Member
Join Date: Jul 2011
Posts: 8
Thanks: 0
Thanked 0 times in 0 posts
|
I figured where to replace the first part of the code but I am having some trouble inserting the second section in the right place.
We are allmost there. |
|
|
|
|
|
#10 |
|
NinjaTrader Customer Service
Join Date: Apr 2010
Location: Denver, CO, USA
Posts: 4,770
Thanks: 158
Thanked 562 times in 553 posts
|
This would just go anywhere in the OnBarUpdate() method between the opening { and closing } (see screen shot)
Matthew
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| SMA Crossover | ktinn | Strategy Development | 3 | 03-26-2012 05:07 AM |
| SMA CrossOver | tacticaltrader | General Programming | 2 | 09-21-2011 05:25 PM |
| SMA/EMA crossover help? | Trankuility | Indicator Development | 2 | 11-05-2010 09:24 AM |
| SMA crossover | kaywai | Strategy Development | 13 | 12-21-2009 09:37 AM |
| making a sma crossover strategy quicker to enter and exit | GONZO | Strategy Analyzer | 3 | 12-10-2009 03:41 PM |