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 > NinjaScript Development Support > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 03-27-2008, 09:23 AM   #1
Edgar V.
Member
 
Join Date: Mar 2008
Posts: 65
Thanks: 0
Thanked 0 times in 0 posts
Default Duplicity of lots

My strategy is a SMA Crossover with an StochRSI. Problem is that when the SMA crosses over, instead of reversing the order, it duplicate the reverse. I'm not sure what is wrong. I just want to have 1 lot reversing when conditions are met. Below is a sample of my strategy:

if ((SMA(Fast)[0] > SMA(Slow)[0]) && (StochRSI(14)[0] >= 0.8)&& wasLong == false)
{
EnterLong(DefaultQuantity,
"LongSMAEnter");
wasLong =
true;
}


if ((SMA(Fast)[0] < SMA(Slow)[0])&& wasLong == true)
{
ExitLong(
"ExitLong", "LongSMAEnter");
wasLong =
false;
}


elseif ((SMA(Fast)[0] < SMA(Slow)[0]) && (StochRSI(14)[0] <= 0.2)&& wasLong == true)
{
EnterShort(DefaultQuantity,
"ShortSMAEnter");
wasLong =
false;
}

if ((SMA(Fast)[0] > SMA(Slow)[0])&& wasLong == false)
{
ExitShort(
"ExitShort", "ShortSMAEnter");
wasLong =
true;
}
Edgar V. is offline  
Reply With Quote
Old 03-27-2008, 09:28 AM   #2
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

Your code is executing as you have written it. You would have to debug this yourself to understand why. I did scan your code and at first glance I don't see the flaw in logic...we don't spend much time debugging user code as part of our support policy.

I would look at the wasLong variable as an issue. For the most part, you do not need this in NinjaScript since method calls are ignored when applicable. If you call ExitShort() and there is no short position, it would be ignored.
NinjaTrader_Ray 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
"Hanging" lots yeneuro Miscellaneous Support 8 11-22-2005 01:23 PM


All times are GMT -6. The time now is 11:52 AM.