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 06-04-2009, 11:18 AM   #1
BigDog008
Senior Member
 
Join Date: Dec 2008
Posts: 198
Thanks: 0
Thanked 0 times in 0 posts
Default Issues with limit orders...

I'm having some issues with Limit Orders where they keep changing as the market keeps moving... I have it set that its liveUntilCancelled, but still seem to be having issues...

SHORTS....
Code:
if (some condition is met)
{
EnterShortLimit(0, true, DefaultQuantity, GetCurrentAsk() + 2 * TickSize, "ShortA");
EnterShortLimit(0, true, DefaultQuantity, GetCurrentAsk() + 3 * TickSize, "ShortB");
EnterShortLimit(0, true, DefaultQuantity, GetCurrentAsk() + 4 * TickSize, "ShortC");
}
LONGS....
Code:
if (some condition is met
{
EnterLongLimit(0, true, DefaultQuantity, GetCurrentBid() - 2 * TickSize, "LongA");
EnterLongLimit(0, true, DefaultQuantity, GetCurrentBid() - 3 * TickSize, "LongB");
EnterLongLimit(0, true, DefaultQuantity, GetCurrentBid() - 4 * TickSize, "LongC");
}
BigDog008 is offline  
Reply With Quote
Old 06-04-2009, 11:23 AM   #2
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

If you keep submitting the orders over and over they will keep amending and moving. Don't resubmit if you don't wish to amend the order.
NinjaTrader_Josh is offline  
Reply With Quote
Old 06-04-2009, 11:29 AM   #3
BigDog008
Senior Member
 
Join Date: Dec 2008
Posts: 198
Thanks: 0
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by NinjaTrader_Josh View Post
If you keep submitting the orders over and over they will keep amending and moving. Don't resubmit if you don't wish to amend the order.
so how would I ammend this if I don't keep order submission in OnBarUpdate()?
Last edited by BigDog008; 06-04-2009 at 11:44 AM.
BigDog008 is offline  
Reply With Quote
Old 06-04-2009, 11:50 AM   #4
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

Not sure I follow. Your original post eluded to you not wanting the orders to move. If you don't want them to move, do not resubmit your orders. If you want to amend them then simply call the EnterShortLimit() again.
NinjaTrader_Josh is offline  
Reply With Quote
Old 06-04-2009, 11:55 AM   #5
BigDog008
Senior Member
 
Join Date: Dec 2008
Posts: 198
Thanks: 0
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by NinjaTrader_Josh View Post
Not sure I follow. Your original post eluded to you not wanting the orders to move. If you don't want them to move, do not resubmit your orders. If you want to amend them then simply call the EnterShortLimit() again.
Meaning how do I keep it from not resubmitting orders?

I currently have the EnterShortLimit and EnterLongLimit in the OnBarUpdate() section because I want to be able enter them based on current market prices...
BigDog008 is offline  
Reply With Quote
Old 06-04-2009, 12:01 PM   #6
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

You can use flag variables.

Code:
if (flag == false)
{
     EnterLongLimit(...);
     flag = true;
}
NinjaTrader_Josh is offline  
Reply With Quote
Old 06-04-2009, 12:03 PM   #7
BigDog008
Senior Member
 
Join Date: Dec 2008
Posts: 198
Thanks: 0
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by NinjaTrader_Josh View Post
You can use flag variables.

Code:
if (flag == false)
{
     EnterLongLimit(...);
     flag = true;
}

but then how would I handle the issue of switching to flag = false when I hit a profit target or a stop?

could I add flag = false to the protected override void Initialize() section?
BigDog008 is offline  
Reply With Quote
Old 06-04-2009, 12:05 PM   #8
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

private bool flag = false;

in the Variables region of your code.

You just need to decide when you want to reset it to false yourself. Whether that means when you are flat, when your entry gets filled, whatever your criteria is when you set it back to false.
NinjaTrader_Josh is offline  
Reply With Quote
Old 06-04-2009, 01:32 PM   #9
BigDog008
Senior Member
 
Join Date: Dec 2008
Posts: 198
Thanks: 0
Thanked 0 times in 0 posts
Default

so I did that... and now I'm not able to submit orders at all... finding it rather frustrating that I'm missing something here... not sure what though....


Code:
#region Variables
 private int stoplossticks = 8;
private bool flag = false;
#endregion
and....
Code:
if (some conditions....
   && flag == false)
and....
Code:
{
 EnterShortLimit(0, true, DefaultQuantity, GetCurrentAsk() + 2 * TickSize, "Short A");
EnterShortLimit(0, true, DefaultQuantity, GetCurrentAsk() + 3 * TickSize, "Short B");
EnterShortLimit(0, true, DefaultQuantity, GetCurrentAsk() + 4 * TickSize, "Short C");
flag = true;
}
but no dice
BigDog008 is offline  
Reply With Quote
Old 06-04-2009, 01:50 PM   #10
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

I suggest you print the value of your flag variable. You have no code there that resets the flag to false.
NinjaTrader_Josh is offline  
Reply With Quote
Old 06-04-2009, 04:09 PM   #11
BigDog008
Senior Member
 
Join Date: Dec 2008
Posts: 198
Thanks: 0
Thanked 0 times in 0 posts
Default

Here's what I've done... but still seem to be resubmitting orders...

Code:
#region Variables
// Wizard generated variables
private bool flag = false;
// User defined variables (add any user defined variables below)
#endregion
and then for logic...

Code:
protected override void Initialize()
{
SetProfitTarget("Long A", CalculationMode.Ticks, 4);
SetProfitTarget("Long B", CalculationMode.Ticks, 6);
SetProfitTarget("Long C", CalculationMode.Ticks, 8);
SetProfitTarget("Short A", CalculationMode.Ticks, 4);
SetProfitTarget("Short B", CalculationMode.Ticks, 6);
SetProfitTarget("Short C", CalculationMode.Ticks, 8);
            
SetStopLoss("Long A", CalculationMode.Ticks, 8, false);
SetStopLoss("Long B", CalculationMode.Ticks, 8, false);
SetStopLoss("Long C", CalculationMode.Ticks, 8, false);
SetStopLoss("Short A", CalculationMode.Ticks, 8, false);
SetStopLoss("Short B", CalculationMode.Ticks, 8, false);
SetStopLoss("Short C", CalculationMode.Ticks, 8, false);

CalculateOnBarClose = false;
}

protected override void OnBarUpdate()
{
// Condition set 1
if (some condition met...
   && flag == false)
{
      EnterShortLimit(0, true, DefaultQuantity, GetCurrentAsk() + 2 * TickSize, "Short A");
      EnterShortLimit(0, true, DefaultQuantity, GetCurrentAsk() + 3 * TickSize, "Short B");
      EnterShortLimit(0, true, DefaultQuantity, GetCurrentAsk() + 4 * TickSize, "Short C");
      flag = true;
 }

// Condition set 2
if (some condition met...
    && flag == false)
{
      EnterLongLimit(0, true, DefaultQuantity, GetCurrentBid() - 2 * TickSize, "Long A");
      EnterLongLimit(0, true, DefaultQuantity, GetCurrentBid() - 3 * TickSize, "Long B");
      EnterLongLimit(0, true, DefaultQuantity, GetCurrentBid() - 4 * TickSize, "Long C");
      flag = true;
}
            
if (Position.MarketPosition == MarketPosition.Flat)
{
    flag = false;
}

i'm confused... what am i missing?
Last edited by BigDog008; 06-04-2009 at 06:19 PM.
BigDog008 is offline  
Reply With Quote
Old 06-05-2009, 05:36 AM   #12
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,411
Thanks: 252
Thanked 976 times in 959 posts
Default

It may be your orders expire unfilled and the condition becomes true intrabar again since you run it on CalculateOnBarClose = false, have you tried working with TraceOrders to check into the order behavior of your strategy? http://www.ninjatrader-support2.com/...ead.php?t=3627
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 06-05-2009, 06:49 AM   #13
BigDog008
Senior Member
 
Join Date: Dec 2008
Posts: 198
Thanks: 0
Thanked 0 times in 0 posts
Default

Bertrand, but does it make sense that it will expire when I have liveUntilCancelled set to true?

for what its worth, even though i initially have the flag set to false, have logic to change the flag back to false, the moment i click on start in the strategy tab, it seems to send out two orders, regardless of what the time is.... i want to run the strategy from 8:30am to 3pm central standard time, yet it'll still send out order prior to that.... i am testing using market replay
Last edited by BigDog008; 06-05-2009 at 06:52 AM.
BigDog008 is offline  
Reply With Quote
Old 06-05-2009, 06:52 AM   #14
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,411
Thanks: 252
Thanked 976 times in 959 posts
Default

No, sorry missed that in my earlier post BigDog008 - I thought you had it to false and that's why you needed to work with flags for resubmitting until filled.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 06-05-2009, 07:33 AM   #15
BigDog008
Senior Member
 
Join Date: Dec 2008
Posts: 198
Thanks: 0
Thanked 0 times in 0 posts
Default

any suggestion as to where this is failing? the logic seems rather simple and sound and shouldn't be misbehaving to this level
BigDog008 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
Limit orders not being executed at limit Marzullo Miscellaneous Support 15 08-24-2011 01:20 PM
SIM Limit orders executing as market orders ericadam SuperDOM and other Order Entry Windows 11 10-10-2010 11:42 AM
issues with stop limit orders woodside General Programming 4 02-12-2008 09:45 AM
Limit orders - book position kept when new orders are generated Fabrice Automated Trading 6 10-13-2007 03:16 PM
Negative Limit - Stop Limit Entry Orders biswar Automated Trading 1 10-18-2005 12:58 AM


All times are GMT -6. The time now is 01:53 AM.