Time in a trade.  [SOLVED]

Questions about MultiCharts and user contributed studies.
Jesh
Posts: 41
Joined: 04 Jan 2011
Has thanked: 12 times
Been thanked: 4 times

Time in a trade.

Postby Jesh » 18 Jul 2013

Hi,

I have been looking at creating an indicator to show me how long I have been in a trade executed manually via the DOM or Chart trader. I can find keywords for Strategy trades regarding what time a trade was executed but not for manual trades. Can anyone assist with how I can display this information on a chart? Ideally for me this information would be displayed on the DOM.

Thanks,

Jesh

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

Re: Time in a trade.

Postby TJ » 18 Jul 2013

Hi,

I have been looking at creating an indicator to show me how long I have been in a trade executed manually via the DOM or Chart trader. I can find keywords for Strategy trades regarding what time a trade was executed but not for manual trades. Can anyone assist with how I can display this information on a chart? Ideally for me this information would be displayed on the DOM.

Thanks,

Jesh
Go to Wiki

look under PowerLanguage Keyword Reference

There is a whole section on Strategy Position.

I am sure you will find the keywords you need.

Jesh
Posts: 41
Joined: 04 Jan 2011
Has thanked: 12 times
Been thanked: 4 times

Re: Time in a trade.

Postby Jesh » 18 Jul 2013

Go to Wiki

look under PowerLanguage Keyword Reference

There is a whole section on Strategy Position.

I am sure you will find the keywords you need.
Thanks TJ but as I explained in my post I know there are keywords for a Strategy position/entry but I'm not looking at applying a Strategy, I'm trying to display the time a manual/discretionary entry was made.

There are no keyword for accessing this information outside a Strategy for an indicator to access for example from what I've seen in the Wiki.

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

Re: Time in a trade.

Postby TJ » 18 Jul 2013

Thanks TJ but as I explained in my post I know there are keywords for a Strategy position/entry but I'm not looking at applying a Strategy, I'm trying to display the time a manual/discretionary entry was made.

There are no keyword for accessing this information outside a Strategy for an indicator to access for example from what I've seen in the Wiki.
Look for the keywords with the "i" prefix,
those can be used in an indicator.

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

Re: Time in a trade.

Postby TJ » 18 Jul 2013

or, submit a request if you want it as a built-in feature:

https://www.multicharts.com/pm/

SP
Posts: 465
Joined: 06 Feb 2006
Has thanked: 36 times
Been thanked: 286 times

Re: Time in a trade.

Postby SP » 19 Jul 2013

As a starting point.
Insert as strategy, turn SA on.

Code: Select all

//Strategy, SA on
[IntrabarOrderGeneration = true];
inputs: Offset (2);
vars: intrabarpersist MPatB(0), intrabarpersist prevMPatB(0), intrabarpersist myEntrytimes (0), intrabarpersist timediffs(0),
textstr( "Turn SA On"),txt(0) ;


if getappinfo(airealtimecalc) = 1 and getappinfo(aistrategyauto) = 1 then
begin

MPatB= MarketPosition_at_Broker;

if MPatB <>prevMPatB and MPatB<> 0 then
begin
myEntrytimes = TimeToSeconds(Time_s);
end;


if MPatB<> 0 then
begin
timediffs = TimeToSeconds(Time_s)- myEntrytimeS ;
textstr= (
"In " + ifftext (MPatB<0,"Short","Long")+" Position since " + NumToStr (timediffS,0 ) +" Seconds.");
//if LastBarOnChart_s then Print (textstr);
end;
if MPatB = 0 then textstr = " No Position";

prevMPatB = MPatB;
end;

if Barnumber = 1 then
begin
txt = text_new_s (date,time_s,close ,"");
text_SetStyle (txt,1,0);
text_SetColor (txt,white);
end else
begin
text_SetString(txt,textstr);
text_SetColor (txt,iff (MPatB=0,white, iff (MPatB<0,red,green)));
text_SetLocation_s(txt,date,time_s, getappinfo(aihighestDispValue)-Offset );
end;

User avatar
arnie
Posts: 1594
Joined: 11 Feb 2009
Location: Portugal
Has thanked: 481 times
Been thanked: 514 times

Re: Time in a trade.

Postby arnie » 19 Jul 2013

As a starting point.
Insert as strategy, turn SA on.
How cool is this.
I had no idea that this was already available on MC.

I remember having requested something similar to this many months ago and at the time there was no such keywords.

Many thanks SP.
This weekend I'll have my hands on this to tweak it the way I want it.

Sometimes we just need a workable example so we can be able to work from there.

Again, many thanks SP.

Jesh
Posts: 41
Joined: 04 Jan 2011
Has thanked: 12 times
Been thanked: 4 times

Re: Time in a trade.

Postby Jesh » 22 Jul 2013

Thanks TJ and SP. I'll take a look at the code and try and get it working with the information you supplied.

User avatar
arnie
Posts: 1594
Joined: 11 Feb 2009
Location: Portugal
Has thanked: 481 times
Been thanked: 514 times

Re: Time in a trade.  [SOLVED]

Postby arnie » 23 Jul 2013

Finally I had the time to finish this....

Many thanks for your code SP.

Image

Code: Select all

[IntrabarOrderGeneration = true];

//Strategy, SA on

inputs:
ShiftBox (0),
TimeOffSet (5),
LabelSize (10),
LabelColor (lightgray),
LongColor (green),
ShortColor (red),
LabelFont ("Arial Bold");

vars:
intrabarpersist MPatB (0),
intrabarpersist prevMPatB (0),
intrabarpersist myEntrytimes (0),
intrabarpersist timeDiff (0),
txtStr ("Turn SA On"),
txtTime (-1),
txtContracts (-1),
txtPosition (-1),
myTime (0),
myTime2 (0),
myMinutes (0),
offSetTime (ELTimeToDateTime(TimeOffSet)),
dTick (MinMove/PriceScale),
boxShift (0);


boxShift = ShiftBox * dTick;

if getappinfo(airealtimecalc) = 1 and getappinfo(aistrategyauto) = 1 then begin

MPatB = MarketPosition_at_Broker;

if MPatB <> prevMPatB and MPatB <> 0 then begin
myEntrytimes = TimeToSeconds(Time_s);
end;


if MPatB <> 0 then begin
timeDiff = TimeToSeconds(Time_s) - myEntrytimeS ;
myTime = SecondsToTime_s(timeDiff);

myTime2 = myTime/100;
MyMinutes = IntPortion(myTime2);

if MyMinutes >= 60 then begin
txtStr = ("" + ifftext (MPatB < 0, " Short position", " Long position") + newline + text(MPatB) + " contract (s) " + newline +
newline + FormatTime(" hh:mm", el_timetodatetime_s(mytime)) + "h" + " in trade");
end
else
if MyMinutes >= 1 and MyMinutes < 60 then begin
txtStr = ("" + ifftext (MPatB < 0, " Short position", " Long position") + newline + text(MPatB) + " contract (s)" + newline +
newline + FormatTime(" mm", el_timetodatetime_s(mytime)) + "m" + " in trade");
end
else
if MyMinutes < 1 then begin
txtStr = ("" + ifftext (MPatB < 0, " Short position", " Long position") + newline + text(MPatB) + " contract (s)" + newline +
newline + FormatTime(" ss", el_timetodatetime_s(mytime)) + "s" + " in trade");
end;

end; //if LastBarOnChart_s then Print all text variables;

if MPatB = 0 then begin
txtStr = " NO POSITION ";
end;

prevMPatB = MPatB;
end;

if Barnumber = 1 then begin

txtTime = text_new_self_s(JulianToDate(aiRightDispDateTime), GetAppInfo(aiRightDispDateTime), GetAppInfo(aiHighestDispValue) - BoxShift,"");
text_setfontname(txtTime, LabelFont);
text_setcolor(txtTime, LabelColor);
text_setsize(txtTime, LabelSize);
Text_SetStyle(txtTime, 0, 0);
//text_setborder(txtTime , true);
//text_setbgcolor(txtTime , black);
text_lock(txtTime, true);

end
else begin
text_SetString(txtTime, txtStr);
text_SetColor (txtTime, iff(MPatB = 0, LabelColor, iff(MPatB < 0,ShortColor ,LongColor)));

if BarStatus(1) = 2 then begin
Text_SetLocation_s(txtTime, JulianToDate(GetAppInfo(aiRightDispDateTime)),DateTime2ELTime_s(GetAppInfo(aiRightDispDateTime) -
offSetTime), GetAppInfo(aiHighestDispValue) - boxShift);
end;


end;
Attachments
trade_timer.png
(37.01 KiB) Downloaded 1638 times

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

Re: Time in a trade.

Postby TJ » 23 Jul 2013

Finally I had the time to finish this....
Many thanks for your code SP.
You need to post the text_lock function.

User avatar
arnie
Posts: 1594
Joined: 11 Feb 2009
Location: Portugal
Has thanked: 481 times
Been thanked: 514 times

Re: Time in a trade.

Postby arnie » 23 Jul 2013

Finally I had the time to finish this....
Many thanks for your code SP.
You need to post the text_lock function.
That function is already on MC.
Which MC version are you using TJ?

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

Re: Time in a trade.

Postby TJ » 23 Jul 2013

Finally I had the time to finish this....
Many thanks for your code SP.
You need to post the text_lock function.
That function is already on MC.
Which MC version are you using TJ?
I am using version 8

User avatar
arnie
Posts: 1594
Joined: 11 Feb 2009
Location: Portugal
Has thanked: 481 times
Been thanked: 514 times

Re: Time in a trade.

Postby arnie » 23 Jul 2013

Just comment that line if using a version without this keyword.

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

Re: Time in a trade.

Postby TJ » 23 Jul 2013

Just comment that line if using a version without this keyword.
ok, thanks.

waveslider
Posts: 222
Joined: 16 Oct 2011
Has thanked: 66 times
Been thanked: 20 times

Re: Time in a trade.

Postby waveslider » 07 Oct 2016

Hello -

I can see that some snippets of this code are close to what I am looking to do, but not quite.

I would like to have an indicator produce text that locks into the upper or lower right corner of a chart and does not move.

Any suggestions?
Thanks in advance

waveslider
Posts: 222
Joined: 16 Oct 2011
Has thanked: 66 times
Been thanked: 20 times

Re: Time in a trade.

Postby waveslider » 07 Oct 2016



Return to “MultiCharts”