MarketPosition Is Screwy

Questions about MultiCharts and user contributed studies.
Thomas Mann
Posts: 173
Joined: 25 Aug 2007

MarketPosition Is Screwy

Postby Thomas Mann » 12 Mar 2009

Hi,
I have a current strategt that gets the current MarketPosition and stores the results in a variable called MP. When I load a strategy I am working on I shows I am currently Long 1 contract yet my sim account is flat and holds no positions. How can this be ? I also tried turning on the auto trade to see if it reset the variable and I still show I am Long 1 contract. Any ideas ? I am using the latest beta. Attached is a snap shot showing my IB acct is flat and yet the code reports in a print statement I am L 1 contract.

Thanks
Attachments
Capture.jpg
(135.64 KiB) Downloaded 1181 times

SUPER
Posts: 633
Joined: 03 Mar 2007
Has thanked: 105 times
Been thanked: 81 times

Postby SUPER » 12 Mar 2009

Just like all Function/Variable values, MarketPosition is calculated based on the chart and not Broker, it is not possible to obtain "MarketPositionBroker" in MC.

Thomas Mann
Posts: 173
Joined: 25 Aug 2007

Postby Thomas Mann » 13 Mar 2009

Thanks Super,
That is messed up in my opinion sice I would not feel comfy running a auto trading system that does not know what the current position of a symbol is.

User avatar
Andrew Kirillov
Posts: 1589
Joined: 28 Jul 2005
Has thanked: 2 times
Been thanked: 31 times
Contact:

Postby Andrew Kirillov » 13 Mar 2009

We are going to add broker market position key word in the nearest versions.

SUPER
Posts: 633
Joined: 03 Mar 2007
Has thanked: 105 times
Been thanked: 81 times

Postby SUPER » 13 Mar 2009

Andrew,

That is great news, thank you very much.

Regards
Super

User avatar
Andrew Kirillov
Posts: 1589
Joined: 28 Jul 2005
Has thanked: 2 times
Been thanked: 31 times
Contact:

Postby Andrew Kirillov » 13 Mar 2009

We are considering of adding stop limit orders too.
We don't want to add a low level function. We want to integrate it to our engine which will mean
1. You can use plain English statements as you do with current stop, limit and open/close orders
2. Stop limit functions will work as they should in backtesting and you will be able to simulate real trading.
Considering that we are adding precise backtesting it is really important.

User avatar
TJ
Posts: 7380
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 996 times
Been thanked: 2110 times

Postby TJ » 13 Mar 2009

great stuff !

Thomas Mann
Posts: 173
Joined: 25 Aug 2007

Postby Thomas Mann » 14 Mar 2009

That would be Awesome Andrew. Thanks for the update
Could someone explain exactly what and how Intra Bar Order Generation is suppose to do. I still have not seen it work as expected yet. If I watch the profit amount in my live simulation account when a profit amount reaches where I have exits set they do not seem to activate until the next bar.


Thanks

User avatar
TJ
Posts: 7380
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 996 times
Been thanked: 2110 times

Postby TJ » 14 Mar 2009

with IOG,

sell short next bar at market;

has the same effect as

sell short next tick at market;

.

SUPER
Posts: 633
Joined: 03 Mar 2007
Has thanked: 105 times
Been thanked: 81 times

Postby SUPER » 14 Mar 2009

That would be Awesome Andrew. Thanks for the update
Could someone explain exactly what and how Intra Bar Order Generation is suppose to do. I still have not seen it work as expected yet. If I watch the profit amount in my live simulation account when a profit amount reaches where I have exits set they do not seem to activate until the next bar.


Thanks
Thomas here's something from TS forum. Hope it is of use.

"Intrabarordergeneration" if checked, orders can be generated as frequently as every tick during a bar. If unchecked, orders can be generated only on bar close (or at bar open for ‘open next bar’ strategies).

The setting is disabled by default. The value of the setting is associated with each individual strategy that is applied to a chart. Different strategies in the same strategy group may have different settings.

When ‘Enable intrabar order generation and calculation’ is checked a choice is provide to determine whether fills should occur more than once per bar.

• If ‘Limit entries from same signal in this strategy and exits from same signal in this strategy to once per bar’ is selected, each entry and exit order from the same signal can be filled only one time per bar (even if Position Limits settings have pyramiding enabled). This option is selected by default.

• If ‘Limit entries from all signals in this strategy and exits from all signals in this strategy to once per bar’ is selected, the strategy will enter and exit only once per bar.

• If ‘Allow any entry from this strategy and any exit from this strategy to occur multiple times per bar’ is selected, the strategy may enter and exit from the same or from different signals as many times per bar as conditions dictate.


What does [0] now mean?
When “Enable intrabar order generation” is enabled then [0] refers to the in-progress bar.


How will historical calculations work?
When “Enable intra-bar order generation” is disabled historical calculations will behave as they did in prior TS versions. When the intrabar calculation setting is enabled, historical calculations will vary based on the ‘Look-Inside-Bar’ back-testing settings:

- Historical calculations with Look-Inside-Bar Back-testing disabled:

When Look-Inside-Bar Back-testing disabled, historical strategy calculations will occur 4 times per bar on the Open, High, Low, and Close of the historical bar.

The actual calculation order will depend on the proximity of the high and low to the open. If the open is closer to the high then calculations will proceed in the following order: Open, High, Low, and then Close. If the open is closer to the low then calculations will proceed in the following order: Open, Low, High, and Close.

Volume is split between the 4 points (Volume / 4). Open interest will not be divided by 4

- Historical calculations with “Look-Inside-Bar Back-testing” enabled:

When Look-Inside-Bar Back-testing” is enabled, historical strategy calculations will occur on the Open, High, Low, and Close of each interim ‘Look-Inside’ bar. If using tick resolution, a calculation will occur on the tick only. The high and low will update on each interim Look-Inside bar to simulate the creation of a bar in progress. After the last Look-Inside bar is processed a calculation will occur one more time on the actual close of the bar.


Intrabar on Multiple Datastream Charts
Intrabar order generation is not allowed on multiple datastream charts.


Open next bar systems
Enable Intra-bar order generation is not allowed for open next bar systems. However, since calculations can occur on each tick during the bar, EasyLanguage code can detect the open of the bar and execute specific code at the open. This enables ‘open next bar’ type strategies to be rewritten as intrabar strategies, if desired.


How to write code that evaluates intrabar, and places orders intrabar?
Enable intra-bar order generation and calculation for the strategy on the Format Strategy Dialog – Calculation Tab.

Write the EasyLanguage code to place the order as a ‘next bar’ order; it will be active for the next tick for the in-progress bar.

For example:

if MarketPosition <> 1 and close > close[1] then
buy next bar at market ;

This will place a market order for the next tick of the in-progress bar, if the close of the current in-progress bar is greater than the close of the prior bar.


How to write code that evaluates intrabar, but places orders only on the bar close?
Use the BarStatus reserved word. For example:

If BarStatus(1) = 2 then
{ place orders for next bar }
buy next bar at market ;


IntrabarOrderGeneration EasyLanguage Attribute
An attribute has been added to EasyLanguage [IntrabarOrderGeneration=True/False] that allows the intrabar order generation capability to be turned on or off from within EasyLanguage. This attribute value will override the user interface setting in the Format Strategy dialog.

If the attribute is not present in the strategy code, the intrabar order generation and calculations setting will be controlled through the Calculations tab of the format Strategy window. If the attribute is present and set to TRUE, the ‘Enable intrabar order generation and calculation’ flag will be checked, the checkbox will be disabled, and the radio buttons will be available.

If the attribute is present and set to FALSE, the ‘Enable intrabar order generation and calculation’ flag will unchecked and the checkbox and radio buttons will be disabled.

The syntax for the attribute is as follows:

[IntrabarOrderGeneration = Value] where Value can be TRUE or FALSE

The attribute may only be used in a strategy. Attributes are evaluated at compile time only, so their values cannot be changed at run-time.

Usage Example:

[IntrabarOrderGeneration = FALSE] // Strategy will only generate orders at close of bar

1. EasyLanguage code executes by default on every "BarStatus(1)=2" tick. Each bar is closed by a BarStatus(1) = 2 tick. If 'intrabar order generation' is turned on, EasyLanguage code executes every tick.

2. In real time, bars are constructed 'tick by tick', regardless the bar interval. In history (use GetAppInfo(aiRealtimeCalc) <> 1 to identify historic calculations), bars are constructed from one data point consisting of an Open, High, Low and Close.

3. If "Intrabar order generation" is on, EasyLanguage code will execute on each live tick. Additionally, historic bars are treated as 5 ticks (Open, high, low, close with BarStatus(1) = 1, and a 'bar closing tick' with BarStatus(1)=2.

4. If "Look inside bar" backtesting is on, historical bars are treated as a sequence of small time frame bars. For example, a 5 minute bar can be treated as 5 one minute bars. In this case, EasyLanguage code will run 21 times (5 bars * 4 ticks/bar + 1 close of bar tick).

5. Look-inside-bar-backtesting can be done with tick resolution.

6. Daily bars with 1 tick look insidebar backtesting is possible, but can be very slow. Additionally, there is probably a limitation on the amount of tick history compared to the amount of daily bar history. When the 'intrabar' frequency does not have the date range called by the 'visible' chart bar interval and date-time range, an error message is delivered reporting the lack of 'intrabar' data.

To offer most specific assistance. please post your code and chart settings.

Intrabarpersist variables with intrabarordergeneration:

Test code 1:
variables:
Count( 0, data2 ) ;

Count = Count + 1 ;

print(BarNumber data1, " ", BarNumber data2," ", Count ) ;

Test code 2:
variables:
IntrabarPersist Count( 0, data2 ) ;

Count = Count + 1 ;

print(BarNumber data1, " ", BarNumber data2," ", Count ) ;
Attachments
_INTRABARTEST.ELD
(6.39 KiB) Downloaded 399 times
Last edited by SUPER on 23 Mar 2009, edited 1 time in total.

Thomas Mann
Posts: 173
Joined: 25 Aug 2007

Postby Thomas Mann » 22 Mar 2009

Hi Super,
Thanks a bunch for taking the time to try and explain this to me. I read thruough it a couple times and although I am not sure I understand it all I think I have a idea how to test and find what I am trying to determine. The eld you attached seems to be gone now so I hope MC did not remove it.
Thanks

User avatar
RobotMan
Posts: 375
Joined: 12 Jul 2006
Location: Los Altos, California, USA
Has thanked: 31 times
Been thanked: 13 times
Contact:

Postby RobotMan » 22 Mar 2009

You have to be logged-in to see/download it.

SUPER
Posts: 633
Joined: 03 Mar 2007
Has thanked: 105 times
Been thanked: 81 times

Postby SUPER » 23 Mar 2009

Hi Super,
Thanks a bunch for taking the time to try and explain this to me. I read thruough it a couple times and although I am not sure I understand it all I think I have a idea how to test and find what I am trying to determine. The eld you attached seems to be gone now so I hope MC did not remove it.
Thanks
Don't know why the download link stoped working, I have re-attached. Hopefully it should work now.


Return to “MultiCharts”