PDA

View Full Version : Ninjascript Strategy returning wrong order?


edgeliner
10-23-2007, 05:21 PM
When I set up a simple strategy to buy on a crossover and sell on a crossunder (and it doesn't get much simpler than that), it always fills twice the number of lots??? As an example, if the crossover triggers a buy order of one lot, it submits two orders..... (1) Buy to Cover and (2) Buy! This nets a "Position" of 2 lots??? Can anyone tell me why?????

NinjaTrader_Ray
10-23-2007, 05:40 PM
This is correct.

If you are short and then you call EnterLong(), NT will send an BuyToCover for 1 lot to close the short and then send a buy order for 1 lot to open the long position.

Your strategy position will net the correct amount, which is 1 long.

NinjaTrader_Ray
10-23-2007, 09:41 PM
For further clarification.

When you run your strategy, it will calculate its current "strategy" position. Lets say its 1 lot long. Should your actual account position be flat, you have the option (most would do this) to synchronize your account position to your strategy position. In this case, you could enter a buy order to get your account position in sync with your strategy.

edgeliner
12-31-2007, 01:32 PM
I continue to have a problem with strategy fills?? I have created a nice system, but occasionally, here is what happens. If I have an order to go long when my conditions are met with an "enterlong", everthing is great until it reverses before kicking in and hits the "exitlong" first. Here is basically how it looks......


protected override void OnBarUpdate()
{
// Condition set 1
if condition is satisfied
{
EnterLong(DefaultQuantity,"");
}


// Condition set 2
if ((exit Condition is met))
&& (Position.MarketPosition == MarketPosition.Long)))
{
ExitLong("");

What happens is that I end up short a position if the condition 2 is met, even though I have the (Position.MarketPosition == MarketPosition.Long) in there.

I had this happen, so "flattened" everythin via the "File" menu in the control center, closed down the chart, and reopened it with a fresh strategy and it happened again??? Any idea why?????

NinjaTrader_Josh
12-31-2007, 01:38 PM
Without seeing the exact rendition of code you have I do not know what is wrong, but this is a potential cause of problems on what you have posted:

if ((exit Condition is met)) <-- that already closed the if-statement. the whole &&... isn't part of the if-condition.
&& (Position.MarketPosition == MarketPosition.Long)))

edgeliner
01-01-2008, 06:28 PM
I figured it out Josh. I had the

if (Historical)
return;

in the wrong place. I had it below the protected override void Initialize instead of below the protected override void OnBarUpdate. I think that solved it.

As always, thanks!