Text_SetLocation not for vertical location change

Questions about MultiCharts and user contributed studies.
PK1
Posts: 46
Joined: 12 Jun 2011
Has thanked: 21 times
Been thanked: 8 times

Text_SetLocation not for vertical location change

Postby PK1 » 20 Aug 2012

While re-arranging the marketdepth indicator I came to some un-easy things while dealing with text strings. If I want to put a simple text I can create a new text object with text_new_s and giving as paramater a place for X and Y (datetime and price). The last time MC often has problems with not enough memory (on a 64 Bit machine with 16GB) so I am carefully creating new objects, instead I want to re-use them by just changing the vertical location instead of endless creating new things, like draw_DOM_level (unfortunately) does.

I wonder if there is another method oder something additionally I have to do. So what can I do that Text_SetLocation is using the Price - Param to change the location of the string?

User avatar
TJ
Posts: 6598
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 971 times
Been thanked: 1909 times

Re: Text_SetLocation not for vertical location change

Postby TJ » 21 Aug 2012

PK1 wrote:While re-arranging the marketdepth indicator I came to some un-easy things while dealing with text strings. If I want to put a simple text I can create a new text object with text_new_s and giving as paramater a place for X and Y (datetime and price). The last time MC often has problems with not enough memory (on a 64 Bit machine with 16GB) so I am carefully creating new objects, instead I want to re-use them by just changing the vertical location instead of endless creating new things, like draw_DOM_level (unfortunately) does.

I wonder if there is another method oder something additionally I have to do. So what can I do that Text_SetLocation is using the Price - Param to change the location of the string?

What would you propose?
These users thanked the author TJ for the post:
PK1

User avatar
ABC
Posts: 528
Joined: 16 Dec 2006
Has thanked: 112 times
Been thanked: 296 times
Contact:

Re: Text_SetLocation not for vertical location change

Postby ABC » 21 Aug 2012

PK1,

it's a bit hard for me to understand what you are trying to do. If you have created your text IDs with text_new_s and want to change the location, you should use text_setlocation_s and for that you will need date, time and price information of the new location.

In case you only want to change the price and keep the horizontal location the same, either store time and date in a variable once you create the text object or use text_getdate and text_gettime_s to retrieve the date and time of the text object. There is no reserved word that allows you to input a new price value only, without using the values for the horizontal text location.

Regards,
ABC
These users thanked the author ABC for the post (total 2):
PK1JoshM

User avatar
Henry MultiСharts
Posts: 8520
Joined: 25 Aug 2011
Has thanked: 1213 times
Been thanked: 2741 times

Re: Text_SetLocation not for vertical location change

Postby Henry MultiСharts » 21 Aug 2012

In order to replace the existing drawing you need to use the ID of the previously plotted drawing with new coordinates IDText=Text_SetLocation(IDText,Date,Time,High);
These users thanked the author Henry MultiСharts for the post:
PK1

PK1
Posts: 46
Joined: 12 Jun 2011
Has thanked: 21 times
Been thanked: 8 times

Re: Text_SetLocation not for vertical location change

Postby PK1 » 21 Aug 2012

@ABC thx for your help, pls see the last sentence of my first posting.
@Henry from dictionary-documentation: "returns a value of 0 if the location of the object was successfully modified, and a value of -2 if the specified object ID number is invalid"

User avatar
ABC
Posts: 528
Joined: 16 Dec 2006
Has thanked: 112 times
Been thanked: 296 times
Contact:

Re: Text_SetLocation not for vertical location change

Postby ABC » 21 Aug 2012

PK1 wrote:@ABC thx for your help, pls see the last sentence of my first posting.
[/i]"


PK1, I am sorry, but I still don't get it. You need a date and time for a specific price, otherwise you get a line spanning around all date and time values for your price.
Can you give an example on what you exactly are trying to do?
These users thanked the author ABC for the post:
PK1

PK1
Posts: 46
Joined: 12 Jun 2011
Has thanked: 21 times
Been thanked: 8 times

Re: Text_SetLocation not for vertical location change

Postby PK1 » 21 Aug 2012

_txtObjId = Text_New( ... ) // once

_lastDate = getappinfo(AIRightDispDateTime);

// later on
_result = Text_SetLocation(_txtObjId, JulianToDate(_lastDate), datetime2eltime_s(_lastDate), Last);


I get it working but checking some things and post here ...

PK1
Posts: 46
Joined: 12 Jun 2011
Has thanked: 21 times
Been thanked: 8 times

Re: Text_SetLocation not for vertical location change

Postby PK1 » 21 Aug 2012

TJ, I can't give You an answer to this.

I've tried some things, thought it would be working but was not. Following a shortened piece of indicator code showing a text with Last at the current price. To get it running You won't need _GetIntervalType, any string will be fine. For the indicator Update on every tick should be checked.

The indicator will position the text on the right, by using the last datetime fetched via GetAppInfo. On the first run-through the text is not existing and will be calculated. The id is kept in the variable _txtId. The next tick after creation of the txt the indicator should use the second branch by only changing the location. Text_SetLocation_s is not assigning a new txtId as I understood the posting from Henrik. There are defined return values. I've documented this in the code below, the MC-Dictionary-Docu just tells about code 0 and -2. But the aim of this code should be clear, showing the last price on the position 'last DateTime + last price'.

While trying different scenarios, sometimes the txt was updating as expecting. Then in the output window one could see that the txt is existing and only the location was changed. Fine! But then from suddenly the check whether the txt is existing was not true anymore ... hardly to summarize this behavior.

Now the probs I'm talking about with this code:

    *I'm not anymore sure whether Text_Exist should be used or is used in a wrong way. So I'm using another compare-mechanism (if _txtId < 0) with default value of -1. TJ?
    * When running the indicator at start the text will be created and the id stored in _txtId, but with the next tick the text object is gone, lost, removed ... calling the Text_SetLocation_s method is resulting in the proper result of -2 because the object is not there anymore, even on the chart

Code: Select all

if not LastBarOnChart_s then #return;

variables:
 _lastDate (0),
 _result   (0),
intrabarpersist _txtId (-1),
 _tfStr    (""),
 _txtVal   (" - ");

once
 begin
   _tfStr = _GetIntervalType(); // M5, M15, ...
 END;
 
_lastDate = getappinfo(AIRightDispDateTime);
_txtVal   = Text("Last: ", Last:4:4);

Print("#1   (", _tfStr, ") _txtId: ",  _txtId);

// if Text_Exist(_txtId) = false then
if _txtId < 0 then
  BEGIN
   Print("#2.1 (", _tfStr, ") TxtId ", _txtId, " ##### DOESN'T ##### exists.");
    _txtId = text_new(JulianToDate(_lastDate), datetime2eltime_s(_lastDate), Last, _txtVal);
   
   Text_SetColor(_txtId, LightGray);
   Text_SetStyle(_txtId,
                 1,         // 0 .. to the right of the specified bar, 1 .. left,  2 .. centered
                 2);        // 0 .. below the specified value,         1 .. above, 2 .. centered
   Print("#2.2 (", _tfStr, ") Text object created with Id: ", _txtId);
  END
else
  BEGIN
    Print("#3.1 (", _tfStr, ") TxtObj ", _txtId, " exists.");
    Text_SetString(_txtId, _txtVal);
   
    // _result will be -2, means ObjId invalid --> because the text obj is not there anymore, what happened here??
    _result = Text_SetLocation_s(_txtId, JulianToDate(_lastDate), datetime2eltime_s(_lastDate), Last);

    // _result will be -1, means wrong Date/Time param
    // _result = Text_SetLocation(_txtId, JulianToDate(_lastDate), datetime2eltime_s(_lastDate), Last);
   
    if      _result = -2 then Print("Text_SetLocation: TxtId invalid")
    else if _result = -1 then Print("Text_SetLocation: Date and/or Time param invalid");

    Print("#3.2 (", _tfStr, ") Setting new location with result: ", _result);
  END;


Any idea what is wrong?
Last edited by PK1 on 22 Aug 2012, edited 1 time in total.

User avatar
TJ
Posts: 6598
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 971 times
Been thanked: 1909 times

Re: Text_SetLocation not for vertical location change

Postby TJ » 21 Aug 2012

PK1 wrote:TJ, I can't give You an answer to this.
...
Any idea what is wrong?


Can you draw a diagram(s) to illustrate how you would like the text operation presented on the chart?
These users thanked the author TJ for the post:
PK1

PK1
Posts: 46
Joined: 12 Jun 2011
Has thanked: 21 times
Been thanked: 8 times

Re: Text_SetLocation not for vertical location change

Postby PK1 » 21 Aug 2012

What else can I write more? The text should be changed by placing on the chart on the current place according to AIRightDispDateTime and Last-Price to be used as X and Y-Ordinates. Can You run this indicator and see that the object is getting disposed?

PK1
Posts: 46
Joined: 12 Jun 2011
Has thanked: 21 times
Been thanked: 8 times

Re: Text_SetLocation not for vertical location change

Postby PK1 » 21 Aug 2012

Changing the line

if _txtId < 0 then
into
if Text_Exist(_txtId) = false then

will do on the chart what I am expecting from the indicator, but here the lost/disposed txt object will be created again and again instead of just changing the location.

PK1
Posts: 46
Joined: 12 Jun 2011
Has thanked: 21 times
Been thanked: 8 times

Re: Text_SetLocation not for vertical location change

Postby PK1 » 22 Aug 2012

Regarding the probs (see #8) with Text_Exist I now understand. From my point of view it's not working because the used functions Text_GetFirst(3) is not delivering a newly created text object (at least not in the same bar, only after the bar is closed). Perhaps this is a forced limitation but within an indicator it leaves out existing objects hence not really helpful.

Edit: Why is this issue set to solved? I was explaining thorough that there are problems (bugs?). The subject should be changed, yes, but I have no solution how to use this function properly. My investigations showed me that the problem is not originally on this method, more on the context when using it, but that doesn't imply that I can use this method as expected. An example is given.

Edit2: Text_Exist can not find the text object because with next tick the text object it's already disposed. What is MC doing here??

PK1
Posts: 46
Joined: 12 Jun 2011
Has thanked: 21 times
Been thanked: 8 times

Re: Text_SetLocation not for vertical location change

Postby PK1 » 22 Aug 2012

It seems that it wasn't possible to use the function as expected but late I checked the existence of the underlying txt object itself. I did not know that there is such kind of wrong 'garbarge collecting'. Meaning the handling of MC with txt objects is not as it should be. This is clarification for me why functions like draw_DOM_level are not re-using text objects as it should be for doing best practice.

Some summary:
    * Indicator-Settings: 'Update on every tick' CHECKED --> txt object is getting disposed (lost) with next tick. Hence having this checked the indicator is getting updated with every thick but text object is lost and need to be created again, again and again ... This is the bug
    * Indicator-Settings: 'Update on every tick' UNCHECKED --> txt object is not getting disposed with next tick and can be re-used. Furthermore the object is still there with next bar. Perfect.

In the chat Andrew told me about this wrong handling, (perhaps) solved in 8.1.

User avatar
TJ
Posts: 6598
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 971 times
Been thanked: 1909 times

Re: Text_SetLocation not for vertical location change

Postby TJ » 22 Aug 2012

How is this used?

Code: Select all

intrabarpersist _txtId (-1),

PK1
Posts: 46
Joined: 12 Jun 2011
Has thanked: 21 times
Been thanked: 8 times

Re: Text_SetLocation not for vertical location change

Postby PK1 » 22 Aug 2012

TJ wrote:why do you need this?

Code: Select all

intrabarpersist _txtId (-1),


intrabarpersist for persisting until next indicator processing. The -1 was a try but will be overwritten by MC with next bar. Hence this check can be used within a bar but not later. Following the code again with my _TxtExist. Running the code you see in the Output window that until next bar with every tick the text object is not there needs to be created again and again. But with next bar things change ...

Indicator:

Code: Select all

if not LastBarOnChart_s then #return;
variables:
 _lastDate (0),
 _result   (0),
intrabarpersist _txtId    (0),  // shouldn't be -1 because with a new bar the value will be set to 0
 _txtVal   (" - ");

_lastDate = getappinfo(AIRightDispDateTime);
_txtVal   = Text("Last: ", Last:4:4);

_printTxtObjects(false);
Print("##1   _txtId: ",  _txtId :0:0);

if _TxtExist(_txtId, false) = false then
// if _txtId <= 0 then // <= instead of < 0 necessary because with next bar the variable will be set to 0.
  BEGIN
   Print("##2.1 _txtId_ ", _txtId:0:0, " ##### DOESN'T ##### exists.");
    _txtId = text_new(JulianToDate(_lastDate), datetime2eltime_s(_lastDate), Last, _txtVal);
   Text_SetColor(_txtId , LightGray);   Text_SetStyle(_txtId , 1, 2);
   Print("##2.2 Text object created with Id: ", _txtId :0:0);
  END;
   
  BEGIN
    Text_SetString(_txtId, _txtVal);
   
    // _result will be -2, means ObjId invalid --> because the text obj is not there anymore, what happened here??
    _result = Text_SetLocation_s(_txtId , JulianToDate(_lastDate), datetime2eltime_s(_lastDate), Last);
    if      _result = -2 then Print("##3.2 Setting new location for _txtId (", _txtId:0:0, ") with result: Invalid")
    else if _result = -1 then Print("##3.2 Setting new location for _txtId (", _txtId:0:0, ") with result: Date and/or Time param invalid")
    else                      Print("##3.2 Setting new location for _txtId (", _txtId:0:0, ") with result: SUCCESS.");
  END;
 


Helper-Function _printTxtObjects

Code: Select all

inputs:
    createdByCurrentStudy(TrueFalse);
   
variables:
    txtIdFound(0),
    txtIdFoundContent(""),
    param(0);

// 3: returns objId for the first added txtObj added by ANY study or user
// 4: returns objId for the first added txtObj added by CURRENT study or user
if createdByCurrentStudy = True then param = 4
else                                 param = 3;

Print("--------------------->");
txtIdFound = Text_GetFirst(param);
if txtIdFound > 0 then
   BEGIN
     if txtIdFound > 0 then txtIdFoundContent = "(" + Text_GetString(txtIdFound) + ")"
     else                   txtIdFoundContent = "";
   END;
   Print("> ", txtIdFound:0:0, txtIdFoundContent);

WHILE txtIdFound > 0  // I'd need a DO ... WHILE Notation here ;)
  BEGIN
     txtIdFound = Text_GetNext(txtIdFound, param); // get the next text object added after txtIdFound

     if txtIdFound > 0 then txtIdFoundContent = "(" + Text_GetString(txtIdFound) + ")"
     else                   txtIdFoundContent = "";
     Print("> ", txtIdFound:0:0, txtIdFoundContent);
  END;

_printTxtObjects = 1;
Print("<---------------------");


Helper-Function _TxtExist

Code: Select all

inputs:
    txtId(numericsimple),
    createdByCurrentStudy(TrueFalse);
   
variables:
    var0(0),
    param(0);

_TxtExist = false;

// 3: returns objId for the first added txtObj added by ANY study or user
// 4: returns objId for the first added txtObj added by CURRENT study or user
if createdByCurrentStudy then param = 4
else                          param = 3;

var0 = Text_GetFirst(param);
if var0 = txtId then
  BEGIN
    _TxtExist = true;
    #return;
  END;

while var0 >= 0
  begin
    if var0 = txtId then   // Found obj identical to the overgiven one
   begin
     _TxtExist = true;
     var0 = -2;
       end
    else var0 = Text_GetNext(var0, param); // get the next text object added after var0
  end;
These users thanked the author PK1 for the post:
TJ

User avatar
JoshM
Posts: 2089
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1525 times
Been thanked: 1485 times
Contact:

Re: Text_SetLocation not for vertical location change

Postby JoshM » 25 Aug 2012

PK1 wrote:intrabarpersist for persisting until next indicator processing. The -1 was a try but will be overwritten by MC with next bar. Hence this check can be used within a bar but not later.

(..)

But with next bar things change ...

I haven't deciphered all your code in this thread, but are you aware of this?

bowlesj3 wrote:Text, Trend Lines and Arrows will not remain until they are placed when Barstatus=2 (that is the last tick of the bar). So if 50 ticks come in during a bar and the first tick is when your first Text_new occurs then that text will be deleted on every next tick up until barstatus=2. Intrabarpersist will not help with this.

Read more here about that behaviour.

PK1
Posts: 46
Joined: 12 Jun 2011
Has thanked: 21 times
Been thanked: 8 times

Re: Text_SetLocation not for vertical location change

Postby PK1 » 25 Aug 2012

@Josh Thanks for this information. Looks like this is explaining the behavior. But pls. read my summary in #13, where this behavior is different depending on one indicator setting.

I did quite a lot of investigation what MC is doing until #13 then I was told it's known and likely solved in 8.1. Now I read the explanation of TJ that the reference of the objects is bound to EOB. A design decision ... ;(


Return to “MultiCharts”