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
Time in a trade. [SOLVED]
- TJ
- Posts: 7745
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2224 times
Re: Time in a trade.
Go to WikiHi,
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
look under PowerLanguage Keyword Reference
There is a whole section on Strategy Position.
I am sure you will find the keywords you need.
Re: Time in a trade.
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.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.
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.
- TJ
- Posts: 7745
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2224 times
Re: Time in a trade.
Look for the keywords with the "i" prefix,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.
those can be used in an indicator.
- TJ
- Posts: 7745
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2224 times
Re: Time in a trade.
As a starting point.
Insert as strategy, turn SA on.
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;
- arnie
- Posts: 1594
- Joined: 11 Feb 2009
- Location: Portugal
- Has thanked: 481 times
- Been thanked: 514 times
Re: Time in a trade.
How cool is this.As a starting point.
Insert as strategy, turn SA on.
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.
- arnie
- Posts: 1594
- Joined: 11 Feb 2009
- Location: Portugal
- Has thanked: 481 times
- Been thanked: 514 times
Re: Time in a trade. [SOLVED]
Finally I had the time to finish this....
Many thanks for your code SP.
Many thanks for your code SP.
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
- TJ
- Posts: 7745
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2224 times
Re: Time in a trade.
You need to post the text_lock function.Finally I had the time to finish this....
Many thanks for your code SP.
- arnie
- Posts: 1594
- Joined: 11 Feb 2009
- Location: Portugal
- Has thanked: 481 times
- Been thanked: 514 times
Re: Time in a trade.
That function is already on MC.You need to post the text_lock function.Finally I had the time to finish this....
Many thanks for your code SP.
Which MC version are you using TJ?
- TJ
- Posts: 7745
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2224 times
Re: Time in a trade.
I am using version 8That function is already on MC.You need to post the text_lock function.Finally I had the time to finish this....
Many thanks for your code SP.
Which MC version are you using TJ?
- TJ
- Posts: 7745
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2224 times
-
- Posts: 224
- Joined: 16 Oct 2011
- Has thanked: 66 times
- Been thanked: 20 times
Re: Time in a trade.
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
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
-
- Posts: 224
- Joined: 16 Oct 2011
- Has thanked: 66 times
- Been thanked: 20 times