Terend Line and Txt in Chart  [SOLVED]

Questions about MultiCharts and user contributed studies.
lopper70
Posts: 22
Joined: 17 Oct 2014
Has thanked: 2 times

Terend Line and Txt in Chart

Postby lopper70 » 17 Oct 2014

hello everyone, I have just joined the forum, but I read in many months, since using MC (Version 8.0), I have learned many things
sorry for my english!

I'm trying to create me some good visual indicators and I got a good point, but now I can not improve it.
I want to simply create a horizontal line and a text when RSI indicator is croses under 30 and crosses over 70. then I want that when there is a new signal I need to delete the old lines and txt.
The problem that generates me is that I can not make clear the old signals and the horizontal lines disappear after a while and I have to turn off the indicator and turn it back on.
what is wrong? thanks

this is my code list: (and attach my Dow Jones 15 minutes chart!)

Code: Select all

inputs:
Price (Close),
RSILength( 14 ),
OverSold( 30 ),
OverBought( 70 ),
HighTLColor (red),
LowTLColor (darkgreen),
TLSize(1),
TLStyle(1),
HighTextColor (red),
LowTextColor (darkgreen),
TextSize(14);




Variables:

MyRSI( 0 ),
VertTxtP1 (0), // 0 - Plot UP, 1 - Plott Down, 2 - Plot Center
HorizTxtP1 (0), // 0 - Plotta Right , 1- Plot Left, 2- Plotta Center
OldRSIHigh (0),
OldRSILow (0),
OldTXTLow (0),
OldTXTHigh (0),
HiTxt (-1),
LoTxt (-1),
HiTL (-1),
LoTL (-1);


MyRSI = RSI( Price, RSILength ) ;

if MyRSI crosses under OverSold then
begin
OldRSILow = LoTL;
OldTXTLow = LoTxt;

LoTL = TL_New (Date[1], Time[1], Low, Date, Time, Low);
TL_SetColor(LoTL, LowTLColor);
TL_SetSize(LoTL,TLSize);
TL_SetStyle(LoTL,TLStyle);

LoTxt = Text_New(Date[1], Time[1], Low, " BUY ZONE ");
text_setcolor(LoTxt,LowTextColor);
text_setsize(LoTxt,TextSize);
Text_SetStyle(LoTxt,HorizTxtP1, VertTxtP1);


Value1 = TL_SetExtRight(LoTL, True);
if OldRSILow <> -1 then //reset Old line
Value1 = tl_delete (OldRSILow);

Value2 = tl_setextright(LoTxt, True);
if OldTXTLow <> -1 then
Value2 = tl_delete (OldTXTLow);

end;


if MyRSI crosses over OverBought then
begin
OldRSIHigh = HiTL;
OldTXTHigh = HiTxt;

HiTL = TL_New (Date[1], Time[1], High, Date, Time, High);
TL_SetColor(HiTL, HighTLColor);
TL_SetSize(HiTL,TLSize);
TL_SetStyle(HiTL,TLStyle);

HiTxt = Text_New(Date[1], Time[1], High, " SELL ZONE ");
text_setcolor(HiTxt,HighTextColor);
text_setsize(HiTxt,TextSize);
Text_SetStyle(HiTxt,HorizTxtP1, VertTxtP1);


Value3 = TL_SetExtRight(HiTL, True);
If OldRSIHigh <> -1 Then
Value3 = TL_Delete(OldRSIHigh);

Value4 = tl_setextright(HiTxt, True);
if OldTXTHigh <> -1 then
Value4 = tl_delete(OldTXTHigh);

End;
Attachments
DowJones-15 min RSI.JPG
(179.17 KiB) Downloaded 1175 times
Last edited by lopper70 on 20 Oct 2014, edited 1 time in total.

User avatar
furytrader
Posts: 354
Joined: 30 Jul 2010
Location: Chicago, IL
Has thanked: 155 times
Been thanked: 217 times

Re: Terend Line and Txt in Chart  [SOLVED]

Postby furytrader » 17 Oct 2014

Not sure if this is one of the problems but you need to change the following line of code:

Code: Select all

if OldTXTHigh <> -1 then Value4 = tl_delete(OldTXTHigh);
... to ...

Code: Select all

if OldTXTHigh <> -1 then Value4 = text_delete(OldTXTHigh);

lopper70
Posts: 22
Joined: 17 Oct 2014
Has thanked: 2 times

Re: Terend Line and Txt in Chart

Postby lopper70 » 17 Oct 2014

Not sure if this is one of the problems but you need to change the following line of code:

Code: Select all

if OldTXTHigh <> -1 then Value4 = tl_delete(OldTXTHigh);
... to ...

Code: Select all

if OldTXTHigh <> -1 then Value4 = text_delete(OldTXTHigh);
aahhhhh!!!!!! I never noticed that mistake!
well I checked the code many times and I never realized that it could be that the error...
now it works fine, I see now even if the trend line is perfect and do not disappear as before.
thanks for the help

lopper70
Posts: 22
Joined: 17 Oct 2014
Has thanked: 2 times

Re: Terend Line and Txt in Chart

Postby lopper70 » 20 Oct 2014

Unfortunately, when there is a new signal, it delete the previous line and txt, but do not show the new line and txt!
I have to show for it or turn off / on status indicator in all charts....or re-compil code!
what can be the problem?

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

Re: Terend Line and Txt in Chart

Postby TJ » 20 Oct 2014

Unfortunately, when there is a new signal, it delete the previous line and txt, but do not show the new line and txt!
I have to show for it or turn off / on status indicator in all charts....or re-compil code!
what can be the problem?
Instead of doing all the ID assignment (which can cause timing problem if you do not accurately laid out your logic)...

you can simply use this method:

Code: Select all

tl_delete( HiTxt[1] ) ;

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

Re: Terend Line and Txt in Chart

Postby TJ » 20 Oct 2014

ps:
[FAQ] How to Post Codes (that people can read)
viewtopic.php?f=16&t=11713

lopper70
Posts: 22
Joined: 17 Oct 2014
Has thanked: 2 times

Re: Terend Line and Txt in Chart

Postby lopper70 » 20 Oct 2014

ps:
[FAQ] How to Post Codes (that people can read)
viewtopic.php?f=16&t=11713
sorry, you're right. I edited my first post with putting the window code!

I tried to use the new indication of code, but unfortunately it does not work so often, and when a new signal disappears the old, but I do not see the new.

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

Re: Terend Line and Txt in Chart

Postby TJ » 20 Oct 2014

::
I tried to use the new indication of code, but unfortunately it does not work so often, and when a new signal disappears the old, but I do not see the new.
Please post your re-worked code for further debugging.

lopper70
Posts: 22
Joined: 17 Oct 2014
Has thanked: 2 times

Re: Terend Line and Txt in Chart

Postby lopper70 » 23 Oct 2014

::
I tried to use the new indication of code, but unfortunately it does not work so often, and when a new signal disappears the old, but I do not see the new.
Please post your re-worked code for further debugging.
Here is the modified code, I also left the old code to see
there is the same problem still occurs, just active the code I see the line and txt "SELL ZONE" and "BUY ZONE", but when there is a new signal, everything disappears and does not work.
to make a test I disable the deletion of the past linea and txt, in that case the signals are correct, but I put the text and not the horizontal line.
I discovered that there is a problem in the interim signals...if market get down and RSI indicator is crosses under 30, I see the correct line and txt, but if che market get up very little and RSI indicator back for a moment over 30, the signal is delete immediately...For this reason, do not see it.
If RSI indicator get down very well below 30 and the bar market closes well down, then the signal is fixed well and is not deleted, but it happens very rarely because it takes only a few ticks for RSI get down and up 30, one moment!

this is my code:

Code: Select all

inputs:
Price (Close),
RSILength( 14 ),
OverSold( 30 ),
OverBought( 70 ),
HighTLColor (red),
LowTLColor (darkgreen),
TLSize(1),
TLStyle(1),
HighTextColor (red),
LowTextColor (darkgreen),
TextSize(14);




Variables:

MyRSI( 0 ),
VertTxtP1 (0), // 0 - Plot UP, 1 - Plott Down, 2 - Plot Center
HorizTxtP1 (0), // 0 - Plotta Right , 1- Plot Left, 2- Plotta Center
OldRSIHigh (0),
OldRSILow (0),
OldTXTLow (0),
OldTXTHigh (0),
HiTxt (-1),
LoTxt (-1),
HiTL (-1),
LoTL (-1);


MyRSI = RSI( Price, RSILength ) ;

if MyRSI crosses under OverSold then
begin
OldRSILow = LoTL;
OldTXTLow = LoTxt;

LoTL = TL_New (Date[1], Time[1], Low, Date, Time, Low);
TL_SetColor(LoTL, LowTLColor);
TL_SetSize(LoTL,TLSize);
TL_SetStyle(LoTL,TLStyle);

LoTxt = Text_New(Date[1], Time[1], Low, " BUY ZONE ");
text_setcolor(LoTxt,LowTextColor);
text_setsize(LoTxt,TextSize);
Text_SetStyle(LoTxt,HorizTxtP1, VertTxtP1);


Value1 = TL_SetExtRight(LoTL, True);
if OldRSILow <> -1 then //reset Old line
Value1 = tl_delete (LoTL[1]);
//Value1 = tl_delete (OldRSILow); previus Code used

Value2 = tl_setextright(LoTxt, True);
if OldTXTLow <> -1 then
Value2 = text_delete (LoTxt[1]);
//Value2 = text_delete (OldTXTLow); previus Code used

end;


if MyRSI crosses over OverBought then
begin
OldRSIHigh = HiTL;
OldTXTHigh = HiTxt;

HiTL = TL_New (Date[1], Time[1], High, Date, Time, High);
TL_SetColor(HiTL, HighTLColor);
TL_SetSize(HiTL,TLSize);
TL_SetStyle(HiTL,TLStyle);

HiTxt = Text_New(Date[1], Time[1], High, " SELL ZONE ");
text_setcolor(HiTxt,HighTextColor);
text_setsize(HiTxt,TextSize);
Text_SetStyle(HiTxt,HorizTxtP1, VertTxtP1);


Value3 = TL_SetExtRight(HiTL, True);
If OldRSIHigh <> -1 Then
Value3 = TL_Delete(HiTL[1]);
//Value3 = TL_Delete(OldRSIHigh); previus Code used

Value4 = tl_setextright(HiTxt, True);
if OldTXTHigh <> -1 then
Value4 = text_delete(HITxt[1]);
//Value4 = text_delete(OldTXTHigh); previus Code used
End;

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

Re: Terend Line and Txt in Chart

Postby TJ » 23 Oct 2014

Here is the modified code, I also left the old code to see
there is the same problem still occurs, just active the code I see the line and txt "SELL ZONE" and "BUY ZONE", but when there is a new signal, everything disappears and does not work.
to make a test I disable the deletion of the past linea and txt, in that case the signals are correct, but I put the text and not the horizontal line.
I discovered that there is a problem in the interim signals...if market get down and RSI indicator is crosses under 30, I see the correct line and txt, but if che market get up very little and RSI indicator back for a moment over 30, the signal is delete immediately...For this reason, do not see it.
If RSI indicator get down very well below 30 and the bar market closes well down, then the signal is fixed well and is not deleted, but it happens very rarely because it takes only a few ticks for RSI get down and up 30, one moment!

this is my code:
::
Please read my original message carefully:
Instead of doing all the ID assignment (which can cause timing problem if you do not accurately laid out your logic)...

you can simply use this method:
"instead"... means delete your old method and use the new method.

this is ID assignment (ie you don't need them -- because they can cause timing problem):

Code: Select all

OldRSILow = LoTL;
OldTXTLow = LoTxt;
please remove the whole logic related to the "old"...

Code: Select all

if OldRSILow <> -1 then //reset Old line
Value1 = tl_delete (OldRSILow);
and replace it with this single line:

Code: Select all

tl_delete ( LoTL[1] );
Do the same for all your old drawing objects.

Hope the above helps. If you still encounter the same problem, then there must be something else that caused the error.

lopper70
Posts: 22
Joined: 17 Oct 2014
Has thanked: 2 times

Re: Terend Line and Txt in Chart

Postby lopper70 » 24 Oct 2014

sorry I did not understand!
I modified the old code, but however so I do not see the horizontal lines now, and the old text remains visible, is not deleted!
maybe there are other errors in the my code

This is the current code:

Code: Select all

inputs:
Price (Close),
RSILength( 14 ),
OverSold( 30 ),
OverBought( 70 ),
HighTLColor (red),
LowTLColor (darkgreen),
TLSize(1),
TLStyle(1),
HighTextColor (red),
LowTextColor (darkgreen),
TextSize(14);

Variables:

MyRSI( 0 ),
VertTxtP1 (0), // 0 - Plot UP, 1 - Plott Down, 2 - Plot Center
HorizTxtP1 (0), // 0 - Plotta Right , 1- Plot Left, 2- Plotta Center
HiTxt (-1),
LoTxt (-1),
HiTL (-1),
LoTL (-1);


MyRSI = RSI( Price, RSILength ) ;

if MyRSI crosses under OverSold then
begin


LoTL = TL_New (Date[1], Time[1], Low, Date, Time, Low);
TL_SetColor(LoTL, LowTLColor);
TL_SetSize(LoTL,TLSize);
TL_SetStyle(LoTL,TLStyle);

LoTxt = Text_New(Date[1], Time[1], Low, " BUY ZONE ");
text_setcolor(LoTxt,LowTextColor);
text_setsize(LoTxt,TextSize);
Text_SetStyle(LoTxt,HorizTxtP1, VertTxtP1);

tl_delete ( LoTL[1] );
tl_delete ( LoTxt[1] );

end;


if MyRSI crosses over OverBought then
begin


HiTL = TL_New (Date[1], Time[1], High, Date, Time, High);
TL_SetColor(HiTL, HighTLColor);
TL_SetSize(HiTL,TLSize);
TL_SetStyle(HiTL,TLStyle);

HiTxt = Text_New(Date[1], Time[1], High, " SELL ZONE ");
text_setcolor(HiTxt,HighTextColor);
text_setsize(HiTxt,TextSize);
Text_SetStyle(HiTxt,HorizTxtP1, VertTxtP1);

tl_delete ( HiTL[1] );
tl_delete ( HiTxt[1] );

End;

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

Re: Terend Line and Txt in Chart

Postby TJ » 24 Oct 2014

instead of

Code: Select all

if MyRSI crosses under OverSold then
try:

Code: Select all

if MyRSI < OverSold and MyRSI[1] >= OverSold then

lopper70
Posts: 22
Joined: 17 Oct 2014
Has thanked: 2 times

Re: Terend Line and Txt in Chart

Postby lopper70 » 29 Oct 2014

instead of

Code: Select all

if MyRSI crosses under OverSold then
try:

Code: Select all

if MyRSI < OverSold and MyRSI[1] >= OverSold then

I tried, but unfortunately it does not change anything...remain visible signals past and do not see the horizontal line.

This is the actual code used

Code: Select all

inputs:
Price (Close),
RSILength( 14 ),
OverSold( 30 ),
OverBought( 70 ),
HighTLColor (red),
LowTLColor (darkgreen),
TLSize(1),
TLStyle(1),
HighTextColor (red),
LowTextColor (darkgreen),
TextSize(14);

Variables:

MyRSI( 0 ),
VertTxtP1 (0), // 0 - Plot UP, 1 - Plott Down, 2 - Plot Center
HorizTxtP1 (0), // 0 - Plotta Right , 1- Plot Left, 2- Plotta Center
HiTxt (-1),
LoTxt (-1),
HiTL (-1),
LoTL (-1);


MyRSI = RSI( Price, RSILength ) ;

if MyRSI < OverSold and MyRSI[1] >= OverSold then
begin


LoTL = TL_New (Date[1], Time[1], Low, Date, Time, Low);
TL_SetColor(LoTL, LowTLColor);
TL_SetSize(LoTL,TLSize);
TL_SetStyle(LoTL,TLStyle);

LoTxt = Text_New(Date[1], Time[1], Low, " BUY ZONE ");
text_setcolor(LoTxt,LowTextColor);
text_setsize(LoTxt,TextSize);
Text_SetStyle(LoTxt,HorizTxtP1, VertTxtP1);

tl_delete ( LoTL[1] );
tl_delete ( LoTxt[1] );


end;

if MyRSI > OverBought and MyRSI[1] <= OverBought then
begin


HiTL = TL_New (Date[1], Time[1], High, Date, Time, High);
TL_SetColor(HiTL, HighTLColor);
TL_SetSize(HiTL,TLSize);
TL_SetStyle(HiTL,TLStyle);

HiTxt = Text_New(Date[1], Time[1], High, " SELL ZONE ");
text_setcolor(HiTxt,HighTextColor);
text_setsize(HiTxt,TextSize);
Text_SetStyle(HiTxt,HorizTxtP1, VertTxtP1);

tl_delete ( HiTL[1] );
tl_delete ( HiTxt[1] );

End;

lopper70
Posts: 22
Joined: 17 Oct 2014
Has thanked: 2 times

Re: Terend Line and Txt in Chart

Postby lopper70 » 29 Oct 2014

now I get this result on the chart

[img]
http://gyazo.com/5df3e34a9b1b8585fd646f16190d937c
[/img]


but I want to get this result (This is the first code I posted, but when there is a new signal deletes the old and the new can not be see)

[img]
http://gyazo.com/3fff9e027922145951f86ca99396544a
[/img]
Attachments
Djones-RSI-2.JPG
(81.01 KiB) Downloaded 1155 times

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

Re: Terend Line and Txt in Chart

Postby TJ » 29 Oct 2014

now I get this result on the chart
[img]
http://gyazo.com/5df3e34a9b1b8585fd646f16190d937c
[/img]
but I want to get this result (This is the first code I posted, but when there is a new signal deletes the old and the new can not be see)
[img]
http://gyazo.com/3fff9e027922145951f86ca99396544a
[/img]
You have omitted this line:

Code: Select all

TL_SetExtRight(HiTL, True);

lopper70
Posts: 22
Joined: 17 Oct 2014
Has thanked: 2 times

Re: Terend Line and Txt in Chart

Postby lopper70 » 29 Oct 2014

sorry I thought I had to be taken away! Now put it back and I see the horizontal lines buy and sell.
remain visible earlier texts, do not delete them ... it seems like not read the code

Code: Select all

TL_Delete (HITxt[1] );
I do not understand why...if I delete this code it remains completely unchanged in the chart!
I can solve this problem by not writing the text and using only the lines.
Tomorrow check if the lines work well. thanks

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

Re: Terend Line and Txt in Chart

Postby TJ » 29 Oct 2014

sorry I thought I had to be taken away! Now put it back and I see the horizontal lines buy and sell.
remain visible earlier texts, do not delete them ... it seems like not read the code

Code: Select all

TL_Delete (HITxt[1] );
I do not understand why...if I delete this code it remains completely unchanged in the chart!
I can solve this problem by not writing the text and using only the lines.
Tomorrow check if the lines work well. thanks
I have not been reading your code with a fine tooth comb, because I was expecting you to study the meaning and purpose of every keyword before you apply it to your code.

Please look up the following keywords and study their usage:

TL_delete
Text_delete
TL_SetExtRight


Return to “MultiCharts”