During the current bar the stochastic K/D values can cross, uncross, or re-cross. What code is required to get an object to display this changing condition during the current bar? No problem with background color changing intrabar, but objects don't seem to behave the same way; once objects appear, they don't change.
In the formula, the idea is to have an object reflect the changing condition of the K/D cross. For example, for an unclosed bar, light green or light red on a cross, and nothing when it uncrosses.
If the bar closes in a crossover condition, then the light green or light red object color changes to dark green or dark red.
I've tried it a few ways, and no problem with background color, but it's not working for objects. Thanks for any ideas.
Here's some test code:
//vFastLast and vSlowLast is for bar -1
//vFast2 and vSlow2 is for bar -2
var vLastAlert = -1;
//K crossing D to downside on current bar (bar not closed yet)
if ((vFastLast >= vSlowLast) && (vFast < vSlow)) {
drawShapeRelative(0, 5, Shape.SQUARE, "", Color.RGB(254,213,195), Shape.RELATIVETOTOP | Shape.ONTOP);
vLastAlert = 1; //to update every tick
}
//last bar closed with K crossed below D
if ((vFast2 >= vSlow2) && (vFastLast < vSlowLast)) {
drawShapeRelative(-1, 5, Shape.SQUARE, "", Color.RGB(255,0,0), Shape.RELATIVETOTOP | Shape.ONTOP);
}
//K crossing D to upside on current bar (bar not closed yet)
if ((vFastLast <= vSlowLast) && (vFast > vSlow)) {
drawShapeRelative(0, 0, Shape.SQUARE, "", Color.RGB(157,252,141), Shape.RELATIVETOBOTTOM | Shape.ONTOP);
vLastAlert = 2; //to update every tick
}
//last bar closed with K crossed above D
if ((vFast2 <= vSlow2) && (vFastLast > vSlowLast)) {
drawShapeRelative(-1, 0, Shape.SQUARE, "", Color.RGB(0,128,0), Shape.RELATIVETOBOTTOM | Shape.ONTOP);
}
In the formula, the idea is to have an object reflect the changing condition of the K/D cross. For example, for an unclosed bar, light green or light red on a cross, and nothing when it uncrosses.
If the bar closes in a crossover condition, then the light green or light red object color changes to dark green or dark red.
I've tried it a few ways, and no problem with background color, but it's not working for objects. Thanks for any ideas.
Here's some test code:
//vFastLast and vSlowLast is for bar -1
//vFast2 and vSlow2 is for bar -2
var vLastAlert = -1;
//K crossing D to downside on current bar (bar not closed yet)
if ((vFastLast >= vSlowLast) && (vFast < vSlow)) {
drawShapeRelative(0, 5, Shape.SQUARE, "", Color.RGB(254,213,195), Shape.RELATIVETOTOP | Shape.ONTOP);
vLastAlert = 1; //to update every tick
}
//last bar closed with K crossed below D
if ((vFast2 >= vSlow2) && (vFastLast < vSlowLast)) {
drawShapeRelative(-1, 5, Shape.SQUARE, "", Color.RGB(255,0,0), Shape.RELATIVETOTOP | Shape.ONTOP);
}
//K crossing D to upside on current bar (bar not closed yet)
if ((vFastLast <= vSlowLast) && (vFast > vSlow)) {
drawShapeRelative(0, 0, Shape.SQUARE, "", Color.RGB(157,252,141), Shape.RELATIVETOBOTTOM | Shape.ONTOP);
vLastAlert = 2; //to update every tick
}
//last bar closed with K crossed above D
if ((vFast2 <= vSlow2) && (vFastLast > vSlowLast)) {
drawShapeRelative(-1, 0, Shape.SQUARE, "", Color.RGB(0,128,0), Shape.RELATIVETOBOTTOM | Shape.ONTOP);
}
Comment