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.
print messages on chart when market position change [SOLVED]
- 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
MATricks posted a code snippet for that earlier this week here, though you will need to change 'Alert' to 'Print' then.
Re: print messages on chart when market position change
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;
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;
Re: print messages on chart when market position change [SOLVED]
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;
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;
Re: print messages on chart when market position change
Almost. Your Long Exit code allows for a print on short orders as well as exiting long orders. Try:
If you want the option of all:
I use MPos because MP is now a function.. I like using the variable
Code: Select all
if LastMP>0 and MP<=0 then
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;