how to buy next bar at close

Questions about MultiCharts and user contributed studies.
martingale
Posts: 91
Joined: 10 Dec 2010
Has thanked: 2 times
Been thanked: 1 time

how to buy next bar at close

Postby martingale » 23 May 2012

i have 1 min data while i want to make calculation on 3 minute bar.

at end of each 3 min bar, if condition = true, i want to buy at on next 1 min bar close price. how can i do this?

e.g.
i'm calculating my indicator using 3 min bars at ... 10:00, 10:03, 10:06 and if 10:06 give me a buy condition, i want to buy at 10:07 close.

i know i need to set [intrabarordergeneration=true], but not really sure how to use that .

thanks

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: how to buy next bar at close

Postby TJ » 23 May 2012

i have 1 min data while i want to make calculation on 3 minute bar.

at end of each 3 min bar, if condition = true, i want to buy at on next 1 min bar close price. how can i do this?

e.g.
i'm calculating my indicator using 3 min bars at ... 10:00, 10:03, 10:06 and if 10:06 give me a buy condition, i want to buy at 10:07 close.

i know i need to set [intrabarordergeneration=true], but not really sure how to use that .

thanks
You cannot buy at the close price, you can only do that in back test.

In real life, when you have determined that a specific tick is the close, theoretically the close has already passed. You cannot buy at an event that has already happened. The best you can do is to buy at the tick AFTER the close, which is the open of the following bar.


ps. unless you can show me at 10:06:59.99 the price of the next tick.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: how to buy next bar at close

Postby TJ » 23 May 2012

someone asked a similar type of question, maybe you can understand the "timing" problem in this illustration:

A trader wants to buy at the open if the OPEN is higher than the previous close,
and wants to sell at the open if the OPEN is lower than the previous close.


Well, when the OPEN has happened, you can determine whether you should buy or to sell.
But by the time you have determined the course of action, you will not be executing it at the OPEN anymore, you are trading at the tick AFTER the open.


Click "Thanks" if it makes sense.

martingale
Posts: 91
Joined: 10 Dec 2010
Has thanked: 2 times
Been thanked: 1 time

Re: how to buy next bar at close

Postby martingale » 23 May 2012

i have 1 min data while i want to make calculation on 3 minute bar.

at end of each 3 min bar, if condition = true, i want to buy at on next 1 min bar close price. how can i do this?

e.g.
i'm calculating my indicator using 3 min bars at ... 10:00, 10:03, 10:06 and if 10:06 give me a buy condition, i want to buy at 10:07 close.

i know i need to set [intrabarordergeneration=true], but not really sure how to use that .

thanks
You cannot buy at the close price, you can only do that in back test.

In real life, when you have determined that a specific tick is the close, theoretically the close has already passed. You cannot buy at an event that has already happened. The best you can do is to buy at the tick AFTER the close, which is the open of the following bar.


ps. unless you can show me at 10:06:59.99 the price of the next tick.
TJ, i'm actually talking about back test, and the code
Buy("long") next Bar on Close;
actually gives me a complier error.
let me know if i can correct this in backtest.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: how to buy next bar at close

Postby TJ » 23 May 2012

i have 1 min data while i want to make calculation on 3 minute bar.

at end of each 3 min bar, if condition = true, i want to buy at on next 1 min bar close price. how can i do this?

e.g.
i'm calculating my indicator using 3 min bars at ... 10:00, 10:03, 10:06 and if 10:06 give me a buy condition, i want to buy at 10:07 close.

i know i need to set [intrabarordergeneration=true], but not really sure how to use that .

thanks
You cannot buy at the close price, you can only do that in back test.

In real life, when you have determined that a specific tick is the close, theoretically the close has already passed. You cannot buy at an event that has already happened. The best you can do is to buy at the tick AFTER the close, which is the open of the following bar.


ps. unless you can show me at 10:06:59.99 the price of the next tick.
TJ, i'm actually talking about back test, and the code
Buy("long") next Bar on Close;
actually gives me a complier error.
let me know if i can correct this in backtest.
If you want a solution, you will need to

1. post the code

2. copy and paste the error message (or screenshot)



The PLE does not give an error message unless there is an error in coding.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: how to buy next bar at close

Postby TJ » 23 May 2012

TJ, i'm actually talking about back test, and the code
Buy("long") next Bar on Close;
actually gives me a complier error.
let me know if i can correct this in backtest.
try

Buy("long") THIS Bar on Close;

martingale
Posts: 91
Joined: 10 Dec 2010
Has thanked: 2 times
Been thanked: 1 time

Re: how to buy next bar at close

Postby martingale » 23 May 2012

TJ, i'm actually talking about back test, and the code
Buy("long") next Bar on Close;
actually gives me a complier error.
let me know if i can correct this in backtest.
try

Buy("long") THIS Bar on Close;
no, this is not what i want, what i want is
calculation based on 3 min bar, and enter position at the end of the 1 min bar after the 3 min bar.

User avatar
furytrader
Posts: 354
Joined: 30 Jul 2010
Location: Chicago, IL
Has thanked: 155 times
Been thanked: 217 times

Re: how to buy next bar at close

Postby furytrader » 24 May 2012

Just set up a boolean variable that tells you when the conditions are met to buy the next bar t the close and when they are met, then wait 1 bar and then buy the next bar at the close. It's a pretty simple programming thing.


Return to “MultiCharts”