When does marketposition change?

skan

Junior member
Messages
20
Likes
0
Hi

Let's say we are running a strategy on hourly bars on Tradestation.
At the end of each bar we know the Low, High, Open and Close of that bar.
With that information we can make calculation and send orders at the end of the bar.
Therefore you have one bar delay betwen the data reception and the orders sending.

but When do we know marketposition value?
What happens when a stop is executed in the market within a bar?
Do I know it at once or at at the end of the bar?



In some forum I've seen
this expression:

"If marketposition = 1 and barssinceentry = 0 then Buy ... "

I can't understand the meaning of than sentence.
How can it be possible to be in marketposition = 1 if barssinceentry is 0,
Shouldn't barsinceentry be at least one?
 
Hi skan,
Barssinceentry are reset to zero whenever there is a new Open Position (Either Long or Short). So
"If marketposition = 1 and barssinceentry = 0 " means that the current bar has triggered the Long Position.

Using Intrabar Order Generation you will be able to retrieve the Marketposition in the real time. Or you have to use Look Inside BarBacktesting to read tick data within a minute data or minutes within minutes.(say 5 minutes within 60 minutes).
There may be other methods available to get the Marketposition status in the real time....
Good Luck
MGN.
 
Hi

But don't you know that position changed on the next bar, thus when barssinceentry = 1 ?
Or maybe it works differently if IntraBarOrdergeneration = TRUE
 
Hi skan

There are three types of market position:

Long Position (After "buying") = 1
Short Position = (After "Selling Short") -1
No Position = 0

Let's, for example, say your strategy requires you to "Buy next bar at Market"
This would mean that on the next bar you enter the market with a long position.
On the "entry bar" you have not been in the market for 1 complete bar. Therefore your "barssinceentry" is 0.
It is only on the bar after the entry bar (i.e. the second hour in your system) that you have had at least 1 bar completed since your entry.

Hope this helps.

BPV
 
Hi skan
Let's, for example, say your strategy requires you to "Buy next bar at Market"
This would mean that on the next bar you enter the market with a long position.
On the "entry bar" you have not been in the market for 1 complete bar. Therefore your "barssinceentry" is 0.
It is only on the bar after the entry bar (i.e. the second hour in your system) that you have had at least 1 bar completed since your entry.
BPV

but, in the same way, marketposition only changes from 0 to 1 when at the beginning of the next bar.
 
Marketposition is triggered by a BarStatus event. When the BarStatus = 2 then the changes occur. This will be the first tick after the "official" close of a bar.
 
Hello

I think the best way to visualize it would be a diagram.
An example, condition met in the middle of the second bar

111111112222222233333333444444445555555566666666 bar number
000000000000111111111111111111111111111111111111 condition
000000000000000001111111111111111111111111111111 marketposition
000000000000000000000000111111112222222223333333 barssinceentry

Is it right?
I thought barssinceentry changed in the third bar too.
How would it be if Intrabarordergeneration=true?
 
Your condition might be met in the middle of the bar, but MarketPosition will not change until the BarStatus changes from a 1 to a 2 which will be the first tick of the new official bar or the bar following your intrabar condition. BarsSinceEntry will = 0 on the same bar where MarketPosition changes since by definition it declares the entry here and it is the zero bar. So when you see MarketPosition change from a zero to a one then on the same bar where it changes you will start counting BarsSinceEntry starting from zero. This is assuming next bar market orders. If you are using this bar close orders then the MarketPosition change will also have a BarsSinceEntry value of one. Outside of stats gathering or novelty sake there is no realistic reason that I have seen for ever using a this bar close order since we should strive to reflect reality in our programming for testing purposes and there is no such thing as a this bar close order that executes in real life in the manner it does in testing.

you can see this easily by adding this line of code to your strategy.

print( time, " ", MarketPosition, " ", BarsSinceEntry ) ;

Using IOG and IntraBarPersist then the same things happen except this time every new tick increment that comes into your chart is treated as a "bar" and will execute your code and update variables. For instance a next bar market order will execute on the next available incoming tick and not wait until the end of the normal bar closing. If you have variables that you do not declare as intrabarpersist then those variables will update during the bar on each incoming tick, but then reset back to the previous bars value upon completion of a normal bar. The completion of the normal bar is determined by an BarStatus( 1 ) = 2 event
 
Top