NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


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 03-22-2012, 10:36 AM   #1
topor
Junior Member
 
Join Date: Feb 2012
Posts: 10
Thanks: 7
Thanked 0 times in 0 posts
Default Reference sample reversal strategy

Please post reference sample reversal strategy.

This NOT work:

if( Position.MarketPosition == MarketPosition.Long )
{
if( Close[0] > upperBand )
{
ExitLong();
EnterShort();
}
}
else if( Position.MarketPosition == MarketPosition.Short )
{
if( Close[0] < lowerBand )
{
ExitShort();
EnterLong();
}
}
else //Flat
{
if( Close[0] < lowerBand )//Long
{
EnterLong();
}
if( Close[0] > upperBand )//Short
{
EnterShort();
}
}
topor is offline  
Reply With Quote
Old 03-22-2012, 10:47 AM   #2
NinjaTrader_Joydeep
NinjaTrader Customer Service
 
NinjaTrader_Joydeep's Avatar
 
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
Default

Hello topor,
Thanks for writing in and I am happy to assist you.

EnterLong/EnterShort will close any existing position and then will got short/long. Please modify your code as per the below code

Code:
if( Position.MarketPosition == MarketPosition.Long )
{
if( Close[0] > upperBand )
{
EnterShort();
}
}
else if( Position.MarketPosition == MarketPosition.Short )
{
if( Close[0] < lowerBand )
{
EnterLong();
}
}
else //Flat
{
if( Close[0] < lowerBand )//Long
{
EnterLong();
}
if( Close[0] > upperBand )//Short
{
EnterShort();
}
}
Please refer to the SampleMACrossover strategy which comes with NinjaTrader for a basic Moving average reversal strategy.
  • In Control Center menu bar goto Tools>Edit NinjaScript>Strategies…
  • In the Strategies dialog se
lect SampleMACrossover and click on the Ok button.

Please let me know if I can assist you any further.
NinjaTrader_Joydeep is offline  
Reply With Quote
The following user says thank you to NinjaTrader_Joydeep for this post:
Old 04-04-2012, 04:03 AM   #3
topor
Junior Member
 
Join Date: Feb 2012
Posts: 10
Thanks: 7
Thanked 0 times in 0 posts
Default

Thanks, it works!
topor is offline  
Reply With Quote
Old 04-04-2012, 06:02 AM   #4
NinjaTrader_Joydeep
NinjaTrader Customer Service
 
NinjaTrader_Joydeep's Avatar
 
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
Default

Hello topor,
Glad to know it works for you.
Please let me know if I can assist you any further.
NinjaTrader_Joydeep 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
Reference Sample: Strategy: Stopping a strategy after consecutive losers AnotherTrader Automated Trading 6 02-05-2012 02:15 AM
Onmarketdata() Reference Sample mgabriel01 Indicator Development 8 10-31-2011 03:02 PM
Reference sample question marotom General Programming 24 06-27-2011 05:35 AM
Question on A reference Sample Jim-Boulder Strategy Development 1 01-15-2011 12:41 PM
Reference sample request pdawg Indicator Development 2 04-09-2008 11:49 PM


All times are GMT -6. The time now is 07:43 AM.