how to code in powerlanguage to get previous market position

Questions about MultiCharts and user contributed studies.
petercruz
Posts: 6
Joined: 01 May 2013
Has thanked: 1 time

how to code in powerlanguage to get previous market position

Postby petercruz » 30 Jan 2015

any help is deeply appreciated

if marketposition[1] =0 and C>highest(H,3) then buy next bar at market...

accurately code my idea that

if previous market position is zero then buy when current close exceed the high of last 3 trading bars?
i only want the signal to be "fired" if previous market position is zero. Is my code marketposition[1]
correct?
tks

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

Re: how to code in powerlanguage to get previous market posi

Postby TJ » 30 Jan 2015

any help is deeply appreciated

if marketposition[1] =0 and C>highest(H,3) then buy next bar at market...

accurately code my idea that

if previous market position is zero then buy when current close exceed the high of last 3 trading bars?
i only want the signal to be "fired" if previous market position is zero. Is my code marketposition[1]
correct?
tks
Your code will never fire because C can never be higher than highest(H,3)... because it contains the current bar high.

You will need to compare the previous bars.

Code: Select all


C > highest(H,3)[1]

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

Re: how to code in powerlanguage to get previous market posi

Postby JoshM » 31 Jan 2015

any help is deeply appreciated

if marketposition[1] =0 and C>highest(H,3) then buy next bar at market...

accurately code my idea that

if previous market position is zero then buy when current close exceed the high of last 3 trading bars?
i only want the signal to be "fired" if previous market position is zero. Is my code marketposition[1]
correct?
Your code will never fire because C can never be higher than highest(H,3)... because it contains the current bar high.
What TJ says, plus `MarketPosition` cannot be referenced for previous bars like `Close` and `High` can.

But you can assign `MarketPosition` to a variable and then access the previous values for this values (meaning, the value the variable had on the close of the preceding bars).

If you understood you correctly, you'd get something like this:

Code: Select all

Variables:
highestHigh(0),
MP(0);

if (BarStatus(1) = 2) then begin

MP = MarketPosition;

highestHigh = Highest(High, 3)[1];

if (Close > highestHigh) and (MP[1] = 0) then
Buy next bar at market;
end;


Return to “MultiCharts”