How to enter long buy on a bar immediately before it closes. - futures io
futures io futures trading



How to enter long buy on a bar immediately before it closes.


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one kevinkdog with 7 posts (6 thanks)
    2. looks_two bmtfken with 6 posts (0 thanks)
    3. looks_3 Hulk with 4 posts (2 thanks)
    4. looks_4 ABCTG with 2 posts (2 thanks)
    1. trending_up 6,302 views
    2. thumb_up 10 thanks given
    3. group 4 followers
    1. forum 19 posts
    2. attach_file 1 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

How to enter long buy on a bar immediately before it closes.

(login for full post details)
  #1 (permalink)
boca ration,fl/usa
 
 
Posts: 6 since Jul 2014
Thanks: 6 given, 0 received

Hi all, requesting help in EasyLanguage:

I've looked all over google and the
forums and no one can answer this.
And turning on intrabarordergeneration
does NOT help, it only buys at the end
of the current bar (missing the move)

See attached pic,
I want to buy a CURRENT bar as soon as
it crosses the previous bars range high,
immediately.
EDIT: That is to say that on a Daily chart, when the current bar crosses the last daily bar high, that I need a long entry immediately.

NOT at the close of the current bar.
NOT at the open of the next bar.

Easylanguage code seems so powerful that
it is hard to believe that E.L. can't do this.

If "(a current value)" > range[1] then
buy this bar at market; does NOT work.

Is that possible using separate conditions1 ,2 etc. using a Daily bar as the trigger and then a 1 tick bar for a long entry?
??

Ken

Attached Thumbnails
Click image for larger version

Name:	strat.JPG
Views:	93
Size:	54.5 KB
ID:	150827  
Reply With Quote

Journal Challenge February 2021 results (so far):
Competing for $1500 in prizes from Topstep
looks_oneSBtrader82 's Trading Journalby SBtrader82
(152 thanks from 29 posts)
looks_twoJust BEING a Trader: Letting Go!!by iqgod
(110 thanks from 31 posts)
looks_3Wisdom is Emptinessby Mtype
(68 thanks from 25 posts)
looks_4Deetee’s DAX Trading Journal (time based)by Deetee
(31 thanks from 15 posts)
looks_5Journal for peanuts1956by peanuts1956
(23 thanks from 13 posts)
 
 
(login for full post details)
  #3 (permalink)
 
 
Posts: 2,976 since Jul 2012
Thanks: 1,576 given, 5,890 received


In your picture, on the red bar shown, you'd have the code:

buy next bar at high stop;



That will send an order, good for the entire next bar (the green bar where you want to enter).

So, your logic has to be setup so you know at the close of the red bar, what your plan is for the next (green) bar.

Follow me on Twitter Reply With Quote
The following 3 users say Thank You to kevinkdog for this post:
 
(login for full post details)
  #4 (permalink)
Texas, USA
 
Experience: Advanced
Platform: TT Pro, Custom
Broker: dxFeed
Trading: Futures, Spreads
 
Hulk's Avatar
 
Posts: 249 since May 2014
Thanks: 596 given, 665 received


bmtfken View Post
Hi all, requesting help in EasyLanguage:

I've looked all over google and the
forums and no one can answer this.
And turning on intrabarordergeneration
does NOT help, it only buys at the end
of the current bar (missing the move)

See attached pic,
I want to buy a CURRENT bar as soon as
it crosses the previous bars range high,
immediately.
EDIT: That is to say that on a Daily chart, when the current bar crosses the last daily bar high, that I need a long entry immediately.

NOT at the close of the current bar.
NOT at the open of the next bar.

Easylanguage code seems so powerful that
it is hard to believe that E.L. can't do this.

If "(a current value)" > range[1] then
buy this bar at market; does NOT work.

Is that possible using separate conditions1 ,2 etc. using a Daily bar as the trigger and then a 1 tick bar for a long entry?
??

Ken

Basically, what Kevin said. You need to do 2 things:

1. Use IntraBarOrderGeneration=True in your code.
2. You need a stop order to be placed when the current bar closes.

So, lets assume the current bar range high is 1960 and you want to buy 1 tick above this high on the next bar (assuming 1 tick=0.25), you need to place a buy stop order at 1960.25 using this kind of syntax when the current bar closes.

 
Code
Buy next bar at 1960.25 stop;
By doing so, as soon as the current bar closes, you will see a buy stop market order is placed at 1 tick above the high and if the next bar gets to this high, it should get filled.

Visit my futures io Trade Journal Reply With Quote
The following user says Thank You to Hulk for this post:
 
(login for full post details)
  #5 (permalink)
 
 
Posts: 2,976 since Jul 2012
Thanks: 1,576 given, 5,890 received


Hulk View Post
Basically, what Kevin said. You need to do 2 things:

1. Use IntraBarOrderGeneration=True in your code.
2. You need a stop order to be placed when the current bar closes.

So, lets assume the current bar range high is 1960 and you want to buy 1 tick above this high on the next bar (assuming 1 tick=0.25), you need to place a buy stop order at 1960.25 using this kind of syntax when the current bar closes.

 
Code
Buy next bar at 1960.25 stop;
By doing so, as soon as the current bar closes, you will see a buy stop market order is placed at 1 tick above the high and if the next bar gets to this high, it should get filled.


You don't need IntraBarOrderGeneration=True. I always keep it to False.

Follow me on Twitter Reply With Quote
 
(login for full post details)
  #6 (permalink)
Texas, USA
 
Experience: Advanced
Platform: TT Pro, Custom
Broker: dxFeed
Trading: Futures, Spreads
 
Hulk's Avatar
 
Posts: 249 since May 2014
Thanks: 596 given, 665 received


kevinkdog View Post
You don't need IntraBarOrderGeneration=True. I always keep it to False.

Thats true. Orders always generated at the close of the bar in this case so this isnt required.

Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #7 (permalink)
 
 
Posts: 2,976 since Jul 2012
Thanks: 1,576 given, 5,890 received


Hulk View Post
Thats true. Orders always generated at the close of the bar in this case so this isnt required.

If he wanted to use IBOG, I think he could do this on the green bar (please correct me if I am wrong):

INTRABARORDERGENERATION=TRUE;
If close>high[1] then buy this bar at market; //you might have to use "high" instead of "close"


But, you cannot backtest with this setup, where you can with the other approach.

Follow me on Twitter Reply With Quote
The following user says Thank You to kevinkdog for this post:
 
(login for full post details)
  #8 (permalink)
Texas, USA
 
Experience: Advanced
Platform: TT Pro, Custom
Broker: dxFeed
Trading: Futures, Spreads
 
Hulk's Avatar
 
Posts: 249 since May 2014
Thanks: 596 given, 665 received


kevinkdog View Post
If he wanted to use IBOG, I think he could do this on the green bar (please correct me if I am wrong):

INTRABARORDERGENERATION=TRUE;
If close>high[1] then buy this bar at market; //you might have to use "high" instead of "close"


But, you cannot backtest with this setup, where you can with the other approach.

You are right Kevin. IBOG isnt required in this case. The information required to make the trade decision is available at the close of the current bar so the next (in-progress) bar really doesnt need to decide anything.

I had written a strategy sometime back that was based on a range (momentum) bar chart and would fade the close of the current bar when certain conditions are met and I think I was getting confused because of that.

Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #9 (permalink)
 
 
Posts: 2,230 since Apr 2013
Thanks: 409 given, 1,470 received

It's fine to use "close" in your example as in realtime with IOG this will be the last tick that came in (i.e. on the tick that prints the high the close should have the same value).

Regards,
ABCTG


kevinkdog View Post
If he wanted to use IBOG, I think he could do this on the green bar (please correct me if I am wrong):

INTRABARORDERGENERATION=TRUE;
If close>high[1] then buy this bar at market; //you might have to use "high" instead of "close"


But, you cannot backtest with this setup, where you can with the other approach.


Follow me on Twitter Reply With Quote
The following 2 users say Thank You to ABCTG for this post:
 
(login for full post details)
  #10 (permalink)
boca ration,fl/usa
 
 
Posts: 6 since Jul 2014
Thanks: 6 given, 0 received


Thanks all, I will review my code and post back.

Reply With Quote
 
(login for full post details)
  #11 (permalink)
boca ration,fl/usa
 
 
Posts: 6 since Jul 2014
Thanks: 6 given, 0 received

Yes, but that is the whole thing I am trying to avoid.

I want to buy in the middle of the GREEN candle in my pic. (Middle of the day in this case)
Not at the close of the current green candle.
Not at the end of the day.

I understand that EasyLanguage can't calculate until AFTER the clsoe of the candle for its data calculations.
That's why I wondered if using multiples data sets (data1,data2,etc) was optimal in this situation.

Perhaps a data1 = close of 10min
data2 = high of daily[1]

if data1 > data2 then buy this bar at market on a very small interval chart, 1 tick ? 1 min?



kevinkdog View Post
If he wanted to use IBOG, I think he could do this on the green bar (please correct me if I am wrong):

INTRABARORDERGENERATION=TRUE;
If close>high[1] then buy this bar at market; //you might have to use "high" instead of "close"


But, you cannot backtest with this setup, where you can with the other approach.



ABCTG View Post
It's fine to use "close" in your example as in realtime with IOG this will be the last tick that came in (i.e. on the tick that prints the high the close should have the same value).

Regards,
ABCTG


Reply With Quote
 
(login for full post details)
  #12 (permalink)
 
 
Posts: 2,230 since Apr 2013
Thanks: 409 given, 1,470 received

You need to modify Kevin's example to
 
Code
[INTRABARORDERGENERATION=TRUE]
If close>high[1] then buy next bar at market;
When using intrabar order generation "next bar" means the next tick. If you use this bar Close, then you'd only see the order at the end of the bar.

Regards,
ABCTG





bmtfken View Post
Yes, but that is the whole thing I am trying to avoid.

I want to buy in the middle of the GREEN candle in my pic. (Middle of the day in this case)
Not at the close of the current green candle.
Not at the end of the day.

I understand that EasyLanguage can't calculate until AFTER the clsoe of the candle for its data calculations.
That's why I wondered if using multiples data sets (data1,data2,etc) was optimal in this situation.

Perhaps a data1 = close of 10min
data2 = high of daily[1]

if data1 > data2 then buy this bar at market on a very small interval chart, 1 tick ? 1 min?


Follow me on Twitter Reply With Quote
 
(login for full post details)
  #13 (permalink)
 
 
Posts: 2,976 since Jul 2012
Thanks: 1,576 given, 5,890 received


bmtfken View Post
Yes, but that is the whole thing I am trying to avoid.

I want to buy in the middle of the GREEN candle in my pic. (Middle of the day in this case)
Not at the close of the current green candle.
Not at the end of the day.

I understand that EasyLanguage can't calculate until AFTER the clsoe of the candle for its data calculations.
That's why I wondered if using multiples data sets (data1,data2,etc) was optimal in this situation.

Perhaps a data1 = close of 10min
data2 = high of daily[1]

if data1 > data2 then buy this bar at market on a very small interval chart, 1 tick ? 1 min?



Maybe I don;t get exactly what you want to do. Why won't this work, if entered on the red bar before the green bar?:

buy next bar at high stop;

Follow me on Twitter Reply With Quote
The following user says Thank You to kevinkdog for this post:
 
(login for full post details)
  #14 (permalink)
boca ration,fl/usa
 
 
Posts: 6 since Jul 2014
Thanks: 6 given, 0 received

I will test and get back with you.

Thank you!

Reply With Quote
 
(login for full post details)
  #15 (permalink)
boca ration,fl/usa
 
 
Posts: 6 since Jul 2014
Thanks: 6 given, 0 received

Ok, that makes sense to me.
But how would you do that on a running basis for the chart?

[intrabarordergeneration = true];
If high of next bar > high[1] then buy next bar at market; or buy at market stop;

Does not work.
El errors out to :
Error 1; Description: 'Next Bar' can only be applied to 'OPEN', 'DATE' and 'TIME'






Hulk View Post
Basically, what Kevin said. You need to do 2 things:

1. Use IntraBarOrderGeneration=True in your code.
2. You need a stop order to be placed when the current bar closes.

So, lets assume the current bar range high is 1960 and you want to buy 1 tick above this high on the next bar (assuming 1 tick=0.25), you need to place a buy stop order at 1960.25 using this kind of syntax when the current bar closes.

 
Code
Buy next bar at 1960.25 stop;
By doing so, as soon as the current bar closes, you will see a buy stop market order is placed at 1 tick above the high and if the next bar gets to this high, it should get filled.


Reply With Quote
 
(login for full post details)
  #16 (permalink)
 
 
Posts: 2,976 since Jul 2012
Thanks: 1,576 given, 5,890 received

Repeat of my first post in the thread. That's all you need, based on what you described. Don't mess with IntraBarOrderGeneration (leave it false):


In your picture, on the red bar shown, you'd have the code:

buy next bar at high stop;



That will send an order, good for the entire next bar (the green bar where you want to enter).

So, your logic has to be setup so you know at the close of the red bar, what your plan is for the next (green) bar.

Follow me on Twitter Reply With Quote
The following user says Thank You to kevinkdog for this post:
 
(login for full post details)
  #17 (permalink)
Texas, USA
 
Experience: Advanced
Platform: TT Pro, Custom
Broker: dxFeed
Trading: Futures, Spreads
 
Hulk's Avatar
 
Posts: 249 since May 2014
Thanks: 596 given, 665 received


bmtfken View Post
Ok, that makes sense to me.
But how would you do that on a running basis for the chart?

[intrabarordergeneration = true];
If high of next bar > high[1] then buy next bar at market; or buy at market stop;

Does not work.
El errors out to :
Error 1; Description: 'Next Bar' can only be applied to 'OPEN', 'DATE' and 'TIME'

@bmtfken, what @kevinkdog is saying is all you need. It will work on a running basis. In real-time, if you place a stop order using the syntax "buy next bar at high stop;", then you will see a stop market order being placed at the high of the current bar as soon as the current bar closes and the next bar opens. Now if price makes it to that high, your order will be filled otherwise it wont. As an example, you can take a look at one of the canned strategies in TS called the Keltner Channel LE:

 
Code
{ The IntrabarOrderGeneration attribute is set to false in this strategy because
strategy calculations depend on end-of-bar prices.  Specifically, an "Average True
Range" is calculated.  Calculation of Average True Range depends on end-of-bar high,
low, and closing prices. }

[IntrabarOrderGeneration = false]
inputs:  Price( Close ), Length( 20 ), NumATRs( 1.5 ) ;
variables:  Avg( 0 ), Shift( 0 ), UpperBand( 0 ), Setup( false ), CrossingHigh( 0 ) ;

Avg = AverageFC( Price, Length ) ;
Shift = NumATRs * AvgTrueRange( Length ) ;
UpperBand = Avg + Shift ;

if CurrentBar > 1 and Price crosses over UpperBand then
{ CB > 1 check used to avoid spurious cross confirmation at CB = 1 }
	begin
	SetUp = true ;
	CrossingHigh = High ;
	end 
else if Setup and ( Price < Avg or High >= CrossingHigh + 1 point ) then
	Setup = false ;
	{ the High >= condition being true indicates that a buy must already have been 
	  triggered at this bar so this setup has been used up and needs to be negated; 
	  an example of a persisitent setup with an indefinite stop/limit trigger - setup 
	  has to be negated after entry confirmed; also see Pivot Reversal LE/SE and 
	  PercentR LE/SE }

if Setup then 
	Buy ( "KltChLE" ) next bar at CrossingHigh + 1 point stop ;


{ ** Copyright (c) 2001 - 2010 TradeStation Technologies, Inc. All rights reserved. ** 
  ** TradeStation reserves the right to modify or overwrite this strategy component 
     with each release. ** }

Visit my futures io Trade Journal Reply With Quote
The following user says Thank You to Hulk for this post:
 
(login for full post details)
  #18 (permalink)
boca ration,fl/usa
 
 
Posts: 6 since Jul 2014
Thanks: 6 given, 0 received

YES !, that worked with the other logic required for the entry.
buy next bar at high stop;

I will work out my trailing stops.

Thanks gents.

Reply With Quote
 
(login for full post details)
  #19 (permalink)
Dallas Texas
 
Experience: Advanced
Platform: Tradestation
Trading: Emini ES, Emini YM
 
Posts: 11 since Sep 2013
Thanks: 0 given, 1 received

What happens if there is a gap? The next bar opens above the current high?

Reply With Quote
 
(login for full post details)
  #20 (permalink)
 
 
Posts: 2,976 since Jul 2012
Thanks: 1,576 given, 5,890 received


Keystone View Post
What happens if there is a gap? The next bar opens above the current high?



If you have the statement:

buy next bar at high stop;


Here's what I expect: If next bar opens above the previous high, the stop is triggered, and a market order should be immediately sent, filling it at opening price. That is how backtest engine should fill it. In reality, there will be slippage on the fill.

Follow me on Twitter Reply With Quote


futures io Trading Community Platforms and Indicators EasyLanguage Programming > How to enter long buy on a bar immediately before it closes.


Last Updated on July 27, 2014


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
 

Journal Challenge w/$1500 prizes from Topstep!

February
 

Identifying Setups & Targets Using Profile Charts w/Trevor & Tradovate

Feb 25
 

Battlestations! Show us your trading desk - $1,500 in prizes!

March
     



Copyright © 2021 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts