PDA

View Full Version : Entering positions when not flat


edward
08-08-2007, 08:16 PM
I have written a ninja script(mostly through the wizard). In the script, I am using an ATM strategy. I have found that I am entering trades when I am already in one. I have tried putting in pieces of code to keep this from happening, but without success. Here are a few of the ways I have tried. As you can see, I am trying anything in the hopes that it works. Obviously, I am not an advanced programmer. Any help would be appreciated.

1.
protectedoverridevoid OnBarUpdate()
if (GetAtmStrategyMarketPosition(OrderId) != MarketPosition.Flat)

return;

2.
protectedoverridevoid OnBarUpdate()

if (GetAtmStrategyMarketPosition(
atmStrategyId) != MarketPosition.Flat)

return;

and
3.
// Condition set 1
if (ToTime(Time[0]) >= ToTime(8, 45, 00)
&& ToTime(Time[0]) <= ToTime(14, 50, 00)
&& Position.MarketPosition == MarketPosition.Flat
etc...
4.
// Condition set 1
if (ToTime(Time[0]) >= ToTime(8, 45, 00)
&& ToTime(Time[0]) <= ToTime(14, 50, 00)
&& GetAtmStrategyMarketPosition(OrderId) == MarketPosition.Flat
etc...

The log shows an error:
GetAtmStrategyMarketPosition() method error: AtmStrategyId '1dfde556491458491db1e6eeee761d0' does not exist

Edward

NinjaTrader_Josh
08-08-2007, 11:18 PM
Have you tried setting EntriesPerDirection to 1? I don't know if the EntriesPerDirection variable affects ATM strategies though.

edward
08-09-2007, 06:14 AM
Unfortunately that does not work for ATM strategies. Or at least that is what I have read. Thanks though.

NinjaTrader_Ray
08-09-2007, 07:52 AM
Programatically working with ATM strategies in a NinjaScript strategy is an advanced endevour. Please take a look at the sample strategy code and even start with that as a base reference to work out your own logic.

Position.MarketPosition will NOT reflect the position of an ATM strategy. Please see the Help Guide for relevant ATM methods that you can use.

edward
08-09-2007, 02:10 PM
I have been looking at the Help guide concerning ATM strategies. I am using the GetAtmStrategyEntryOrderStatus function. Both of the Print commands show the same orderId, but the line in between shows an error in the log. It states that the specific orderId cannot be found. How can the orderId not exist when it prints out in the output window?

Print("test1 orderId is now: " + (orderId));
string[] status = GetAtmStrategyEntryOrderStatus(orderId);
Print("test2 orderId is now: " + (orderId));


Output window:
test1 orderId is now: c1397fd6281949d0bcf1186b5108275f
test2 orderId is now: c1397fd6281949d0bcf1186b5108275f

Log:
GetAtmStrategyEntryOrderStatus() method error: orderId 'c1397fd6281949d0bcf1186b5108275f' does not exist

NinjaTrader_Ray
08-09-2007, 02:21 PM
Printing out the user defined variable orderId does not mean that it exists at the time you call the Get() method.