Preliminary documentation for new reserved words in MC7

Questions about MultiCharts and user contributed studies.
User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Preliminary documentation for new reserved words in MC7

Postby JoshM » 17 Sep 2011

Edit: The official MultiCharts Support documentation can be found here.

A downloadable PDF for off-line use can be found here.

-------------------------------------------------------------------------------------------------------

I don't know if the text below is the 'release version' of the documentation, or some beta or earlier version, but since it's already available on BigMikeTrading, I thought I re-post it here, since it's quite helpful and informative in my view.

I find it a little bit disappointing that, while Qweasz and myself were having troubles with some of the newly reserved words (an 'early-adopter' risk in my opinion), apparently other users had around the same time a form of documentation for this. I hope that by posting the list here other users don't have to reinvent the wheel before the official documentation is released. :)

Source: BigMikeTrading.

<quote start>
New PowerLanguage keywords
September 15, 2011

1. PosTradeCount
Returns a numerical value, indicating the total number of entries for the specified position.
Usage
PosTradeCount (PosBack)
Where: PosBack - a numerical expression, specifying the position:
0 - open position;
1 - one position back (the last position closed);
2 - two positions back, etc.

Notes
This function can only be used in signals.
Example
PosTradeCount (1) will return a value of 2 if there were two separate entries for the most recently closed position

2. PosTradeSize
Returns an absolute numerical value, indicating the number of contracts or shares in the specified trade.

Usage
PosTradeSize(PosAgo, TradeNumber)
Where: PosAgo - a numerical expression, specifying the position:
0 - open position;
1 - one position back (the last position closed);
2 - two positions back, etc.
TradeNumber - a numerical expression, specifying the number of trade (zero-based). To retrieve the total number of trades in specified position use PosTradeCount .

Notes
This function can only be used in signals.
Example
PosTradeSize(0,1) will return a value of 2 for the second trade of the open position, if this trade had a quantity of 2.

3. PosTradeCommission
Returns an absolute numerical value, indicating the commission amount spent for the specified trade.

Usage
PosTradeCommission(PosAgo, TradeNumber)
Where: PosAgo - a numerical expression, specifying the position:
0 - open position;
1 - one position back (the last position closed);
2 - two positions back, etc.
TradeNumber - a numerical expression, specifying the number of trade (zero-based). To retrieve the total number of trades in specified position use PosTradeCount

Notes
This function can only be used in signals.
Example
PosTradeCommission(0,1) will return a value of 5 for the second trade of the open position, if the commission for this trade is 5 dollars.

4. PosTradeProfit
Returns an absolute numerical value, indicating the profit (or loss if negative) of the specified trade.

Usage
PosTradeProfit(PosAgo, TradeNumber)
Where: PosAgo - a numerical expression, specifying the position:
0 - open position;
1 - one position back (the last position closed);
2 - two positions back, etc.
TradeNumber - a numerical expression, specifying the number of trade (zero-based). To retrieve the total number of trades in specified position use PosTradeCount

Notes
This function can only be used in signals.
Example
PosTradeProfit(0,1) will return a value of 3 for the second trade of the open position, if the profit for this trade is 3 dollars.

5. PosTradeEntryName
Returns entry order name. Entry Name is indicated on the chart and in Order and Position Tracker Window

Usage
PosTradeEntryName(PosAgo, TradeNumber)
Where: PosAgo - a numerical expression, specifying the position:
0 - open position;
1 - one position back (the last position closed);
2 - two positions back, etc.
TradeNumber - a numerical expression, specifying the number of trade (zero-based). To retrieve the total number of trades in specified position use PosTradeCount

Notes
This function can only be used in signals.
Example
PosTradeEntryName(0,1) will return a value of “buy LE” for the second trade of the open position, if this trade was opened by the order with “buy LE” name.

6. PosTradeEntryPrice
Returns an absolute numerical value, indicating the execution price of trade entry order.

Usage
PosTradeEntryPrice(PosAgo, TradeNumber)
Where: PosAgo - a numerical expression, specifying the position:
0 - open position;
1 - one position back (the last position closed);
2 - two positions back, etc.
TradeNumber - a numerical expression, specifying the number of trade (zero-based). To retrieve the total number of trades in specified position use PosTradeCount

Notes
This function can only be used in signals.
Example
PosTradeEntryPrice(0,1) will return a value of 100.2 for the second trade of the open position, if this trade was opened by the order filled at 100.2

7. PosTradeEntryBar
Returns an absolute numerical value, indicating bar number of the trade entry order.

Usage
PosTradeEntryBar(PosAgo, TradeNumber)
Where: PosAgo - a numerical expression, specifying the position:
0 - open position;
1 - one position back (the last position closed);
2 - two positions back, etc.
TradeNumber - a numerical expression, specifying the number of trade (zero-based). To retrieve the total number of trades in specified position use PosTradeCount

Notes
This function can only be used in signals.
Example
PosTradeEntryBar(0,1) will return a value of 25 for the second trade of the open position, if this trade was opened on 25th bar.

8. PosTradeEntryCategory
Returns an absolute numerical value, indicating trade entry order category. The following types are possible:

1 = Stop order (buy next bar at close - 1 point stop)
2 = Limit order (buy next bar at close + 1 point limit)
3 = Market order (buy next bar market)
4 = Market at Close order (buy this bar at close)
5 = Market at open order (buy next bar open)
8 = StopLimit order (buy 1 contracts next bar at close - 2 point stop close + 2 point limit)

Usage
PosTradeEntryCateory(PosAgo, TradeNumber)
Where: PosAgo - a numerical expression, specifying the position:
0 - open position;
1 - one position back (the last position closed);
2 - two positions back, etc.
TradeNumber - a numerical expression, specifying the number of trade (zero-based). To retrieve the total number of trades in specified position use PosTradeCount

Notes
This function can only be used in signals.
Example
PosTradeEntryCategory(0,1) will return a value of 1 for the second trade of the open position, if the order type was Stop Order

9. PosTradeExitName
Returns exit order name. Exit Name is indicated on the chart and in Order and Position Tracker Window

Usage
PosTradeExitName(PosAgo, TradeNumber)
Where: PosAgo - a numerical expression, specifying the position:
0 - open position;
1 - one position back (the last position closed);
2 - two positions back, etc.
TradeNumber - a numerical expression, specifying the number of trade (zero-based). To retrieve the total number of trades in specified position use PosTradeCount

Notes
This function can only be used in signals.
Example
PosTradeExitName(0,1) will return a value of “sell LX” for the second trade of the open position, if this trade was closed by the order with “sell LX” name.

10. PosTradeExitPrice
Returns an absolute numerical value, indicating the execution price of trade exit order.

Usage
PosTradeExitPrice(PosAgo, TradeNumber)
Where: PosAgo - a numerical expression, specifying the position:
0 - open position;
1 - one position back (the last position closed);
2 - two positions back, etc.
TradeNumber - a numerical expression, specifying the number of trade (zero-based). To retrieve the total number of trades in specified position use PosTradeCount

Notes
This function can only be used in signals.
Example
PosTradeExitPrice(0,1) will return a value of 100.5 for the second trade of the open position, if this trade was closed by the order filled at 100.5.

11. PosTradeExitBar

Returns an absolute numerical value, indicating bar number of the trade exit order.

Usage
PosTradeExitBar(PosAgo, TradeNumber)
Where: PosAgo - a numerical expression, specifying the position:
0 - open position;
1 - one position back (the last position closed);
2 - two positions back, etc.
TradeNumber - a numerical expression, specifying the number of trade (zero-based). To retrieve the total number of trades in specified position use PosTradeCount

Notes
This function can only be used in signals.
Example
PosTradeExitBar(0,1) will return a value of 28 for the second trade of the open position, if this trade was closed on 28th bar.

12. PosTradeExitCategory
Returns an absolute numerical value, indicating trade exit order category. The following types are possible:

1 = Stop order (buy next bar at close - 1 point stop)
2 = Limit order (buy next bar at close + 1 point limit)
3 = Market order (buy next bar market)
4 = Market at Close order (buy this bar at close)
5 = Market at open order (buy next bar open)
8 = StopLimit order (buy 1 contracts next bar at close - 2 point stop close + 2 point limit)

Usage
PosTradeExitCateory(PosAgo, TradeNumber)
Where: PosAgo - a numerical expression, specifying the position:
0 - open position;
1 - one position back (the last position closed);
2 - two positions back, etc.
TradeNumber - a numerical expression, specifying the number of trade (zero-based). To retrieve the total number of trades in specified position use PosTradeCount

Notes
This function can only be used in signals.
Example
PosTradeExitCategory(0,1) will return a value of 3 for the second trade of the open position, if the closing order type was Market Order.

13. PosTradeIsOpen
Returns True value if the trade is open, False value if the trade is closed. It makes sense to check the trades of the open position. For other positions False is always returned.

Usage
PosTradeIsOpen(PosAgo, TradeNumber)
Where: PosAgo - a numerical expression, specifying the position:
0 - open position;
1 - one position back (the last position closed);
2 - two positions back, etc.
TradeNumber - a numerical expression, specifying the number of trade (zero-based). To retrieve the total number of trades in specified position use PosTradeCount

Notes
This function can only be used in signals.
Example
PosTradeIsOpen(0,1) will return True for the second trade of the open position, if this trade is opened (haven’t close order).

14. PosTradeIsLong
Returns True value if the trade was opened by buy order, otherwise False value is returned.

Usage
PosTradeIsLong(PosAgo, TradeNumber)
Where: PosAgo - a numerical expression, specifying the position:
0 - open position;
1 - one position back (the last position closed);
2 - two positions back, etc.
TradeNumber - a numerical expression, specifying the number of trade (zero-based). To retrieve the total number of trades in specified position use PosTradeCount

Notes
This function can only be used in signals.
Example
PosTradeIsLong(0,1) will return True for the second trade of the open position, if this trade was opened by “buy” order.

15. PosTradeEntryDateTime
Returns double-precision decimal DateTime for entry order. As an example see computerdatetime .

Usage
PosTradeEntryDateTime(PosAgo, TradeNumber)
Where: PosAgo - a numerical expression, specifying the position:
0 - open position;
1 - one position back (the last position closed);
2 - two positions back, etc.
TradeNumber - a numerical expression, specifying the number of trade (zero-based). To retrieve the total number of trades in specified position use PosTradeCount

Notes
This function can only be used in signals.

16. PosTradeExitDateTime
Returns double-precision decimal DateTime for exit order. As an example see computerdatetime .

Usage
PosTradeExitDateTime(PosAgo, TradeNumber)
Where: PosAgo - a numerical expression, specifying the position:
0 - open position;
1 - one position back (the last position closed);
2 - two positions back, etc.
TradeNumber - a numerical expression, specifying the number of trade (zero-based). To retrieve the total number of trades in specified position use PosTradeCount

Notes
This function can only be used in signals.

17. Portfolio_InvestedCapital
Returns absolute value in US dollars, indicating the amount of cash assets invested in portfolio securities on the moment of strategy calculation.

18. Entryname
Returns the name of the order which opened the position.

Usage

EntryName(TradeNumber)
Where: TradeNumber - a numerical expression, specifying the number of trade (zero-based).

Notes
Same as PosTradeEntryName(0, TradeNumber).

19. Exitname
Returns the name of the order which closed the position.

Usage

ExitName(TradeNumber)
Where: TradeNumber - a numerical expression, specifying the number of trade (zero-based).

Notes
Same as PosTradeExitName(0, TradeNumber).

20. AvgEntryPrice_at_Broker_for_The_Strategy
Returns a numerical value, indicating the average entry price at the broker for the strategy.
A positive value indicates a long position and a negative value indicates a short position. A zero ('0') is returned when the current position is flat, or if Automated Trading is not turned on.

Usage

AvgEntryPrice_at_Broker_for_The_Strategy

Notes
This function can only be used in signals and functions.

Important
If Automated Trading was manually turned off by the user, the value returned by the keyword stops changing, and may remain unequal to '0'.

21. AvgEntryPrice_at_Broker
Returns a numerical value, indicating the average entry price at the broker for the symbol.
A positive value indicates a long position and a negative value indicates a short position.
A zero ('0') is returned when the current position is flat, or if Automated Trading is not turned on.

Usage

AvgEntryPrice_at_Broker

Notes
This function can only be used in signals and functions.
This function can only be used with Interactive Brokers, Patsystems, and Zen-Fire.

Important
If Automated Trading was manually turned off by the user, the value returned by the keyword stops changing, and may remain unequal to '0'

22. q_time_s
Same as q_time. Time is indicated in HHmmss format.

23. ClearPrintLog
Same as cleardebug.

24. mc_tl_getactive
Returns a numerical value indicating the trendline ID number of the currently selected trendline; returns a value of -1 if no trendlines are currently selected.

Usage

Mc_tl_GetActive

Notes
A trendline-specific ID number is assigned by mc_tl_New when the trendline is created.

Example

Assign a value, indicating the trendline ID number of the currently selected trendline, to Value1 variable:
Value1=mc_TL_GetActive;

25. tl_getactive
This reserved word returns a numeric value representing the ID of the currently active trendline..

Value1 = TL_GetActive();

Value1 is any numeric variable or array. You must assign the trendline reserved word to a numeric variable or array so that you can determine whether or not the reserved word performed its operation successfully.

Remarks

When the reserved word performs its operation successfully, a 0 is returned. When a reserved word cannot perform its operation, it returns an error code.

26. mc_arw_getactive
Returns a numerical value indicating the arrow ID number of the currently selected arrow; returns a value of -1 if no arrows are currently selected.

Usage

Mc_arw_GetActive

Example

Assign a value, indicating the arrow ID number of the currently selected arrow, to Value1 variable:
Value1=mc_arw_GetActive;

27. mc_text_getactive
Returns a numerical value indicating the text ID number of the currently selected text; returns a value of -1 if no text is currently selected.

Usage

Mc_text_GetActive

Example

Assign a value, indicating the text ID number of the currently selected text, to Value1 variable:
Value1=mc_text_GetActive;

28. Boxsize
Returns the price-based interval setting associated with the specified price-based chart type an indicator or signal is applied to.
This value is set in the Chart Type section of the Settings tab within the Format Instrument dialog for a chart.

Chart Type Value Returned
Point & Figure Box Size value
Point Point value
Renko Box Size value

29. Revsize
Returns the Reversal of a Point & Figure chart, the Reversalof a Kagi chart, or the number of Line Breaks in a Line Break chart. This value is set in the Chart Type section of the Settings tab within the Format Instrument dialog for a chart.
Example
RevSize returns 2 if the reversal size of a P & F chart is set to 2.
RevSize returns 5 if the number of line breaks for a Line Break chart is set to 5.
RevSize returns 4 if the reversal size of a Kagi chart is set to 4%.

30. RecalcLastBarAfter
Initializes the calculation after expiration of the timeout, set in seconds

Usage

RecalcLastBarAfter(timeout)
Where timeout indicates the number of seconds.

Notes
RecalcLastBarAfter is used for the slow markets. Calculation of the studies is performed in events when the immediate tick has come to a chart. When the tick has not come since the moment of the last calculation and during timeout (sec) a new calculation is being initialized. When the tick has been received before timeout expiration, time counter is reset and countdown for RecalcLastBarAfter(timeout) starts anew

31. i_AvgEntryPrice_at_Broker

Returns the Average entry price of each open entry in a pyramided position.
Notes
I_AvgEntryPrice only returns the average entry price for open trades.
I_AvgEntryPrice can only be used in an indicator.
I_AvgEntryPrice will only return a value if a signal is applied to the same data.

Example
I_AvgEntryPrice returns 170 if three trades are currently open and were entered at a price of 140, 170, and 200.
I_AvgEntryPrice returns 53 if four trades are currently open and were entered at a price of 54, 48, 60, and 50.

32. i_AvgEntryPrice_at_Broker_for_The_Strategy
Is used for the extraction of strategy information in indicator. Returns the same information as AvgEntryPrice_at_Broker_for_The_Strategy.

33. PlaceMarketOrder
Places market order at the broker without position changing on the chart

Usage
PlaceMarketOrder(IsBuy, IsEntry, Contracts)

Where:

IsBuy indicates whether order is buy or sell,
IsEntry indicates whether order is entry or exit,
Contracts indicates the number of contracts/shares of the order.

Notes
Works with auto trading turned off. Can be used as a mean of synchronization of strategy market position with a broker

34. ChangeMarketPosition
Places the order with set name and price on the chart. Though when auto trading is off the order will not be sent to a broker.

Usage

ChangeMarketPosition(Delta, Price, Name)

Where
Delta – number of contracts by which current market position should be changed.
Price – order filling price.
Name – name of the order that changes the position.

Notes
Can be used as a mean of synchronization of strategy market position with a broker

Example

If marketposition = 2 then ChangeMarketPosition(-2, 100, “LX”)
Will place close order with the name “LX” and the price 100 if current marketposition =2

If marketposition = 0 then ChangeMarketPosition(-2, 100, “SE”)
Will place open order with the name “SE” and the price 100 if current marketposition =0

35. OpenEntriesCount
Same as CurrentEntries.

36. OpenEntryDate
Returns a numerical value, indicating the date of specified entry into the open position. The date is indicated in the YYYMMdd format, where YYY is the number of years since 1900, MM is the month, and dd is the day of the month.

Usage

OpenEntryDate(EntryIndex)
Where: EntryIndex - a numerical expression, specifying the number of trade (zero-based). To retrieve the total number of trades in open position use OpenEntriesCount

Notes
This function can only be used in signals.

Example

OpenEntryDate(1) will return 1110402 for the open position if the second trade was generated at April 2nd, 2011.

37. OpenEntryTime
Returns a numerical value, indicating the time of specified entry into the open position. The time is indicated in the HHmm format, where HH is the hour in 24 hours format and mm are minutes.

Usage

OpenEntryTime(EntryIndex)
Where: EntryIndex - a numerical expression, specifying the number of trade (zero-based). To retrieve the total number of trades in open position use OpenEntriesCount

Notes
This function can only be used in signals.

38. OpenEntryPrice
Returns a numerical value, indicating the price of specified entry into the open position.

Usage

OpenEntryPrice(EntryIndex)
Where: EntryIndex - a numerical expression, specifying the number of trade (zero-based). To retrieve the total number of trades in open position use OpenEntriesCount

Notes
This function can only be used in signals.

39. OpenEntryContracts
Returns a numerical value, indicating the Quantity of contracts of specified entry order into the open position.

Usage
OpenEntryContracts(EntryIndex)
Where: EntryIndex - a numerical expression, specifying the number of trade (zero-based). To retrieve the total number of trades in open position use OpenEntriesCount

Notes
This function can only be used in signals.

40. OpenEntryProfit
Returns a numerical value, indicating the profit (loss if negative) of specified entry into the open position in dollars.

Usage
OpenEntryProfit(EntryIndex)
Where: EntryIndex - a numerical expression, specifying the number of trade (zero-based). To retrieve the total number of trades in open position use OpenEntriesCount

Notes
This function can only be used in signals.

41. OpenEntryMaxProfit
Returns a numerical value, indicating maximal value of OpenEntryProfit for the time from entry order execution

Usage
OpenEntryMaxProfut(EntryIndex)
Where: EntryIndex - a numerical expression, specifying the number of trade (zero-based). To retrieve the total number of trades in open position use OpenEntriesCount

Notes
This function can only be used in signals.

42. OpenEntryMinProfit
Returns a numerical value, indicating minimal value of OpenEntryProfit for the time from entry order execution

Usage
OpenEntryMinProfut(EntryIndex)
Where: EntryIndex - a numerical expression, specifying the number of trade (zero-based). To retrieve the total number of trades in open position use OpenEntriesCount

Notes
This function can only be used in signals.

43. OpenEntryProfitPerContract
Returns a numerical value, indicating the profit (loss if negative) per contract of specified entry in dollars.

Usage
OpenEntryProfitPerContract(EntryIndex)
Where: EntryIndex - a numerical expression, specifying the number of trade (zero-based). To retrieve the total number of trades in open position use OpenEntriesCount

Notes
This function can only be used in signals.

44. OpenEntryMaxProfitPerContract
Returns a numerical value, indicating maximal value of OpenEntryProfitPerContract for the time from entry order execution

Usage
OpenEntryMaxProfitPerContract(EntryIndex)
Where: EntryIndex - a numerical expression, specifying the number of trade (zero-based). To retrieve the total number of trades in open position use OpenEntriesCount

Notes
This function can only be used in signals.

45. OpenEntryMinProfitPerContract
Returns a numerical value, indicating minimal value of OpenEntryProfitPerContract for the time from entry order execution

Usage
OpenEntryMinProfitPerContract(EntryIndex)
Where: EntryIndex - a numerical expression, specifying the number of trade (zero-based). To retrieve the total number of trades in open position use OpenEntriesCount

Notes
This function can only be used in signals.

46. OpenEntryComission
Returns a numerical value, indicating the amount of cash assets in US dollars spent on the commission for specified trade.

Usage
OpenEntryComission(EntryIndex)
Where: EntryIndex - a numerical expression, specifying the number of trade (zero-based). To retrieve the total number of trades in open position use OpenEntriesCount

Notes
This function can only be used in signals.

47. Not
Used in TrueFalse statements – negative

Example
condition1 = true;
condition2 = not condition1;
Assigns to condition2 value opposite to condition1.

Other changes

i_openequity –
Returns the current equity = netprofit + openpositionprofit
Usage
i_OpenEquity
Notes
This function can only be used in studies.
Example
i_OpenEquity will return 100 if the current equity is 100.
i_OpenEquity will return -100 if the current equity is -100.

</quote end>
Last edited by JoshM on 07 Oct 2011, edited 2 times in total.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Preliminary documentation for new reserved words in MC7

Postby Henry MultiСharts » 20 Sep 2011

This information will be present in the updated MultiCharts help file.
This is not the final version.

User avatar
Stan Bokov
Posts: 963
Joined: 18 Dec 2009
Has thanked: 367 times
Been thanked: 302 times

Re: Preliminary documentation for new reserved words in MC7

Postby Stan Bokov » 23 Sep 2011

I find it a little bit disappointing that, while Qweasz and myself were having troubles with some of the newly reserved words (an 'early-adopter' risk in my opinion), apparently other users had around the same time a form of documentation for this.
The prelim doc was completed and released to BigMike the day it was posted on BMT. You beat us to the punch by posting it here, it was going to be posted by us.

khalaad
Posts: 323
Joined: 07 Jan 2007
Location: Lahore, Pakistan
Has thanked: 64 times
Been thanked: 57 times

Re: Preliminary documentation for new reserved words in MC7

Postby khalaad » 24 Sep 2011

The prelim doc was completed and released to BigMike the day it was posted on BMT. You beat us to the punch by posting it here, it was going to be posted by us.
No disregard for BigMike, but the document should have appeared here first!

Khalid

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

Re: Preliminary documentation for new reserved words in MC7

Postby TJ » 24 Sep 2011

I think the new keyword mc_tl_getactive
would sound more meaningful if it were
tl_getselected.

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Re: Preliminary documentation for new reserved words in MC7

Postby bowlesj3 » 25 Sep 2011

I think the new keyword mc_tl_getactive
would sound more meaningful if it were
tl_getselected.
I agree, or a variant would be tl_gethighlighted except it is a bit long.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Preliminary documentation for new reserved words in MC7

Postby Henry MultiСharts » 26 Sep 2011

Thank you for your feedback.
We do not plan to change the name of the code word "mc_tl_getactive" at the moment.

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Re: Preliminary documentation for new reserved words in MC7

Postby bowlesj3 » 26 Sep 2011

I agree Henry. It is not worth changing the name. However maybe the manual could be

MC_TL_GetActive (Get Currently Selected/Highlighted)

This would give the new user an immediate hint as to the difference from the TS version. Event better if the TS version had a similar bracketed hint. I could use the TS version hint right now.

janus
Posts: 835
Joined: 25 May 2009
Has thanked: 63 times
Been thanked: 104 times

Re: Preliminary documentation for new reserved words in MC7

Postby janus » 27 Sep 2011

I agree Henry. It is not worth changing the name. However maybe the manual could be

MC_TL_GetActive (Get Currently Selected/Highlighted)

This would give the new user an immediate hint as to the difference from the TS version. Event better if the TS version had a similar bracketed hint. I could use the TS version hint right now.
I agree.

Also, I like Big Mike's forum style; very easy on the eyes, more intuitive and nicer looking. Sorry.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Preliminary documentation for new reserved words in MC7

Postby Henry MultiСharts » 28 Sep 2011

bowlesj3, janus, thank you for your suggestions.
I will forward your requests regarding the hint and forum to the appropriate departments.

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Preliminary documentation for new reserved words in MC7

Postby JoshM » 06 Oct 2011

1. PosTradeCount
Returns a numerical value, indicating the total number of entries for the specified position.
Usage
PosTradeCount (PosBack)
Where: PosBack - a numerical expression, specifying the position:
0 - open position;
1 - one position back (the last position closed);
2 - two positions back, etc.

Notes
This function can only be used in signals.
Example
PosTradeCount (1) will return a value of 2 if there were two separate entries for the most recently closed position
A question and a comment about this newly reserved word:

1) Is there a way to receive the number of exits for a specified position?

2) PosTradeCount returns the number of exits if there are multiple exits with one entry, but returns the number of entries if there is more than one entry.

If this is by design, the documentation needs to be somewhat changed, because it now suggests that PosTradeCount only returns the number of entries, which is only true if there is more than one entry - otherwise it returns the number of exits.

For example:

Code: Select all

variables: MP(0), startTime(630), endTime(2200), shortCondition(False), maFast(0), maSlow(0), posSize(1000);

maFast = XAverage(Close, 5);
maSlow = XAverage(Close, 15);

shortCondition = (Momentum(Close, MomentumPeriod) > Momentum(Close, MomentumPeriod)[1]);

if Time > startTime and Time < endTime and shortCondition = true then begin
if maFast crosses under maSlow then begin
SellShort("ES MKT") posSize contracts next bar at market;
end;
end;

// Exit Short 1
if (maFast crosses over maSlow) or (Time > endTime) then begin
BuyToCover("XS MKT1") (posSize / 2) contracts next bar at market;
end;

// Exit short 2
if (maFast[1] crosses over maSlow[1]) and (maFast > maSlow) then
BuyToCover("XS MKT2") (posSize / 2) contracts next bar at market;

MP = MarketPosition;

if MP[0] <> MP[1] and MP[1] <> 0 then begin

posProfit = CalculatePositionProfit(3);
Print("PosTradeCount: ", PosTradeCount(1));

end;
..returns:
PosTradeCount: 2.00
PosTradeCount: 2.00
PosTradeCount: 2.00
PosTradeCount: 2.00
Regards,
Josh

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Preliminary documentation for new reserved words in MC7

Postby JoshM » 06 Oct 2011

1) Is there a way to receive the number of exits for a specified position?
Since I was stuck with this, I wasn't very patient and wrote an email to support with this question. Sadly, I didn't formulate my point clear enough and wasted someone's time (sorry Dave ;) ). However, when I typed off my response, I realized it wasn't that urgent so I thought it was an better idea to post it here on the forum.

To answer my own question quoted above, one can use a manual counter for this (see code example below), but only after a MarketPosition change (so no looping through the trades in a 'if LastBarOnChart_s'-code block) (though the counter variable can be 'serialized' of course).

However, some questions/comments do remain:

1) The PosTradeCount() reserved word gives "total number of entries for the specified position." My question: is there a reserved word that does the same for the number of exits for a specified position?

2) Point 2 is more a comment, and that is: PosTradeCount() does not work, or the documentation is wrong, or I don't understand any of it :).

Look for example at the following code:

Code: Select all

Variables: maQuick(0), maSlow(0), MP(0), posSize(1000), numOfEntries(0);

once cleardebug;
maQuick = XAverage(Close, 5);
maSlow = XAverage(Close, 15);
MP = MarketPosition;

// Enter short #1
if MP = 0 and MP[1] = 0 and maQuick crosses under maSlow then begin
SellShort("ES #1") (posSize / 2) contracts next bar at market;
numOfEntries = 1;
end;

// Enter short #2
if MP = -1 and BarsSinceEntry(0) >= 5 then begin
numOfEntries = numOfEntries + 1;
SellShort("ES #2") (posSize / 2) contracts next bar at market;
end;

if MP = -1 and maQuick crosses over maSlow then
BuyToCover("XS #1") next bar at market;

if MP = 0 and MP[1] <> 0 then begin

Print("PosTradeCount: ", PosTradeCount(1), " Number of entries: ", numOfEntries);

numOfEntries = 0;
end;
..which gives the following output:
PosTradeCount: 1.00 Number of entries: 1.00
PosTradeCount: 1.00 Number of entries: 7.00
PosTradeCount: 1.00 Number of entries: 1.00
PosTradeCount: 1.00 Number of entries: 20.00
PosTradeCount: 1.00 Number of entries: 19.00
PosTradeCount: 1.00 Number of entries: 9.00
PosTradeCount: 1.00 Number of entries: 40.00
PosTradeCount: 1.00 Number of entries: 4.00
PosTradeCount: 1.00 Number of entries: 1.00
PosTradeCount: 1.00 Number of entries: 8.00
PosTradeCount: 1.00 Number of entries: 1.00
...
Also looking at the chart I see clearly more than one entry orders:
Image

--> Am I doing something very wrong, or does PosTradeCount() also give wrong values for you?

Looking forward to hear your opinions about this,

Regards,
Josh
Attachments
entryOrders.PNG
(9.96 KiB) Downloaded 3856 times

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Preliminary documentation for new reserved words in MC7

Postby JoshM » 07 Oct 2011

For personal use, I've put the documentation from the first post of this thread into a PDF with bookmarks for easy searching and off-line use. Since others users might also be interested in that, I've attached the PDF to this post. :)

Regards,
Josh
Attachments
newReservedWords_MC7.pdf
(419.09 KiB) Downloaded 701 times

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Preliminary documentation for new reserved words in MC7

Postby Henry MultiСharts » 07 Oct 2011

Hello Josh.
There is a mistake in the help file.
1. PosTradeCount
Returns a numerical value, indicating the total number of Trades for the specified position.
Now you can see that the output is correct.
Sorry for misinformation. We will fix the help file.

vking
Posts: 235
Joined: 21 May 2009
Has thanked: 51 times
Been thanked: 41 times

Re: Preliminary documentation for new reserved words in MC7

Postby vking » 10 Oct 2011

JoshM - Thanks a lot for preparing this PDF file. Appreciate it.
For personal use, I've put the documentation from the first post of this thread into a PDF with bookmarks for easy searching and off-line use. Since others users might also be interested in that, I've attached the PDF to this post. :)

Regards,
Josh

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Preliminary documentation for new reserved words in MC7

Postby JoshM » 11 Oct 2011

I noticed something that I thought was weird with the new PosTrade.. reserved words, and contacted Henry through MC Support for this and his explanation made it clear to me how these PosTrade.. words deal with trades that have multiple exits but only one entry (or vice versa). I thought I should share here what I've learned (thanks to Henry :), though any errors below remain mine):

Trades are something different than orders
In most of the PosTrade.. reserved words below, one of the arguments to use the function is the ‘tradenumber’. It’s important to note here that orders and trades are different things. Since PosTrade.. reserved words refer to trades, and not orders, one order can open two different trades.

For example, if you open a position with a buy order for 2 contracts, and close the position with two orders, both with a different name, there are for the entry into the position two trades (but not two entries), that were opened by one order (buy 2 contracts) and closed by two different orders.

So, the PosTradeEntryName() will in that case return values for two trades, both with the same entry name, though you entered the position with one order.

For example, this trade..
Image

..in which there is an entry named “ES MKT” for 1000 forex units, and two separate exits (an “XS MKT1” for 500 units and an “XS MKT2” for the remaining 500 units). Now, note that this position is opened with one entry order and closed with two exit orders. However, since trades are something different than orders, the position pictured above consists of 2 entry trades and 2 exit trades.

For example, if we call the PosTrade.. reserved words for this trade with:

Code: Select all

Variables: MP(0), posAgo(0), numOfTrades(0);

MP = MarketPosition;

if MP[0] <> MP[1] and MP[1] <> 0 then begin

Print(Date:0:0, " - ", time_s:0:0, " Position closed:");

pasAgo = 1; // get the data for the latest position
numOfTrades = PosTradeCount(posAgo); // get the number of trades for that position

// Loop through the entry orders
for value1 = 0 to (numOfTrades - 1) begin

Print(Spaces(3), "EntryOrder: ", PosTradeEntryName(posAgo, value1),
" units: ", NumToStr(PosTradeSize(posAgo, value1), 0),
" @ ", NumToStr(PosTradeEntryPrice(posAgo, value1), 5),
" PosTradeCount: ", PosTradeCount(posAgo));

end;

// Loop through the exit trades
for value5 = 0 to (numOfTrades - 1) begin

Print(Spaces(3), "ExitOrder: ", PosTradeExitName(posAgo, value5),
" units: ", NumToStr(PosTradeSize(posAgo, value5), 0),
" @ ", NumToStr(PosTradeExitPrice(posAgo, value5), 5),
" PosTradeCount: ", PosTradeCount(posAgo));

end;
end;
We’ll get the following output, showing that the entry consists of two trades (though it’s entered with one order):

Code: Select all

1110720 - 114600 Position closed:
EntryOrder: ES MKT units: 500 @ 1.41798 PosTradeCount: 2.00
EntryOrder: ES MKT units: 500 @ 1.41798 PosTradeCount: 2.00
ExitOrder: XS MKT1 units: 500 @ 1.42037 PosTradeCount: 2.00
ExitOrder: XS MKT2 units: 500 @ 1.42043 PosTradeCount: 2.00
Attachments
exampleTrade.PNG
(4.07 KiB) Downloaded 3702 times

User avatar
MC_Prog
Posts: 330
Joined: 28 Feb 2007
Has thanked: 64 times
Been thanked: 35 times

Re: Preliminary documentation for new reserved words in MC7

Postby MC_Prog » 17 Nov 2011

Hi. After a bit of study and experimentation, I'd like to suggest an edit to the Help file.

Instead of this:

34. ChangeMarketPosition
Places the order with set name and price on the chart. Though when auto trading is off the order will not be sent to a broker.


I suggest this:

34. ChangeMarketPosition
Places the order with set name and price on the chart (only). The order placed is NEVER sent to the broker, even when auto trading is ON.

This reflects my understanding of the facts, to wit, that ChangeMarketPosition is intended to adjust the state of your strategy/chart (specifically, the MarketPosition), and does not ever send instructions to the broker or alter the position reported by the broker.

Have I got this right?

janus
Posts: 835
Joined: 25 May 2009
Has thanked: 63 times
Been thanked: 104 times

Re: Preliminary documentation for new reserved words in MC7

Postby janus » 17 Nov 2011

34. ChangeMarketPosition
Places the order with set name and price on the chart (only). The order placed is NEVER sent to the broker, even when auto trading is ON.

This reflects my understanding of the facts, to wit, that ChangeMarketPosition is intended to adjust the state of your strategy/chart (specifically, the MarketPosition), and does not ever send instructions to the broker or alter the position reported by the broker.

Have I got this right?
I haven't yet used the new reserved words but I will soon to synch up properly when I disconnect and re-connect MC with the broker's system. I hope someone from support responds.

Also, why is all this so complicated? MC should keep track of orders on the broker side, including details of the time and number of trades so that it can replicate the status on the charts at any time even if the trades were done manually at the broker's interface (eg, TWS with IB). It's what I would expect from any professional real-time trading system, be it automatic or the traditional manual ones. Clearly it is as important and relevant in the case of automatic trading systems to do this. If one thinks about it why would anyone prefer to have the two systems out of synch? They should always be in synch otherwise the strategy is useless for real-time trading purposes.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Preliminary documentation for new reserved words in MC7

Postby Henry MultiСharts » 18 Nov 2011

Hi. After a bit of study and experimentation, I'd like to suggest an edit to the Help file.

Instead of this:

34. ChangeMarketPosition
Places the order with set name and price on the chart. Though when auto trading is off the order will not be sent to a broker.


I suggest this:

34. ChangeMarketPosition
Places the order with set name and price on the chart (only). The order placed is NEVER sent to the broker, even when auto trading is ON.

This reflects my understanding of the facts, to wit, that ChangeMarketPosition is intended to adjust the state of your strategy/chart (specifically, the MarketPosition), and does not ever send instructions to the broker or alter the position reported by the broker.

Have I got this right?
Yes Sir your observation is correct. The order is not sent to a broker.
We will fix the descripton. Thank you.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Preliminary documentation for new reserved words in MC7

Postby Henry MultiСharts » 18 Nov 2011

I haven't yet used the new reserved words but I will soon to synch up properly when I disconnect and re-connect MC with the broker's system. I hope someone from support responds.
Please describe what do you mean.
Also, why is all this so complicated? MC should keep track of orders on the broker side, including details of the time and number of trades so that it can replicate the status on the charts at any time even if the trades were done manually at the broker's interface (eg, TWS with IB). It's what I would expect from any professional real-time trading system, be it automatic or the traditional manual ones. Clearly it is as important and relevant in the case of automatic trading systems to do this. If one thinks about it why would anyone prefer to have the two systems out of synch? They should always be in synch otherwise the strategy is useless for real-time trading purposes.
MC keeps track of orders on the broker side if it is connected to the broker, it can replicate the status on the charts.
Please describe your exact situation and we will provide a solution for you.

janus
Posts: 835
Joined: 25 May 2009
Has thanked: 63 times
Been thanked: 104 times

Re: Preliminary documentation for new reserved words in MC7

Postby janus » 18 Nov 2011

What I mean is the ability for MC to synch perfectly with the status of all open contracts and orders at the broker's side after each time one exits then re-enters MC, without the need to program a study to do it. This includes the placement of the necessary arrows on the charts at the right dates and times. For example if a study issued a stop order to IB and it's sent to the broker, and then one exists MC, then the stop order is hit and filled while MC is not running, then one starts up MC, the filled order is displayed on the appropriate chart at the correct location in terms of price and time automatically.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Preliminary documentation for new reserved words in MC7

Postby Henry MultiСharts » 21 Nov 2011

What I mean is the ability for MC to synch perfectly with the status of all open contracts and orders at the broker's side after each time one exits then re-enters MC, without the need to program a study to do it.
Happens already for all trades that were actually filled at the broker, upon connection all existing trades are read from the broker list, and displayed on the chart.
This includes the placement of the necessary arrows on the charts at the right dates and times. For example if a study issued a stop order to IB and it's sent to the broker, and then one exists MC, then the stop order is hit and filled while MC is not running, then one starts up MC, the filled order is displayed on the appropriate chart at the correct location in terms of price and time automatically.
That is already done.
MultiCharts populates Order and Position Tracker window “Orders tab", as well as the chart, with the data from the brokers who provide order history.
Keep in mind that order history is not provided by all supported brokers, we cannot guarantee the accuracy of the information sent by the broker.

janus
Posts: 835
Joined: 25 May 2009
Has thanked: 63 times
Been thanked: 104 times

Re: Preliminary documentation for new reserved words in MC7

Postby janus » 21 Nov 2011

I stand corrected then. This is such great news I'll now accelerate the migration of my studies to the latest version of MC to test these new features.

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Preliminary documentation for new reserved words in MC7

Postby JoshM » 26 Dec 2011

According to the blog post..
3. PosTradeCommission
Returns an absolute numerical value, indicating the commission amount spent for the specified trade.

(...)

Example
PosTradeCommission(0,1) will return a value of 5 for the second trade of the open position, if the commission for this trade is 5 dollars.
..this should be:
PosTradeCommission returns an absolute numerical value, indicating the commission and slippage spent for the specified trade.

For example:

Code: Select all

if BarsSinceExit(1) = 1 then begin

for value2 = 0 to (PosTradeCount(1) - 1) begin

Print("Commission: ", commission, Spaces(3),
"PosSize: ", PosTradeSize(1, value2), Spaces(3),
"Slippage: ", Slippage, Spaces(3),
"Commission: ", PosTradeCommission(1, value2));

end;

end;
returns:

Code: Select all

Commission: 2.20 PosSize: 3.00 Slippage: 5.00 Commission: 21.60
.. where the PosTradeCommission = (Position Size * Slippage for entry) + (Position Size * Commission per share/contract).

Regards,
Josh

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Preliminary documentation for new reserved words in MC7

Postby Henry MultiСharts » 28 Dec 2011

Hello Josh.
Thank you for your observation.
We will fix the descripton.
3. PosTradeCommission
PosTradeCommission returns an absolute numerical value, indicating the commission and slippage spent for the specified trade.
PosTradeCommission = (Position Size * Slippage per share/contract) + (Position Size * Commission per share/contract).
Example
PosTradeCommission(0,1) will return a value of 5 for the second trade of the open position, if the commission and slippage for this trade is 5 dollars.

Bentley Wilburforce
Posts: 18
Joined: 22 Feb 2014
Has thanked: 5 times
Been thanked: 2 times

Re: Preliminary documentation for new reserved words in MC7

Postby Bentley Wilburforce » 23 Apr 2014

What I mean is the ability for MC to synch perfectly with the status of all open contracts and orders at the broker's side after each time one exits then re-enters MC, without the need to program a study to do it.
Happens already for all trades that were actually filled at the broker, upon connection all existing trades are read from the broker list, and displayed on the chart.
This includes the placement of the necessary arrows on the charts at the right dates and times. For example if a study issued a stop order to IB and it's sent to the broker, and then one exists MC, then the stop order is hit and filled while MC is not running, then one starts up MC, the filled order is displayed on the appropriate chart at the correct location in terms of price and time automatically.
That is already done.
MultiCharts populates Order and Position Tracker window “Orders tab", as well as the chart, with the data from the brokers who provide order history.
Keep in mind that order history is not provided by all supported brokers, we cannot guarantee the accuracy of the information sent by the broker.
Henry,

Can you tell me if LMAX provide the order history for multicharts to synch each time one exits then re-enters multicharts?

Regards,

Ben

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Preliminary documentation for new reserved words in MC7

Postby Henry MultiСharts » 24 Apr 2014

Henry,

Can you tell me if LMAX provide the order history for multicharts to synch each time one exits then re-enters multicharts?

Regards,

Ben
Hello Ben,

MultiCharts stores each order that was sent from the platform in Order and position tracker Orders tab. It can also receive orders placed from the other application to your broker account if MultiCharts is running and the broker profile is connected (this works OK with LMAX).
If you have placed the orders through the broker or a different platform while MultiCharts was closed - next time you run MultiCharts it will not have any information regarding these orders.


Return to “MultiCharts”