georgemeals
New member
So I found the code translated in thinkscript in some reddit form. However, it freaks out too much. The trailing stop is not supposed to flip this frequently. For instance, on the long side, when price takes out the lowest low from the 3 bar trail, the trailing stop calculation to flip. Now, it should look at the lowest close and go back 2 bars to the highest high. Once price takes out the highest high. The calculation should flip to the highest closes and go back 2 bars to the lowest low. In all cases inside bars are never counted.
Code:
def count;
def basso;
def alto;
def ref;
def inside = high < high[1] and low > low[1];
count = if !inside and count[1] < 4 then count[1] + 1 else 1;
if count == 1 and !inside
{
basso = low;
alto = high;
}
else if count > 1 and !inside
{
basso = if low < basso[1] then low else basso[1];
alto = if high > alto[1] then high else alto[1];
}
else
{
basso = basso[1];
alto = alto[1];
}
if close > alto[1]
{
ref = basso;
}
else if close < basso[1]
{
ref = alto;
}
else
{
ref = ref[1];
}
plot data = ref;
data.SetPaintingStrategy(PaintingStrategy.Points);
Last edited by a moderator: