PosTradeCount(PosBack) | Suggestion for more notes/details

Questions about MultiCharts and user contributed studies.
Posts: 2
Joined: 24 Jul 2018
Has thanked: 1 time

PosTradeCount(PosBack) | Suggestion for more notes/details

Postby JensOhle » 25 Jul 2018

Suggestion: Give more details/information about the functioning of the PosTradeCount(PosBack) keyword.

More specifically, the description "if there is a single entry and multiple scalping exits, ..." in the "Notes" section is kind of misleading. I thought in the beginning that the count would decrease in case after a specific entry (say strategy/signal A, or the "single entry") was closed by its specific exit. However, this is not true in case another entry (e.g. from strategy/signal B), that occured before or after entry A, and is still not closed.

In other words: "PosTradeCount(PosBack) with PosBack = 0 or open position" does not give you the actual/current number of open entries in a position, but the max number of entries (open or closed) in a position. Or, if you like,the historical number of entries in the open position.

I actually missed an information like the following: "Every already closed entry (of a position) that was opened while an earlier or later entry is still open, keeps being registered in PosTradeCount(0) - i.e. as an open entry - as long as one of these other entries is still open.

Or give just a more complex example for PosTradeCount(0) ...

More details on actually all Strategy Position Trades, in some way would be very, very helpful and time saving ... Thanks for your consideration.

Posts: 2
Joined: 24 Jul 2018
Has thanked: 1 time

Re: PosTradeCount(PosBack) | Suggestion for more notes/details

Postby JensOhle » 25 Jul 2018

In addition I wanted to share a function that needed that kind of information, so may be other developpers have it a bit easier ...
If the pros find some flaws, please comment ... Thx. JO.


Code: Select all

// PosTradeOpen:TrueFalse;
// Returns true if the entry/trade with the entry name string as input is still open, otherwise false.

Inputs: TradeEntryName(StringSimple);
Variables: n(0);

PosTradeOpen = false;

// Run through all trades of the entries registered with the current open position (subsequent or earlier entries, still open or already closed)
For n = 0 to (PosTradeCount(0)-1)
// Check if the EntryName of the entry/trade is registered AND if the entry/trade is still open
if not PosTradeOpen
and PosTradeEntryName(0, n) = TradeEntryName
and PosTradeIsOpen(0, n)
then PosTradeOpen = true;

User avatar
Anna MultiCharts
Posts: 461
Joined: 14 Jul 2017
Has thanked: 31 times
Been thanked: 113 times

Re: PosTradeCount(PosBack) | Suggestion for more notes/details

Postby Anna MultiCharts » 26 Jul 2018

Hello, JensOhle!

Yes, you’re right about the description of PosTradeCount(PosBack) in Help: it doesn’t properly reflect what the function does. We’ll rework the description.
PosTradeCount(PosBack) returns the total number of entries within a position while it is open. If you initially entered a position with 10 entries, then 1 of them was closed, but then you entered the position again with 1 more entry the function will return the number of 11 – so it counts all trades both open and closed for this position. Once the position is completely closed the function will return 0.
To check the state of a particular trade you can use PosTradeIsOpen and PosTradeIsClosed keywords.
If you’d like our engineers to review your code please email us to

Return to “MultiCharts”