Tool to calc % variation between two points

Studies that have been contributed to the community by other users. If you’ve got something useful to share, that’s great!
Bulli
Posts: 16
Joined: 27 Oct 2012
Location: Brazil
Has thanked: 6 times
Been thanked: 7 times
Contact:

Tool to calc % variation between two points

Postby Bulli » 15 Nov 2013

Very nice indicator by maxmax68, I just added colors, line would be Green when positive and Red when negative.

Code: Select all

{Updated by/Modificado por: Bulli Castelo 15 11 2013, added colors to the line}
{
Provided by maxmax68
Ver 1.0 26.07.2012
Tool to calc % variation between two points drawn with left mouse click
}
[ProcessMouseEvents = true] ;
Inputs:
UpCor(Green),DnCor(Red), Thickness(2);
vars:
recalcpersist date1(0),recalcpersist time1(0),recalcpersist time2(0),
recalcpersist date2(0),recalcpersist price1(0),recalcpersist price2(0),
recalcpersist init(0),recalcpersist counter(0),recalcpersist perc1(0);
// Need to declare variables as recalcpersist to prevent the reset to any recalculation
// that occurs whenever there comes a tick or a mouse click
// Necessario dichiarare le variabili come recalcpersist altrimenti vengono azzerate ad ogni ricalcolo
// che avviene ogni volta che arriva un tick o un click del mouse

if (LastBarOnChart) then
begin
// This switch is used to distinguish which event caused the recalculation: mouse click or new tick
// Questo switch serve a distinguere quale avvenimento ha causato il ricalcolo: click mouse o nuovo tick
switch (getappinfo(aicalcreason))
begin
// recalc for Left Mouse Click
case CalcReason_MouseLClick :
if (init=0) then
begin
date1=JulianToDate(MouseClickDateTime);
time1=datetime2eltime_s(MouseClickDateTime);
price1=MouseClickPrice;
date2=JulianToDate(MouseClickDateTime);
time2=datetime2eltime_s(MouseClickDateTime);
price2=MouseClickPrice;
tl_delete(value10);
value10=tl_new_s(date1,time1,price1,date2,time2,price2);
tl_setsize(value10,thickness);
tl_setcolor(value10,UpCor);
perc1=0;
text_delete(value20);
value20=text_new_s(date2,time2,price2,Text(" ",perc1:0:2," % "));
if (date2=date1 and time2>=time1) then
Text_SetStyle(value20,0,2)
else if (date2=date1 and time2<time1) then
Text_SetStyle(value20,1,2)
else if (date2>=date1) then
Text_SetStyle(value20,0,2)
else if (date2<date1) then
Text_SetStyle(value20,1,2);
if (time2>=time1 or date2>date1) then
Text_SetStyle(value20,0,2)
else
Text_SetStyle(value20,1,2);
tl_setcolor(value20,RED);

init=1;
end
else if (init=1) then
begin
date2=JulianToDate(MouseClickDateTime);
time2=datetime2eltime_s(MouseClickDateTime);
price2=MouseClickPrice;
tl_delete(value10);
value10=tl_new_s(date1,time1,price1,date2,time2,price2);
tl_setsize(value10,thickness);
tl_setcolor(value10,UpCor);
perc1=(price2-price1)*100/price1;
text_delete(value20);
value20=text_new_s(date2,time2,price2,Text(" ",perc1:0:2," % "));
if (date2=date1 and time2>=time1) then
Text_SetStyle(value20,0,2)
else if (date2=date1 and time2<time1) then
Text_SetStyle(value20,1,2)
else if (date2>=date1) then
Text_SetStyle(value20,0,2)
else if (date2<date1) then
Text_SetStyle(value20,1,2);
if perc1>0 then tl_setcolor(value20,UpCor) else tl_setcolor(value20,DnCor) ; //this one from input > Green
init=0;
end;
// recalc for new tick arrived
case CalcReason_default :
// Delete and redraw the line and text to any recalculation
// Facciamo ridisegnare linea e testo che ad ogni ricalcolo vengono cancellate
tl_delete(value10);
value10=tl_new_s(date1,time1,price1,date2,time2,price2);
tl_setsize(value10,thickness);
tl_setcolor(value10,UpCor);
text_delete(value20);
value20=text_new_s(date2,time2,price2,Text(" ",perc1:0:2," % "));
if (date2=date1 and time2>=time1) then
Text_SetStyle(value20,0,2)
else if (date2=date1 and time2<time1) then
Text_SetStyle(value20,1,2)
else if (date2>=date1) then
Text_SetStyle(value20,0,2)
else if (date2<date1) then
Text_SetStyle(value20,1,2);
text_setcolor(value20,UpCor);
end;
end;
Attachments
Up Dn.png
Percentage Between Two Lines
(42.74 KiB) Downloaded 787 times

krisnara
Posts: 2
Joined: 08 Sep 2020

Re: Tool to calc % variation between two points

Postby krisnara » 09 Apr 2021

Happy to have come across this nice tool.I would appreciate if someone can modify it to also include the Swing distance between the 2 points and the number of bars .


Return to “User Contributed Studies and Indicator Library”