NexusFi: Find Your Edge


Home Menu

 





Keeping limit order alive


Discussion in NinjaTrader

Updated
    1. trending_up 1,675 views
    2. thumb_up 2 thanks given
    3. group 3 followers
    1. forum 2 posts
    2. attach_file 0 attachments




 
Search this Thread

Keeping limit order alive

  #1 (permalink)
MartinHHH
Montréal Québec
 
Posts: 6 since Mar 2019
Thanks Given: 21
Thanks Received: 5

Hello everyone,

I am looking for a way to keep a limit order valid for more than one bar after the conditions of my strategy are met.

Here is an example of what I want to do: The strategy will enter long with a limit order -1 tick of the actual price when the conditions of the strategy are met. One of the condition is the crossover of the MACDs, so typically that condition will not remain satisfied on the next bar update. The limit order get cancelled on the next bar update (my order is only valid for 5 minutes..., the time of one bar).

I would like to keep the order good till 'x' amount of bar updates. Seems to be a simple concept, but I didn't find anyone doing it on ninjatrader, neither on other Platform. I am not a coder, so I play carefully in the code.

On ninjatrader support, I found the following way, but it is not keeping the limit order for a period of time, but until the reversal of the initial condition (SMA crossover/above):
-----------------------------------------------------------
protected override void OnBarUpdate()
{

entryPrice = Low[0] - 2 * TickSize;

if (CrossAbove(SMA(Fast), SMA(Slow), 1))
{
EnterLongLimit(0, true, DefaultQuantity, entryPrice, "live until cancelled long");
}

if (Close[0] > Open[0])
{
EnterLongLimit(0, false, DefaultQuantity, entryPrice, "long order to be resubmitted");
}

if (CrossBelow(SMA(Fast), SMA(Slow), 1))
ExitLong();

----------------------------------------------------------------------

Can I add a bar counter after each bar update? like:

barcount = barcount +1


And the condition to terminate the limit order would be:

if (barcount == 3)
ExitLong();


-----------------------------------------------------------------------
Is that reliable? I am looking for something as much reliable as possible.
Is the comment "live until cancelled long" and "long order to be resubmitted" are usefull? are they supposed to be called and use somewhere else in the code?

Thanks a lot for your help, martin

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
About a successful futures trader who didnt know anythin …
Psychology and Money Management
REcommedations for programming help
Sierra Chart
Trade idea based off three indicators.
Traders Hideout
What broker to use for trading palladium futures
Commodities
MC PL editor upgrade
MultiCharts
 
  #2 (permalink)
 FArias 
Germany
 
Experience: Intermediate
Platform: NinjaTrader
Trading: Futures
Posts: 9 since Feb 2011
Thanks Given: 34
Thanks Received: 2

Hello Martin,

I am learning myself ninjascript at the time, so take my advice with care.

In order to cancel your order after a given period of time, you need a counter as you defined, but the correct way to cancel it is with the command CancelOrder().

You can find an example here:

https://forum.ninjatrader.com/forum/ninjascript-educational-resources/reference-samples/19377-strategy-using-cancelorder-method-to-cancel-orders?t=18890

Regards,
Fernando

Reply With Quote
Thanked by:
  #3 (permalink)
 iantg 
charlotte nc
 
Experience: Advanced
Platform: My Own System
Broker: Optimus
Trading: Emini (ES, YM, NQ, ect.)
Posts: 408 since Jan 2015
Thanks Given: 90
Thanks Received: 1,148


Easy to do.

Check the help guide here: https://ninjatrader.com/support/helpGuides/nt8/en-us/?managed_approach.htm

Click on any of the limit orders to see the full code syntax for example click on EnterLongLimit() to see the examples.
There are 5 or so ways to code the order up. But you want the last one that has the keep alive until canceled = true property.

Syntax
EnterLongLimit(double limitPrice)
EnterLongLimit(double limitPrice, string signalName)

EnterLongLimit(int quantity, double limitPrice)

EnterLongLimit(int quantity, double limitPrice, string signalName)



The following method variation is for experienced programmers who fully understand Advanced Order Handling concepts:

EnterLongLimit(int barsInProgressIndex, bool isLiveUntilCancelled, int quantity, double limitPrice, string signalName)


^ This one above is the one you want.

You can find a full version of the code here with working examples: https://forum.ninjatrader.com/forum/ninjascript-educational-resources/reference-samples/19659-strategy-keeping-orders-alive


But you will run into some issues if you are not careful. This is kind of like taking the training wheels off a bit. So by keeping orders alive, you will need to create your own logic to cancel them. And this needs to cover every permutation of everything that possibly could happen. So take care to think about all the many possibilities once you introduce an order that will not automatically cancel into your code.

If you ever get stumped I might be able to help. I have gone a few dozen steps beyond this and actually taken NT completely apart and used to use the unmanaged approach (No built in safety, training wheels completely off) which is not advisable for anyone less than a professional developer.

Best of luck


Ian





MartinHHH View Post
Hello everyone,

I am looking for a way to keep a limit order valid for more than one bar after the conditions of my strategy are met.

Here is an example of what I want to do: The strategy will enter long with a limit order -1 tick of the actual price when the conditions of the strategy are met. One of the condition is the crossover of the MACDs, so typically that condition will not remain satisfied on the next bar update. The limit order get cancelled on the next bar update (my order is only valid for 5 minutes..., the time of one bar).

I would like to keep the order good till 'x' amount of bar updates. Seems to be a simple concept, but I didn't find anyone doing it on ninjatrader, neither on other Platform. I am not a coder, so I play carefully in the code.

On ninjatrader support, I found the following way, but it is not keeping the limit order for a period of time, but until the reversal of the initial condition (SMA crossover/above):
-----------------------------------------------------------
protected override void OnBarUpdate()
{

entryPrice = Low[0] - 2 * TickSize;

if (CrossAbove(SMA(Fast), SMA(Slow), 1))
{
EnterLongLimit(0, true, DefaultQuantity, entryPrice, "live until cancelled long");
}

if (Close[0] > Open[0])
{
EnterLongLimit(0, false, DefaultQuantity, entryPrice, "long order to be resubmitted");
}

if (CrossBelow(SMA(Fast), SMA(Slow), 1))
ExitLong();

----------------------------------------------------------------------

Can I add a bar counter after each bar update? like:

barcount = barcount +1


And the condition to terminate the limit order would be:

if (barcount == 3)
ExitLong();


-----------------------------------------------------------------------
Is that reliable? I am looking for something as much reliable as possible.
Is the comment "live until cancelled long" and "long order to be resubmitted" are usefull? are they supposed to be called and use somewhere else in the code?

Thanks a lot for your help, martin


In the analytical world there is no such thing as art, there is only the science you know and the science you don't know. Characterizing the science you don't know as "art" is a fools game.
Visit my NexusFi Trade Journal Reply With Quote
Thanked by:




Last Updated on April 30, 2019


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts