print current market position first time indicator is

Questions about MultiCharts and user contributed studies.
maisatomai
Posts: 83
Joined: 18 Mar 2013
Has thanked: 11 times

print current market position first time indicator is

Postby maisatomai » 27 Oct 2014

print current market position first time indicator is applied? I was wondering how can I do this cleanly.

I can code

Code: Select all

if (barnumber=1) then
print(MarketPosition);
but this will print the MarketPosition of bar number 1. I need the current market position.

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

Re: print current market position first time indicator is

Postby JoshM » 28 Oct 2014

print current market position first time indicator is applied? I was wondering how can I do this cleanly.

I can code

Code: Select all

if (barnumber=1) then
print(MarketPosition);
but this will print the MarketPosition of bar number 1. I need the current market position.
You mean like this?

Code: Select all

Variables:
printOnce(false);

if (LastBarOnChart_s = true) and (printOnce = false) then begin

Print("The current market position is: ", i_MarketPosition);

printOnce = true;

end;
Here we use `LastBarOnChart_s` so that the code is executed on the last bar (to get the current market position) so that we don't need to use `BarNumber`.

The `printOnce` variable is used to only execute the `Print()` statement once. After it has been printed, the variable is switched to `true` so that it's not printed again. This gets the current market position the first time the indicator is applied.


Return to “MultiCharts”