Hi, I was wondering if there was a way to achieve this in a chart with labels, like in Ensign?
Announcement
Collapse
No announcement yet.
HH and LL's
Collapse
X
-
I tried to modify zig-zag, but it seems like a few labels are missing:
PHP Code:/*******************************************************************
Description : This Indicator plots ZigZag indicator
Provided By : Developed by TS Support, LLC for eSignal. (c) Copyright 2002
********************************************************************/
function preMain()
{
setPriceStudy(true);
setStudyTitle("ZigZag");
}
var First = true;
var RP = null;
var RPPoint = null;
var RP1 = null;
var RPPoint1 = null;
var Switch = 0;
var Condition1 = false;
var Condition2 = false;
var s = "X";
var SH_1 = 0, SL_1 = 0;
var label = 0;
var text_high = "", text_low = "";
function main(WavePcnt, SwingHigh, SwingLow, Thickness, nColor)
{
if (WavePcnt == null) WavePcnt = .02;
if (SwingHigh == null) SwingHigh = "High";
if (SwingLow == null) SwingLow = "Low";
if (Thickness == null) Thickness = 2;
if (nColor == null) nColor = Color.RGB(0,145,0);
if (nColor == "red") nColor = Color.red;
if (nColor == "black") nColor = Color.black;
if (nColor == "blue") nColor = Color.blue;
if (nColor == "cyan") nColor = Color.cyan;
if (nColor == "green") nColor = Color.green;
if (nColor == "magenta") nColor = Color.magenta;
if (nColor == "white") nColor = Color.white;
if (nColor == "yellow") nColor = Color.yellow;
if (nColor == "purple") nColor = Color.purple;
if (First)
{
First = false;
RP = (high(0) + low(0)) / 2;
RPPoint = getCurrentBarIndex();
RP1 = RP;
RPPoint1 = RPPoint;
}
var SH = 0.0;
var SL = 0.0;
//SwingHigh
var Occur = 1;
var Strength = 1;
var Length = 2;
var Price = SwingHigh;
var vPrice = getValue(Price, 0, -(Strength + Length + Occur + 1));
var Price1 = 0.0;
var J = Strength;
var Found = false;
var Counter = 0;
var X = 0;
var XX = 0;
var YY = 0;
var Truth = true;
for (J = Strength; (J < Length)&&(Found == false); J++)
{
Price1 = vPrice[J];
X = J + 1;
Truth = true;
for (X = (J + 1); ((X - J) <= Strength)&&(Truth); X++)
{
if (Price1 < vPrice[X]) Truth = false;
}
X = J - 1;
for (X = (J - 1); ((J - X) <= Strength)&&(Truth); X--)
{
if (Price1 <= vPrice[X]) Truth = false;
}
if (Truth) Counter++;
if (Counter >= Occur) Found = true;
}
if (Found) SH = Price1;
else SH = -1;
//SwingLow
Price = SwingLow;
vPrice = getValue(Price, 0, -(Strength + Length + Occur + 1));
J = Strength;
Found = false;
Counter = 0;
for (J = Strength; (J < Length)&&(Found == false);J++)
{
Price1 = vPrice[J];
X = J + 1;
Truth = true;
for (X = (J + 1); ((X - J) <= Strength)&&(Truth); X++)
{
if (Price1 > vPrice[X]) Truth = false;
}
X = J - 1;
for (X = (J - 1); ((J - X) <= Strength)&&(Truth); X--)
{
if (Price1 >= vPrice[X]) Truth = false;
}
if (Truth) Counter++;
if (Counter >= Occur) Found = true;
}
if (Found) SL = Price1;
else SL = -1;
//ZigZag
if (SH != -1)
{
if ((Switch != 1)&&(SH >= (RP * (1+(WavePcnt*.01)))))
{
s += "X", label++;
RPPoint1 = RPPoint;
RP1 = RP;
RPPoint = getCurrentBarIndex() - 1;
RP = SH;
//drawLineAbsolute(RPPoint,RP,RPPoint1,RP1, PS_SOLID, Thickness, nColor, s);
if (SH_1 != SH)
text_high = SH_1 < SH ? "HH" : "LH";
drawTextAbsolute( RPPoint, RP+0.18, text_high, Color.green, null, Text.ONTOP | Text.CENTER | Text.BOLD | Text.TOP, "Arial", 12, label );
Switch = 1;
}
else
if ((Switch == 1)&&(SH >= RP))
{
RPPoint = getCurrentBarIndex() - 1;
RP = SH;
//drawLineAbsolute(RPPoint,RP,RPPoint1,RP1, PS_SOLID, Thickness, nColor, s);
if (SH_1 != SH)
text_high = SH_1 < SH ? "HH" : "LH";
drawTextAbsolute( RPPoint, RP+0.18, text_high, Color.green, null, Text.ONTOP | Text.CENTER | Text.BOLD | Text.TOP, "Arial", 12, label++ );
}
SH_1 = SH;
}
if (SL != -1)
{
if ((Switch != -1)&&(SL <= (RP - (RP*(WavePcnt*.01)))))
{
s += "X", label++;
RPPoint1 = RPPoint;
RP1 = RP;
RPPoint = getCurrentBarIndex() - 1;
RP = SL;
//drawLineAbsolute(RPPoint,RP,RPPoint1,RP1, PS_SOLID, Thickness, nColor, s);
if (SL_1 != SL)
text_low = SL_1 > SL ? "LL" : "HL";
drawTextAbsolute( RPPoint, RP-0.18, text_low, Color.red, null, Text.ONTOP | Text.CENTER | Text.BOLD | Text.BOTTOM, "Arial", 12, label++ );
Switch = -1;
}
else
if ((Switch == -1)&&(SL <= RP))
{
RPPoint = getCurrentBarIndex() - 1;
RP = SL;
//drawLineAbsolute(RPPoint,RP,RPPoint1,RP1, PS_SOLID, Thickness, nColor, s);
if (SL_1 != SL)
text_low = SL_1 > SL ? "LL" : "HL";
drawTextAbsolute( RPPoint, RP-0.18, text_low, Color.red, null, Text.ONTOP | Text.CENTER | Text.BOLD | Text.BOTTOM, "Arial", 12, label );
}
SL_1 = SL;
}
return;
}
Last edited by atlas; 12-01-2007, 06:08 PM.
-
Hello Atlas,
The bars you have circled in your image simply did not meet any of the criteria that draws the labels. If you add a debug statement and print out the bar index when each condition in the formula draws a label, you will see that they match the bar index locations of the labels that appear on the chart.
To have the extra bars you've highlighted receive a label, you need to either add another condition or modify the existing conditions.Jason K.
Project Manager
eSignal - an Interactive Data company
EFS KnowledgeBase
JavaScript for EFS Video Series
EFS Beginner Tutorial Series
EFS Glossary
Custom EFS Development Policy
New User Orientation
Comment
-
Hello atlas,
Doesn't look like the original code was written for real time updating. Try changing all of the drawTextAbsolute() calls to drawTextRelative() and replace the variable used for the x-coordinate from RPPoint to 0.
Jason K.
Project Manager
eSignal - an Interactive Data company
EFS KnowledgeBase
JavaScript for EFS Video Series
EFS Beginner Tutorial Series
EFS Glossary
Custom EFS Development Policy
New User Orientation
Comment
Comment