![]() |
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
|
|||||||
| 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: Feb 2012
Posts: 10
Thanks: 7
Thanked 0 times in 0 posts
|
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(); } } |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
|
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 let me know if I can assist you any further.
Joydeep M.
NinjaTrader Customer Service |
|
|
|
|
The following user says thank you to NinjaTrader_Joydeep for this post: |
|
|
|
#3 |
|
Junior Member
Join Date: Feb 2012
Posts: 10
Thanks: 7
Thanked 0 times in 0 posts
|
Thanks, it works!
|
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
|
Hello topor,
Glad to know it works for you. Please let me know if I can assist you any further.
Joydeep M.
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |