Writing in the corner of the chart

Questions about MultiCharts and user contributed studies.
rondot samuel ws
Posts: 103
Joined: 05 Sep 2007
Has thanked: 8 times
Been thanked: 6 times

Writing in the corner of the chart

Postby rondot samuel ws » 14 Mar 2011

Hi,

I would like to write in the corner of the chart (if possible right, upper).

For the moment I can write but sometime my writting is on the candle, not good for reading chart.

I didn't find how to write in a corner, any idea ?

regards

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

Re: Writing in the corner of the chart

Postby TJ » 14 Mar 2011

Hi,

I would like to write in the corner of the chart (if possible right, upper).

For the moment I can write but sometime my writting is on the candle, not good for reading chart.

I didn't find how to write in a corner, any idea ?

regards
can you post your screen shot and your code, with notes on what you want to do?

janus
Posts: 835
Joined: 25 May 2009
Has thanked: 63 times
Been thanked: 104 times

Re: Writing in the corner of the chart

Postby janus » 14 Mar 2011

Hi,
I would like to write in the corner of the chart (if possible right, upper).
regards
You can use the following code to write on the top left. You can make it work to write at the top right but requires adjustment of the time position dependent on the length of the message to be displayed, assuming it's at all possible given the font style, size and scaling of the chart window. Also, the update on every tick may not work 100% of the time so you may see duplicate text. This is why we need a better feature in PL to print text in the chart window, which optionally stays fixed relative to the window and not to the plot so scrolling will not move the text; similar to the status lines that are already there.

Code: Select all

variables:
n1(0), n2(0), intrabarpersist id(0), intrabarpersist del.id(False);

if LastBarOnChart_s then begin
n1 = getappinfo(aiLeftDispDateTime);
n2 = (getappinfo(aiHighestDispValue) - getappinfo(aiLowestDispValue))*0.99 + getappinfo(aiLowestDispValue);
if del.id then text_delete(id);
del.id = False;
if barstatus = 2 and id > 0 then del.id = True; // delete label next tick
id = text_new_s(JulianToDate(n1), StrToNum(FormatTime("HHmmss",n1)), n2, "Message");
Text_SetSize(id, 12);
Text_SetStyle(id, 0, 2);
Text_SetColor(id, red);
Text_SetAttribute(id, 1, true);
end;

rondot samuel ws
Posts: 103
Joined: 05 Sep 2007
Has thanked: 8 times
Been thanked: 6 times

Re: Writing in the corner of the chart

Postby rondot samuel ws » 15 Mar 2011

thanks a lot. i'll try it asap. should be ok for me
Hi,
I would like to write in the corner of the chart (if possible right, upper).
regards
You can use the following code to write on the top left. You can make it work to write at the top right but requires adjustment of the time position dependent on the length of the message to be displayed, assuming it's at all possible given the font style, size and scaling of the chart window. Also, the update on every tick may not work 100% of the time so you may see duplicate text. This is why we need a better feature in PL to print text in the chart window, which optionally stays fixed relative to the window and not to the plot so scrolling will not move the text; similar to the status lines that are already there.

Code: Select all

variables:
n1(0), n2(0), intrabarpersist id(0), intrabarpersist del.id(False);

if LastBarOnChart_s then begin
n1 = getappinfo(aiLeftDispDateTime);
n2 = (getappinfo(aiHighestDispValue) - getappinfo(aiLowestDispValue))*0.99 + getappinfo(aiLowestDispValue);
if del.id then text_delete(id);
del.id = False;
if barstatus = 2 and id > 0 then del.id = True; // delete label next tick
id = text_new_s(JulianToDate(n1), StrToNum(FormatTime("HHmmss",n1)), n2, "Message");
Text_SetSize(id, 12);
Text_SetStyle(id, 0, 2);
Text_SetColor(id, red);
Text_SetAttribute(id, 1, true);
end;

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

Re: Writing in the corner of the chart

Postby TJ » 18 Mar 2011


Chris_THOMAS
Posts: 5
Joined: 17 Oct 2010
Has thanked: 1 time
Been thanked: 1 time

Re: Writing in the corner of the chart

Postby Chris_THOMAS » 10 Apr 2011

Hello Samuel

You can try this :
input : Price(Close),
TextPricePercent(95),
StepBy(10),
DrawText(True),
TextSize(12),
PriceColor(DarkGreen),Xavg1Color(Yellow),Xavg2Color(Cyan),
rien(0);

var : // Mesure l'ecran
RightDateTime(0),HighestDispValue(0),LowestDispValue(0),

TxtID_Price(0),TxtDV_Price(0),

Xavg1(0),TxtID_Xavg1(0),TxtDV_Xavg1(0), Len1(0),

Xavg2(0),TxtID_Xavg2(0),TxtDV_Xavg2(0),Len2(0)

;

// Calcul des Xavg's

Len1 = 20 ;
Len2 = 50 ;
Xavg1 = Xaverage(Price,Len1);
Xavg2 = Xaverage(Price,Len2);

Plot1(Xavg1,"Xavg1",Xavg1Color,default,0);
Plot2(Xavg2,"Xavg2",Xavg2Color,default,0);

// Initialisation des Textes
if CurrentBar = 1 and DrawText then begin

Once begin

// Init Price
TxtID_Price = Text_New(Date, Time, Close, " ");
Text_SetStyle(TxtID_Price, 1, 1);
Text_SetColor(TxtID_Price,PriceColor);
Text_SetSize(TxtID_Price,TextSize);

// Init Xavg1
TxtID_Xavg1 = Text_New(Date, Time, Close, " ");
Text_SetStyle(TxtID_Xavg1, 1, 1);
Text_SetColor(TxtID_Xavg1,Xavg1Color);
Text_SetSize(TxtID_Xavg1,TextSize);

// Init Xavg2
TxtID_Xavg2 = Text_New(Date, Time, Close, " ");
Text_SetStyle(TxtID_Xavg2, 1, 1);
Text_SetColor(TxtID_Xavg2,Xavg2Color);
Text_SetSize(TxtID_Xavg2,TextSize);

end;

end;


// Draw Textes
if LastBarOnChart and DrawText then begin

// Calcul de la hauteur et de la droite de l'ecran
RightDateTime = GetAppInfo( aiRightDispDateTime ) ;
HighestDispValue = GetAppInfo( aiHighestDispValue ) ;
LowestDispValue = GetAppInfo( aiLowestDispValue ) ;


// Affiche la valeur de Price
TxtDV_Price = LowestDispValue + 0.01 * (TextPricePercent - (0 * StepBy)) * ( HighestDispValue - LowestDispValue ) ;
Text_SetString( TxtID_Price, "Price = " + NumToStr( Price, StrLen(NumToStr(PriceScale, 0)) - 1 ) );
Text_SetLocation( TxtID_Price, JulianToDate( IntPortion( RightDateTime ) ), MinutesToTime( FracPortion( RightDateTime ) * 60 * 24 ), TxtDV_Price ) ;

// Affiche la valeur de Xavg1
TxtDV_Xavg1 = LowestDispValue + 0.01 * (TextPricePercent - (1 * StepBy)) * ( HighestDispValue - LowestDispValue ) ;
Text_SetString( TxtID_Xavg1, "Xavg1 = " + NumToStr( Xavg1, StrLen(NumToStr(PriceScale, 0)) - 1 ) );
Text_SetLocation( TxtID_Xavg1, JulianToDate( IntPortion( RightDateTime ) ), MinutesToTime( FracPortion( RightDateTime ) * 60 * 24 ), TxtDV_Xavg1 ) ;

// Affiche la valeur de Xavg2
TxtDV_Xavg2 = LowestDispValue + 0.01 * (TextPricePercent - (2 * StepBy)) * ( HighestDispValue - LowestDispValue ) ;
Text_SetString( TxtID_Xavg2, "Xavg2 = " + NumToStr( Xavg2, StrLen(NumToStr(PriceScale, 0)) - 1 ) );
Text_SetLocation( TxtID_Xavg2, JulianToDate( IntPortion( RightDateTime ) ), MinutesToTime( FracPortion( RightDateTime ) * 60 * 24 ), TxtDV_Xavg2 ) ;

end;
Best regards

Chris

rondot samuel ws
Posts: 103
Joined: 05 Sep 2007
Has thanked: 8 times
Been thanked: 6 times

Re: Writing in the corner of the chart

Postby rondot samuel ws » 19 Apr 2011

Hi,

thanks all for your reply.

I need a function, not an Indicator.
2 reasons : I need to write information only available in study , and I want to add the writing easyly (just add 1 line in all study, not to have to add an indicator for each workspace)

And I need a good refresh

So finally this is the code for the function writing current entry date time price and marketposition * volume:

Code: Select all

[IntrabarOrderGeneration = true]
Var: ID_Text1(0);

if marketposition =-1 then begin
text_setbgcolor(id_text1,red);
text_setcolor(id_text1,black);
end;
if marketposition =1 then begin
text_setbgcolor(id_text1,green);
text_setcolor(id_text1,black);
end;
if marketposition=0 then begin
text_setbgcolor(id_text1,white);
text_setcolor(id_text1,black);
end;
if ID_Text1=0 then begin
ID_Text1=text_new(d,t,getappinfo(aiHighestDispValue),NumToStr(EntryDate(0),0)+ " " + NumToStr(Entrytime(0),0) + " >" + NumToStr(entryprice(0),4) + NumToStr( marketposition*currentcontracts,0) + newline);
Text_SetStyle(ID_Text1, 1, 1);
end
else begin
text_setstring(ID_Text1,NumToStr(EntryDate(0),0)+ " " + NumToStr(Entrytime(0),0) + " " + NumToStr(entryprice(0),4)+ " >"+ NumToStr( marketposition*currentcontracts,0) + newline);
text_setlocation(ID_Text1,d,t,getappinfo(aiHighestDispValue));
end;

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

Re: Writing in the corner of the chart

Postby arnie » 19 Apr 2011

If MC had the screen divided in coordinates it would be much easier for us to select a specific place (coordinate) where to plot the text, instead of the aiHighestDispValue reserved word that never worked properly.

Lets imagine the screen divided in 8 or 16 squares, each with a coordinate, easily accessed through EL reserved words.
We then choose the one we want, write the code and all text would be plotted inside that selected square.

User avatar
Stan Bokov
Posts: 963
Joined: 18 Dec 2009
Has thanked: 367 times
Been thanked: 302 times

Re: Writing in the corner of the chart

Postby Stan Bokov » 19 Apr 2011

If MC had the screen divided in coordinates it would be much easier for us to select a specific place (coordinate) where to plot the text, instead of the aiHighestDispValue reserved word that never worked properly.

Lets imagine the screen divided in 8 or 16 squares, each with a coordinate, easily accessed through EL reserved words.
We then choose the one we want, write the code and all text would be plotted inside that selected square.
Good suggestion - "feature request" it.

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

Re: Writing in the corner of the chart

Postby TJ » 19 Apr 2011

If MC had the screen divided in coordinates it would be much easier for us to select a specific place (coordinate) where to plot the text, instead of the aiHighestDispValue reserved word that never worked properly.
...
Can you describe your problem with "aiHighestDispValue"?
Are you suggesting a "bug"?

I have many text information drawn all over my charts; I can locate a text (or an arrow, or a trendline) anywhere on the screen with precision. I would be happy to help if you can describe your needs.

Chris_THOMAS
Posts: 5
Joined: 17 Oct 2010
Has thanked: 1 time
Been thanked: 1 time

Re: Writing in the corner of the chart

Postby Chris_THOMAS » 19 Apr 2011

Hello Samuel,

Here is the function :

Code: Select all

{***********************************************************
In First, this function works in strategies
Put this function in strategy with MP = MarketPosition
***********************************************************}

input : MP(Numeric),
TextSize(NumericSimple),
ShowText(TrueFalse);

Var : TxtPosition(0), ValPosition(""),
TxtEntryDate(0),
TxtEntryTime(0),
TxtEntryPrice(0),
TxtNbContract(0),

HiDispVal(0),
LoDispVal(0),
RightDispVal(0),RightDate(0),RightTime(0),
WhereAtRight(0),

ColorTxt(0),
BgColorTxt(0),

Decimal(0),
Encore(0);

Decimal = StrLen(NumToStr(PriceScale,0)) - 1 ;

if CurrentBar = 1 then begin

// Init at the first bar
TxtPosition = Text_New(Date, Time, Close, "000");
TxtEntryDate = Text_New(Date, Time, Close, "000");
TxtEntryTime = Text_New(Date, Time, Close, "000");
TxtEntryPrice = Text_New(Date, Time, Close, "000");
TxtNbContract = Text_New(Date, Time, Close, "000");

end;

if LastBarOnChart and ShowText then begin

// Flat Colors
if MP = 0 then begin
ColorTxt = DarkGray ;
BgColorTxt = White ;
ValPosition = "Flat" ;
end;

// Long Colors
if MP > 0 then begin
ColorTxt = Green ;
BgColorTxt = White ;
ValPosition = "Long" ;
end;

// Short Colors
if MP < 0 then begin
ColorTxt = Red ;
BgColorTxt = White ;
ValPosition = "Short" ;
end;

// Display Screen Values
HiDispVal = GetAppInfo( aiHighestDispValue ) ;
LoDispVal = GetAppInfo( aiLowestDispValue ) ;
RightDispVal = GetAppInfo( aiRightDispDateTime ) ;
RightDate = JulianToDate( IntPortion( RightDispVal ) ) ;
RightTime = MinutesToTime( FracPortion( RightDispVal ) * 60 * 24 - 5*BarInterval ); // - Marge
WhereAtRight = ( HiDispVal - LoDispVal ) ;
// 1,41500 ? (1,43600 - 1,41500 ) => 1,41500 + 0.1 * ( 0,021 ) =

// Display Text at the right of the chart
// TxtPosition
Text_SetString(TxtPosition, "Position = " + ValPosition);
Text_SetLocation(TxtPosition, RightDate, RightTime, HiDispVal - 0.1 * WhereAtRight);
Text_SetStyle(TxtPosition, 1, 2);
Text_SetColor(TxtPosition, ColorTxt);
Text_SetSize(TxtPosition, TextSize);

if MP <> 0 then begin

// TxtEntryDate
Text_SetString(TxtEntryDate, "EntryDate = " + DateToString(DateToJulian(EntryDate)));
Text_SetLocation(TxtEntryDate, RightDate, RightTime, HiDispVal - 0.15 * WhereAtRight);
Text_SetStyle(TxtEntryDate, 1, 2);
Text_SetColor(TxtEntryDate, ColorTxt);
Text_SetSize(TxtEntryDate, TextSize);

//TxtEntryTime
Text_SetString(TxtEntryTime, "EntryTime = " + NumToStr(EntryTime, 0));
Text_SetLocation(TxtEntryTime, RightDate, RightTime, HiDispVal - 0.2 * WhereAtRight);
Text_SetStyle(TxtEntryTime, 1, 2);
Text_SetColor(TxtEntryTime, ColorTxt);
Text_SetSize(TxtEntryTime, TextSize);

//TxtEntryPrice
Text_SetString(TxtEntryPrice, "EntryPrice = " + NumToStr(EntryPrice, Decimal));
Text_SetLocation(TxtEntryPrice, RightDate, RightTime, HiDispVal - 0.25 * WhereAtRight);
Text_SetStyle(TxtEntryPrice, 1, 2);
Text_SetColor(TxtEntryPrice, ColorTxt);
Text_SetSize(TxtEntryPrice, TextSize);

// TxtNbContract
Text_SetString(TxtNbContract, "NbContract = " + NumToStr(CurrentContracts, 0) );
Text_SetLocation(TxtNbContract, RightDate, RightTime, HiDispVal - 0.3 * WhereAtRight);
Text_SetStyle(TxtNbContract, 1, 2);
Text_SetColor(TxtNbContract, ColorTxt);
Text_SetSize(TxtNbContract, TextSize);

end;


end;

CT_WriteText = 0 ;

Try this and let me know if you want more things.

Cordialy

Chris

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

Re: Writing in the corner of the chart

Postby arnie » 19 Apr 2011

Good suggestion - "feature request" it.
Done
Are you suggesting a "bug"?

I have many text information drawn all over my charts; I can locate a text (or an arrow, or a trendline) anywhere on the screen with precision. I would be happy to help if you can describe your needs.
No bug.
As I recall, when I tried to plot the text on the top right of the screen using the aiHighestDispValue reserved word, every time I zoomed in the chart the text would disappear form the screen.
Basically, I couldn't zoom the chart in any way if I wanted to maintain the text visible on the screen. This never made sense to me.

I remember that when I tested WealthLab software many years ago, I was able to plot text in any place on a chart since they had specific reserved words for specific sections of a chart screen.

I eventually gave up trying to find a way to work with it and plot the text above the price bar.
Eventually, I abandoned that study since it proved not to be useful for my type of trading, but I have other indicators that I'd like to add text to them, but because of that inability to plot them where I want, I continue to plot the text above and below the bar, which limits the text plotted due to the lack of "space" surrounding the bar.

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

Re: Writing in the corner of the chart

Postby TJ » 19 Apr 2011

Are you suggesting a "bug"?

I have many text information drawn all over my charts; I can locate a text (or an arrow, or a trendline) anywhere on the screen with precision. I would be happy to help if you can describe your needs.
No bug.
As I recall, when I tried to plot the text on the top right of the screen using the aiHighestDispValue reserved word, every time I zoomed in the chart the text would disappear form the screen.
Basically, I couldn't zoom the chart in any way if I wanted to maintain the text visible on the screen. This never made sense to me.

I remember that when I tested WealthLab software many years ago, I was able to plot text in any place on a chart since they had specific reserved words for specific sections of a chart screen.

I eventually gave up trying to find a way to work with it and plot the text above the price bar.
Eventually, I abandoned that study since it proved not to be useful for my type of trading, but I have other indicators that I'd like to add text to them, but because of that inability to plot them where I want, I continue to plot the text above and below the bar, which limits the text plotted due to the lack of "space" surrounding the bar.
There are "limitations" intrinsic to an event-driven program like MultiChart (and most of the charting program on the market):
MC re-draws an object at every tick. If there is no tick, there is no re-draw.
For most situations (ie during the trading hours), there is no problem with such an arrangement.

The problem arises when you want to see the chart off-line (eg. during the weekend), if there is no new ticks coming in, the drawing object that requires aiHighestDispValue might not be positioned at the places you expected.

However if you do zooming during market hours (ie there are new ticks coming in), and used the keyword TEXT_SETLOCATION, the aiHighestDispValue keyword should work as advertised.

You can try the codes in post #5, you should be able to see the text reposition itself even when zoomed.

Chris_THOMAS
Posts: 5
Joined: 17 Oct 2010
Has thanked: 1 time
Been thanked: 1 time

Re: Writing in the corner of the chart

Postby Chris_THOMAS » 19 Apr 2011

Hello Arnie,

Do you want any help to auto-write text ?

Have a good day

Chris

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

Re: Writing in the corner of the chart

Postby arnie » 19 Apr 2011

There are "limitations" intrinsic to an event-driven program like MultiChart (and most of the charting program on the market):
MC re-draws an object at every tick. If there is no tick, there is no re-draw.
For most situations (ie during the trading hours), there is no problem with such an arrangement.

The problem arises when you want to see the chart off-line (eg. during the weekend), if there is no new ticks coming in, the drawing object that requires aiHighestDispValue might not be positioned at the places you expected.

However if you do zooming during market hours (ie there are new ticks coming in), and used the keyword TEXT_SETLOCATION, the aiHighestDispValue keyword should work as advertised.

You can try the codes in post #5, you should be able to see the text reposition itself even when zoomed.

Very important information TJ.
Thanks.

Since I dedicate my time for EL learning during the weekend, it's most likely that I've used the aiHighestDispValue keyword during markets close hours.

:oops:
Do you want any help to auto-write text ?
Thanks Chris.
I'll be in touch if things starts to go south.

janus
Posts: 835
Joined: 25 May 2009
Has thanked: 63 times
Been thanked: 104 times

Re: Writing in the corner of the chart

Postby janus » 19 Apr 2011

The responses and contributions on this thread shows we desperately need a new text writing function that writes to a fixed location on the screen so that scrolling and zooming does not displace the text. This is already the case for the built-in status line we see displayed on our charts. So, why can't we have a function to do the same? Surely it must be one of the easiest things to program into MC. I now notice a similar suggestion has been posted on PM, which is good. However, why limit it to 8 or 16 squares in the window? Why not just use percentages of the x and y axis so the text can be fixed anywhere on the plot area? I've added a comment to the PM suggestion to reflect this.


Return to “MultiCharts”