print messages on chart when market position change  [SOLVED]

Questions about MultiCharts and user contributed studies.
ameoba
Posts: 3
Joined: 08 Feb 2014
Has thanked: 2 times

print messages on chart when market position change

Postby ameoba » 08 Feb 2014

Does any one know which command to use if I want to print message on chart when market position have been changed? for example, from a long position to flat.

thanks for helping.

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

Re: print messages on chart when market position change

Postby JoshM » 08 Feb 2014

MATricks posted a code snippet for that earlier this week here, though you will need to change 'Alert' to 'Print' then.

ameoba
Posts: 3
Joined: 08 Feb 2014
Has thanked: 2 times

Re: print messages on chart when market position change

Postby ameoba » 08 Feb 2014

thanks JoshM, but don't know why it have the message printed twice and triggered when there is no trade. Here is my code and the result attached.

variables: IntrabarPersist MP(0), IntrabarPersist LastMP(0);

if date = 1140129 and time = 1309 then begin
buy ("trade1-buy") next bar on open;
end;

if date = 1140129 and time = 1403 then begin
sell ("trade1-sell") next bar on open;
end;

if date = 1140129 and time = 1042 then begin
buy ("trade2-buy") next bar on open;
end;

if date = 1140129 and time = 1047 then begin
sell ("trade2-sell") next bar on open;
end;


MP = I_MarketPosition;
if MP <> LastMP then begin
Value1 = Text_New(Date, ExitTime(1), High, "New Date");
end;
LastMP = MP;

Capture.PNG
(15.53 KiB) Downloaded 433 times

ameoba
Posts: 3
Joined: 08 Feb 2014
Has thanked: 2 times

Re: print messages on chart when market position change  [SOLVED]

Postby ameoba » 08 Feb 2014

Thanks, I have got it fixed. Here is the code:
plot exit time on the chart when a long position was flatten

variables: IntrabarPersist MP(0), IntrabarPersist LastMP(0);

MP = I_MarketPosition;
if MP < LastMP then begin
Value1 = Text_New(Date, ExitTime(1), High, NumToStr(ExitTime(1),0));
end;
LastMP = MP;

User avatar
MAtricks
Posts: 789
Joined: 09 Apr 2012
Has thanked: 286 times
Been thanked: 288 times

Re: print messages on chart when market position change

Postby MAtricks » 09 Feb 2014

Almost. Your Long Exit code allows for a print on short orders as well as exiting long orders. Try:

Code: Select all

if LastMP>0 and MP<=0 then
If you want the option of all:

Code: Select all

Inputs:
LE( 0 ), //0 = do not use. 1 = use
LX( 1 ), //0 = do not use. 1 = use
SE( 0 ), //0 = do not use. 1 = use
SX( 0 ) ; //0 = do not use. 1 = use

variables:
IntrabarPersist MPos(0),
IntrabarPersist LastMPos(0);

MPos = I_MarketPosition ;

if LE>0 and LastMPos<=0 and MPos>0 then
//Long Entry code
if LX>0 and LastMPos>0 and MPos<=0 then
//Long Exit code
if SE>0 and LastMPos>=0 and MPos<0 then
//Short Entry code
if SX>0 and LastMPos<0 and MPos>=0 then
//Short Exit code

LastMPos = MPos;
I use MPos because MP is now a function.. I like using the variable :)


Return to “MultiCharts”