Total, Highest, Lowest Delta

Studies that have been contributed to the community by other users. If you’ve got something useful to share, that’s great!
User avatar
arnie
Posts: 1589
Joined: 11 Feb 2009
Location: Portugal
Has thanked: 478 times
Been thanked: 509 times

Total, Highest, Lowest Delta

Postby arnie » 14 Feb 2013

Based on what SP made on his NumbersBars study I wrote this one to accomplish my needs.

Image

Code: Select all

// Fernando
// 10-02-2013
// Plot the total, the highest and lowest delta
   {- Add Cumulative Delta as 2nd data series with the same resolution as the main data series
      and base this study on that 2nd data series. Also set it to - Break on Session}

inputs:
   FontType            ("Lucida Sans Typewriter"),
   ShowLabels            (false), // labels each delta calculation
   LabelTextSize            (8),
   LabelColor            (darkgray),
   ShowDeltaHistory         (false), // plots delta calculations prior to today
   ShowHiLoVariation         (true), // plots percentage calculation of total delta against highest and lowest delta
   TextColor            (white),
   DeltaTextSize            (13),
   HiLoTextSize            (10),
   PlusDeltaColor         (blue),
   MinusDeltaColor         (red),
   DeltaLocation            (1.4), // text location on the subchart
   VariLocation            (0.9), // text location on the subchart
   HiDeltaLocation         (0.5), // text location on the subchart
   LoDeltaLocation         (0); // text location on the subchart

variables:
   myDelta            (0),
   myHighDelta            (0),
   myLowDelta            (0),
   hiDeltaVari            (0),
   loDeltaVari            (0),
   deltaTXT            (-1),
   highTXT            (-1),
   lowTXT               (-1),
   variTXT            (-1),
   myDeltaTXT            (-1),
   myHighTXT            (-1),
   myLowTXT            (-1),
   deltaVariTXT            (-1);

if currentbar =  1 then begin
   // Label text
   if ShowLabels = true then begin
      deltaTXT= text_new_self_s(date, time_s, DeltaLocation, "");
         text_setfontname(deltaTXT, FontType);
         text_setsize(deltaTXT, LabelTextSize);
         text_setstyle(deltaTXT, 0, 0); // Hrz = 0=right 1=left 2=centered Vrt = 0=below 1=above 2=centered
         text_setcolor(deltaTXT, LabelColor);

      highTXT= text_new_self_s(date, time_s, HiDeltaLocation, "");
         text_setfontname(highTXT, FontType);
         text_setsize(highTXT, LabelTextSize);
         text_setstyle(highTXT, 0, 0); // Hrz = 0=right 1=left 2=centered Vrt = 0=below 1=above 2=centered
         text_setcolor(highTXT, LabelColor);

      lowTXT= text_new_self_s(date, time_s, LoDeltaLocation, "");
         text_setfontname(lowTXT, FontType);
         text_setsize(lowTXT, LabelTextSize);
         text_setstyle(lowTXT, 0, 0); // Hrz = 0=right 1=left 2=centered Vrt = 0=below 1=above 2=centered
         text_setcolor(lowTXT, LabelColor);
      
      if ShowHiLoVariation = true then begin
         variTXT= text_new_self_s(date, time_s, VariLocation, "");
            text_setfontname(variTXT, FontType);
            text_setsize(variTXT, LabelTextSize);
            text_setstyle(variTXT, 0, 0); // Hrz = 0=right 1=left 2=centered Vrt = 0=below 1=above 2=centered
            text_setcolor(variTXT, LabelColor);
            //text_setbgcolor(variTXT, black);
      end;
   end;
end;
   
if date <> date[1] then begin
   // Delta prices
   myDelta = close;
   myHighDelta = high;
   myLowDelta = low;
end
else begin
   // Delta prices
   myDelta = close - close[1];   
   myHighDelta = high - close[1];
   myLowDelta = low -  close[1];
end;

// Highest delta variation
if myHighDelta <> 0 then
   hiDeltaVari = ((myDelta / myHighDelta) - 1) * 100;
// Lowest delta variation
if myLowDelta <> 0 then
   loDeltaVari = ((myDelta / myLowDelta) - 1) * 100;

// Total, highest and lowest delta text
if ShowDeltaHistory = true or (ShowDeltaHistory = false and date = LastCalcDate) then begin
   myDeltaTXT = text_new_self_s(date, time_s, DeltaLocation, "");
      text_setfontname(myDeltaTXT, FontType);
      text_setsize(myDeltaTXT, 13);
      text_setstyle(myDeltaTXT, 2, 0); // Hrz = 0=right 1=left 2=centered Vrt = 0=below 1=above 2=centered
      text_setcolor(myDeltaTXT, TextColor);

   myHighTXT= text_new_self_s(date, time_s, HiDeltaLocation, "");
      text_setfontname(myHighTXT, FontType);
      text_setsize(myHighTXT, 10);
      text_setstyle(myHighTXT, 2, 0); // Hrz = 0=right 1=left 2=centered Vrt = 0=below 1=above 2=centered
      text_setcolor(myHighTXT, TextColor);
      
   myLowTXT= text_new_self_s(date, time_s, LoDeltaLocation, "");
      text_setfontname(myLowTXT, FontType);
      text_setsize(myLowTXT, 10);
      text_setstyle(myLowTXT, 2, 0); // Hrz = 0=right 1=left 2=centered Vrt = 0=below 1=above 2=centered
      text_setcolor(myLowTXT, TextColor);

      if ShowHiLoVariation = true then begin
         deltaVariTXT= text_new_self_s(date, time_s, VariLocation, "");
            text_setfontname(deltaVariTXT, FontType);
            text_setsize(deltaVariTXT, HiLoTextSize);
            text_setstyle(deltaVariTXT, 2, 0); // Hrz = 0=right 1=left 2=centered Vrt = 0=below 1=above 2=centered
            text_setcolor(deltaVariTXT, TextColor);
      end;
end;

// set highest and lowest delta string variation
if myDelta > 0 then
   text_setstring(deltaVariTXT, {spaces(5 - strlen(numtostr(hiDeltaVari, 0))) +} numtostr(hiDeltaVari, 0) + "%")
else
   text_setstring(deltaVariTXT, {spaces(5 - strlen(numtostr(loDeltaVari, 0))) +} numtostr(absValue(loDeltaVari), 0) + "%");

// set delta string
text_setstring(myDeltaTXT, {spaces(5 - strlen(numtostr(myDelta, 0))) +} numtostr(myDelta, 0));

// set delta string background color
   if myDelta > 0 then
      text_setbgcolor(myDeltaTXT, PlusDeltaColor)
   else
      text_setbgcolor(myDeltaTXT, MinusDeltaColor);

// set highest delta string and background color
if myHighDelta > 0 then                                               
   text_setstring(myHighTXT, spaces(8 - strlen(numtostr(myHighDelta, 0))) + numtostr(myHighDelta, 0))
else
   text_setstring(myHighTXT, spaces(8 - strlen(numtostr(myHighDelta, 0))) + "0");
   text_setbgcolor(myHighTXT, PlusDeltaColor);

// set lowest delta string and background color   
if myLowDelta < 0 then   
   text_setstring(myLowTXT, spaces(8 - strlen(numtostr(myLowDelta, 0))) + numtostr(myLowDelta, 0))
else
   text_setstring(myLowTXT, spaces(8 - strlen(numtostr(myLowDelta, 0))) + "0");
   text_setbgcolor(myLowTXT, MinusDeltaColor);

// set labels string and location
text_setlocation_s(deltaTXT, date, time_s, DeltaLocation);
text_setstring(deltaTXT, spaces(12 - strlen(numtostr(myHighDelta, 0))) + "Total Delta");

text_setlocation_s(variTXT, date, time_s, VariLocation);
text_setstring(variTXT, spaces(12 - strlen(numtostr(myHighDelta, 0))) + "Total Delta %");

text_setlocation_s(highTXT, date, time_s, HiDeltaLocation);
text_setstring(highTXT, spaces(12 - strlen(numtostr(myHighDelta, 0))) + "Highest Delta");

text_setlocation_s(lowTXT, date, time_s, LoDeltaLocation);
text_setstring(lowTXT, spaces(12 - strlen(numtostr(myHighDelta, 0))) + "Lowest Delta");
Attachments
delta_subchart.png
delta_subchart.png (98.01 KiB) Viewed 1560 times

User avatar
swisstrader
Posts: 110
Joined: 16 Nov 2005
Location: Earth
Has thanked: 13 times
Been thanked: 19 times
Contact:

Re: Total, Highest, Lowest Delta

Postby swisstrader » 21 Oct 2013

Good job!

jl12
Posts: 197
Joined: 29 Jun 2007
Has thanked: 8 times
Been thanked: 8 times
Contact:

Re: Total, Highest, Lowest Delta

Postby jl12 » 14 Nov 2014

I've tried to plot this indicator however there seems to be an issue.

I have attached a screenshot
vp.png
vp.png (16.55 KiB) Viewed 931 times


Any suggestions please.

User avatar
arnie
Posts: 1589
Joined: 11 Feb 2009
Location: Portugal
Has thanked: 478 times
Been thanked: 509 times

Re: Total, Highest, Lowest Delta

Postby arnie » 14 Nov 2014

jl12 wrote:I've tried to plot this indicator however there seems to be an issue.

I have attached a screenshot
vp.png


Any suggestions please.


Please read the 4th and 5th line of code.
What does it say?

Hint - 2nd data series

jl12
Posts: 197
Joined: 29 Jun 2007
Has thanked: 8 times
Been thanked: 8 times
Contact:

Re: Total, Highest, Lowest Delta

Postby jl12 » 14 Nov 2014

Arnie

Thanks for pointing that out I hadn't noticed that out originally.

However the second data series hasn't helped very much the figures still don't look right.
VPSTATS2.png
VPSTATS2.png (47.05 KiB) Viewed 935 times

ax
Posts: 34
Joined: 21 Nov 2005
Has thanked: 15 times
Been thanked: 2 times

Re: Total, Highest, Lowest Delta

Postby ax » 10 Oct 2015

Adjust the scale and.......Works Great !!

Thank you
Attachments
HiLo Delta.png
HiLo Delta.png (47.41 KiB) Viewed 804 times


Return to “User Contributed Studies and Indicator Library”