I have been working on drawing lines in my advanced charts but have experienced a number of difficulties as many of the functions are not seemingly properly documented which I would like to get some comments/assistance/advice.
I have used both drawLineRelative and drawLineAbsolute with varying degrees of success as follows:-
///////////////////////////////////////////////
Use of drawLineXXX()
///////////////////////////////////////////////
1. drawLineAbsolute(x1, y1, x2, y2, Line Type, Thickness, Color, TagID);
I have tried to use a combination of:-
getCurrentBarIndex() ; This should give bar index numbers starting at 0 for the current index with the amount incrementing negatively to the prior bar index and shouild update incremently as each bar is drawn. in my system this is never done.
getOldestBarIndex(); This should give the total number of bar indicies startimng from start to current. This should update incremently as each bar is drawn. In my system this is never done.
To fix the x1 and x2 coorinates with poor success, as these functions to do not update properly on my system and you have to reset the chart by reloading the efs file so that it shows the current situation. I believe there is flaw in the coding of the functions
2. drawLineRelative(x1, y1, x2, y2, Line Type, Thickness, Color, TagID);
This has worked out much better drawing the line in majority of cases where I want it. I still have some small problems but they are too esotrerci to go through here at this satge. Please see the code fragments below which has worked out for. What was critical was building the x2 parameter. x1 was easy as that is 0. However the problem is how to build x2. The only way because neither getCurrentBarIndex() or getOldestBarIndex() workews on my system is to build an index of my own.
I have also used a number of differing methods to fix the TagID with the best success using rawtime as in the examples below.
///////////////////////////////////////////////////////////
Building an Index based on Time and Chart Interval
///////////////////////////////////////////////////////////
function preMain()......
var vInterval = null;
var vIndex = 0;
function main()......
var bState = getBarState();
var vRawTime;
if (bState == BARSTATE_ALLBARS){
vInterval = getInterval();
}
vRawTime = getValue("rawtime")
if(vInterval == null)
return;
if(vInterval == "D"){
vIndex = (vRawTime/(60*60*24))
}else if(vInterval == "W"){
vIndex = (vRawTime/((60*60*24*7)))
}else if(vInterval == "M"){
vIndex = (vRawTime/((60*60*24*365.25)/12));
}else{
vIndex = (vRawTime/(vInterval*60))
}
///////////////////////////////////////////////////////////
Assigning x coordinates based on Time/Chart Interval Index
///////////////////////////////////////////////////////////
function preMain()......
var RP = null;
var RPPoint = null;
var RP1 = null;
var RPPoint1 = null;
var aRP = null;
var aRPPoint = null;
function main()......
var bState = getBarState();
var 0, o2;
if (bState == BARSTATE_ALLBARS){
aRP = new Array(2);
o = 0;
aRPPoint = new Array(2);
o2 = 0;
}
Some parameter equal to a value
RPPoint = vIndex;
RP = (current close etc...);
RPPoint1 = (aRPPoint[0]-RPPoint);
RP1 = aRP[0];
drawLineRelative(0,RP,RPPoint1,RP1, PS_SOLID, Thickness, Color, vIndex);
// Fixing RP into Array
if(o < 2) { // prime the array
aRP[o] = RP;
o++;
return;
}
if(bState == BARSTATE_NEWBAR) {
aRP.shift();
aRP.push(RP);
} else if(bState == BARSTATE_CURRENTBAR) {
aRP[1] = RP;
}
// Fixing RPPoint into Array
if(o2 < 2) { // prime the array
aRPPoint[o2] = RPPoint;
o2++;
return;
}
if(bState == BARSTATE_NEWBAR) {
aRPPoint.shift();
aRPPoint.push(RPPoint);
} else if(bState == BARSTATE_CURRENTBAR) {
aRPPoint[1] = RPPoint;
}
/////////////////////////////////////////////////
QUSETIONS
/////////////////////////////////////////////////
My questions are as follows:-
A. How do you clear a previous drawn line considering the the line TagID is XXX
B. Why do getCurrentBarIndex() or getOldestBarIndex() do not work properly.
C. Can the code I put forward be made more efficient
I have used both drawLineRelative and drawLineAbsolute with varying degrees of success as follows:-
///////////////////////////////////////////////
Use of drawLineXXX()
///////////////////////////////////////////////
1. drawLineAbsolute(x1, y1, x2, y2, Line Type, Thickness, Color, TagID);
I have tried to use a combination of:-
getCurrentBarIndex() ; This should give bar index numbers starting at 0 for the current index with the amount incrementing negatively to the prior bar index and shouild update incremently as each bar is drawn. in my system this is never done.
getOldestBarIndex(); This should give the total number of bar indicies startimng from start to current. This should update incremently as each bar is drawn. In my system this is never done.
To fix the x1 and x2 coorinates with poor success, as these functions to do not update properly on my system and you have to reset the chart by reloading the efs file so that it shows the current situation. I believe there is flaw in the coding of the functions
2. drawLineRelative(x1, y1, x2, y2, Line Type, Thickness, Color, TagID);
This has worked out much better drawing the line in majority of cases where I want it. I still have some small problems but they are too esotrerci to go through here at this satge. Please see the code fragments below which has worked out for. What was critical was building the x2 parameter. x1 was easy as that is 0. However the problem is how to build x2. The only way because neither getCurrentBarIndex() or getOldestBarIndex() workews on my system is to build an index of my own.
I have also used a number of differing methods to fix the TagID with the best success using rawtime as in the examples below.
///////////////////////////////////////////////////////////
Building an Index based on Time and Chart Interval
///////////////////////////////////////////////////////////
function preMain()......
var vInterval = null;
var vIndex = 0;
function main()......
var bState = getBarState();
var vRawTime;
if (bState == BARSTATE_ALLBARS){
vInterval = getInterval();
}
vRawTime = getValue("rawtime")
if(vInterval == null)
return;
if(vInterval == "D"){
vIndex = (vRawTime/(60*60*24))
}else if(vInterval == "W"){
vIndex = (vRawTime/((60*60*24*7)))
}else if(vInterval == "M"){
vIndex = (vRawTime/((60*60*24*365.25)/12));
}else{
vIndex = (vRawTime/(vInterval*60))
}
///////////////////////////////////////////////////////////
Assigning x coordinates based on Time/Chart Interval Index
///////////////////////////////////////////////////////////
function preMain()......
var RP = null;
var RPPoint = null;
var RP1 = null;
var RPPoint1 = null;
var aRP = null;
var aRPPoint = null;
function main()......
var bState = getBarState();
var 0, o2;
if (bState == BARSTATE_ALLBARS){
aRP = new Array(2);
o = 0;
aRPPoint = new Array(2);
o2 = 0;
}
Some parameter equal to a value
RPPoint = vIndex;
RP = (current close etc...);
RPPoint1 = (aRPPoint[0]-RPPoint);
RP1 = aRP[0];
drawLineRelative(0,RP,RPPoint1,RP1, PS_SOLID, Thickness, Color, vIndex);
// Fixing RP into Array
if(o < 2) { // prime the array
aRP[o] = RP;
o++;
return;
}
if(bState == BARSTATE_NEWBAR) {
aRP.shift();
aRP.push(RP);
} else if(bState == BARSTATE_CURRENTBAR) {
aRP[1] = RP;
}
// Fixing RPPoint into Array
if(o2 < 2) { // prime the array
aRPPoint[o2] = RPPoint;
o2++;
return;
}
if(bState == BARSTATE_NEWBAR) {
aRPPoint.shift();
aRPPoint.push(RPPoint);
} else if(bState == BARSTATE_CURRENTBAR) {
aRPPoint[1] = RPPoint;
}
/////////////////////////////////////////////////
QUSETIONS
/////////////////////////////////////////////////
My questions are as follows:-
A. How do you clear a previous drawn line considering the the line TagID is XXX
B. Why do getCurrentBarIndex() or getOldestBarIndex() do not work properly.
C. Can the code I put forward be made more efficient
Comment