NexusFi: Find Your Edge


Home Menu

 





3 bar high/low entry maintain active order until 3 bar high/low in opposite direction


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one mrticks with 4 posts (3 thanks)
    2. looks_two wh with 3 posts (2 thanks)
    3. looks_3 Saroj with 1 posts (0 thanks)
    4. looks_4 sam028 with 1 posts (0 thanks)
    1. trending_up 6,532 views
    2. thumb_up 5 thanks given
    3. group 2 followers
    1. forum 8 posts
    2. attach_file 1 attachments




 
Search this Thread
  #1 (permalink)
 
mrticks's Avatar
 mrticks 
Dublin, Ireland.
 
Experience: Advanced
Platform: NinjaTrader, TOS, Multicharts, Open Source various
Trading: FDAX, cable/yen, FX, options on commodities
Posts: 67 since Jun 2009
Thanks Given: 16
Thanks Received: 10

[IMG]file:///D:/DOCUME%7E1/gdavey/LOCALS%7E1/Temp/moz-screenshot.png[/IMG][IMG]file:///D:/DOCUME%7E1/gdavey/LOCALS%7E1/Temp/moz-screenshot-1.png[/IMG]

Hello,

This is my first post so I hope I don't mess it up! I have written code to enter a buy stop after three successive lower bars at the previous bar high. So when the close is lower than the open 3 times in a row a buy stop is entered at the high of the previous bar, which is [1]. So it looks like,

if (Close[2] < Open[2] && Close[1] < Open[1] && Close[0] < Open[0])
{
EnterLongStop(ContractAmount, High[1], "3BR Long Entry" );

My question is, how can I keep that buy order active untill a specified number of bars have closed without it being filled? I find that I get a lot of orders pending only to be cancelled after the next bar closes as it hasn't reached the buy stop, only for the market to go that way 3 or 4 bars later.

I have attached a screenshot with an example of buy orders placed. I intend to modify this strategy to also implement sell stop orders with the opposite criteria and also place orders a certain amount of ticks above the previous bar high.

Any tips/help/advice or code snippets would be greatly appreciated!!!!!

 
Code
protected override void Initialize()
        {
            CalculateOnBarClose = true;
            
        SetTrailStop("3BR Long Entry", CalculationMode.Ticks, TrailStop, false);
        }
        


        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            if  (Close[2] < Open[2] && Close[1] < Open[1] && Close[0] < Open[0])
            {
             EnterLongStop(ContractAmount, High[1], "3BR Long Entry" );
            }


Attached Thumbnails
Click image for larger version

Name:	3BLong.bmp
Views:	571
Size:	2.22 MB
ID:	3608  
Started this thread Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
Kharg Island at 6%, Regime Fall at 1.5% -- The Black Swa …
Prediction Markets & Event Contracts
Victory Day Delivers: Russia-Ukraine Ceasefire Market Cl …
Prediction Markets & Event Contracts
SEC Chairman Calls for New Golden Age of SEC-CFTC Regula …
Traders Hideout
Asia Equities Crash Overnight -- Nikkei -5.2%, KOSPI -6. …
Traders Hideout
NinjaTrader Connect Launches -- Krakens $1.5B Acquisitio …
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
22 thanks
2026 Jlab journal
10 thanks
Trying to learn Volume and price action correlation
8 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Hello Im new here
5 thanks
  #2 (permalink)
 
sam028's Avatar
 sam028 
Site Moderator
 
Posts: 3,756 since Jun 2009
Thanks Given: 3,825
Thanks Received: 4,632

Maybe using the IOrder class, and manage yourself the cancellation ( see the method
EnterLongStop(int barsInProgressIndex, bool liveUntilCancelled, int quantity, double stopPrice, string signalName) ).

But you'll have to manage yourself the order cancellation, wait 1 or 2 bars more for ex.


Follow me on X Reply With Quote
  #3 (permalink)
 
mrticks's Avatar
 mrticks 
Dublin, Ireland.
 
Experience: Advanced
Platform: NinjaTrader, TOS, Multicharts, Open Source various
Trading: FDAX, cable/yen, FX, options on commodities
Posts: 67 since Jun 2009
Thanks Given: 16
Thanks Received: 10



sam028 View Post
Maybe using the IOrder class, and manage yourself the cancellation ( see the method
EnterLongStop(int barsInProgressIndex, bool liveUntilCancelled, int quantity, double stopPrice, string signalName) ).

But you'll have to manage yourself the order cancellation, wait 1 or 2 bars more for ex.


Thanks for the response Sam. I had seen IOrder in the NinjaTrader help section and it is very close to what I need.

The code looks like:
 
Code
private IOrder  entryOrder = null;
 protected override  void OnBarUpdate()  
{ 
    if (entryOrder == null && Close[0] >  Open[0]) 
        entryOrder = EnterLong();  
}
 protected override void OnOrderUpdate(IOrder order) 
{ 
    if (entryOrder  != null &&  entryOrder.Token == order.Token) 
    {  
        Print(order.ToString()); 
         if (order.OrderState ==  OrderState.Filled) 
            entryOrder =  null; 
     } 
}
I was looking for a method to:

else if keep alive for "X" amount of bars &&
else if cancel after "X" amount of bars if not filled &&
else if set period of time &&
else if 3 bar reversal in the other direction ;

I'll look further into IOrder and maybe attach an exit long attached to a different signal.


Thanks.


Started this thread Reply With Quote
  #4 (permalink)
 
wh's Avatar
 wh 
Neubrandenburg, Germany
 
Experience: Advanced
Platform: R
Trading: Stocks
Posts: 538 since Jun 2009
Thanks Given: 298
Thanks Received: 512

sory forget yesterday to post:

here are some examples

asgs - Revision 13: /trunk


Reply With Quote
Thanked by:
  #5 (permalink)
 
mrticks's Avatar
 mrticks 
Dublin, Ireland.
 
Experience: Advanced
Platform: NinjaTrader, TOS, Multicharts, Open Source various
Trading: FDAX, cable/yen, FX, options on commodities
Posts: 67 since Jun 2009
Thanks Given: 16
Thanks Received: 10


wh View Post
sory forget yesterday to post:

here are some examples

asgs - Revision 13: /trunk

Hi wh,

Thanks for the respone and I took a quick look at some of that code. We likey! We likey! It gave me a warm feeling.

lastBarCount = Bars.Count;

This gave me a few ideas that I will see if I can do something with IOrder and that. Will post my code up when I'm finished if it tests OK. I'll spend some time looking at your code later on this evening and see what I can throw up.


Thanks,

Gavin.


Started this thread Reply With Quote
  #6 (permalink)
 
wh's Avatar
 wh 
Neubrandenburg, Germany
 
Experience: Advanced
Platform: R
Trading: Stocks
Posts: 538 since Jun 2009
Thanks Given: 298
Thanks Received: 512

thats is not my code i do not auto trade ... but sometimes ...

hope it helps ...


Reply With Quote
  #7 (permalink)
 
Saroj's Avatar
 Saroj 
Arcata, CA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: index futures, oil
Posts: 482 since Jun 2009
Thanks Given: 232
Thanks Received: 416


wh View Post
sory forget yesterday to post:

here are some examples

asgs - Revision 13: /trunk

wh, I see a file with the extension ".odt".. Indicators.odt. What is this please?


Reply With Quote
  #8 (permalink)
 
wh's Avatar
 wh 
Neubrandenburg, Germany
 
Experience: Advanced
Platform: R
Trading: Stocks
Posts: 538 since Jun 2009
Thanks Given: 298
Thanks Received: 512

odt is an open office format like the a word document from micro office

<googl>odt open</google>


Reply With Quote
  #9 (permalink)
 
mrticks's Avatar
 mrticks 
Dublin, Ireland.
 
Experience: Advanced
Platform: NinjaTrader, TOS, Multicharts, Open Source various
Trading: FDAX, cable/yen, FX, options on commodities
Posts: 67 since Jun 2009
Thanks Given: 16
Thanks Received: 10

Hello all,

As a follow up, I found this code achieved what I needed, which was to keep an order alive for x amount of bars before cancelling the order. Snippets of the necessary below.


private IOrder myEntryOrder = null;
private int barNumberOfOrder = 0;
protected override void OnBarUpdate()

enterlongstop blah blah blah
barNumberOfOrder = CurrentBar;

// If entryOrder has not been filled within x bars, cancel the order.
else if (myEntryOrder != null && CurrentBar > barNumberOfOrder + ActiveBars)
{

CancelOrder(myEntryOrder);
}


The ActiveBars reference above in the else if statement is from a private int.


Started this thread Reply With Quote
Thanked by:




Last Updated on November 13, 2009


© 2026 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 - Downloads - Top
no new posts