Stochastic Distance Indicator [CC]
"Stochastic Distance Indicator [CC]" by cheatcountry, MIT. Ported to FloScript by FloSignals; modifications under MPL-2.0. Original: Stochastic Distance Indicator [CC] (v1.0), read 2026-10-12T15:42:30.243Z; source language v5.
Licence: MIT License (MIT) — full text.
Stochastic Distance Indicator [CC] by cheatcountry, ported from Pine v5. Pane indicator with 1 plot, 3 levels, bar/background colouring, alerts and 8 inputs.
// Copyright (c) 2019-present, Franklin Moormann (cheatcountry)
// Stochastic Distance Indicator [CC] script may be freely distributed under the MIT license.
// ------------------------------------------------------------------------------------------------
// Original author: cheatcountry
// Original title: Stochastic Distance Indicator [CC]
// Licence: MIT (the header above is the original notice, kept verbatim)
// Pine version: 5
// Fetched: 2026-10-12
// Ported to FloScript by FloSignals; modifications under MPL-2.0.
// Converter: @flosignals/floscript 0.1.0, strict mode, score 100/100
// ------------------------------------------------------------------------------------------------
//@floscript=1
//@version=5
indicator("Stochastic Distance Indicator [CC]", overlay=false)
requestSecurity(string _symbol, string _res, bool _repaints) =>
repIndex = _repaints ? 0 : barstate.isrealtime ? 1 : 0
resIndex = _repaints ? 0 : barstate.isrealtime ? 0 : 1
c = close[repIndex][resIndex]
var GRP1 = "General Settings"
string res = input.timeframe(title="Resolution", defval="", group=GRP1)
int lbLength = input.int(title="Lookback Length", defval=200, minval=1, maxval=1000, group=GRP1)
int length1 = input.int(title="Length 1", defval=12, minval=1, maxval=1000, group=GRP1)
int length2 = input.int(title="Length 2", defval=3, minval=1, maxval=1000, group=GRP1)
bool rep = input.bool(title="Allow Repainting?", defval=false, group=GRP1)
bool bar = input.bool(title="Allow Bar Color Change?", defval=true, group=GRP1)
int obLevel = input.int(title="ObLevel", defval=40, minval=0, maxval=100, group=GRP1)
int osLevel = input.int(title="OsLevel", defval=-40, minval=-100, maxval=0, group=GRP1)
float c = requestSecurity(syminfo.tickerid, res, rep)
distance = math.abs(c - nz(c[length1]))
hh = ta.highest(distance, lbLength)
ll = ta.lowest(distance, lbLength)
distanceSto = hh - ll != 0 ? (distance - ll) / (hh - ll) * 100 : 0
distanceD = c > nz(c[length1]) ? distanceSto : c < nz(c[length1]) ? -distanceSto : 0
sdo = ta.ema(distanceD, length2)
hline(obLevel, color=color.green)
hline(osLevel, color=color.red)
hline(0)
sig = distanceD > sdo or nz(sdo[1]) < osLevel and sdo > osLevel ? 1 : distanceD < sdo or nz(sdo[1]) > obLevel and sdo < obLevel ? -1 : 0
alertcondition(ta.crossover(sig, 1), 'Strong Buy Signal', 'Strong Bullish Change Detected')
alertcondition(ta.crossunder(sig, -1), 'Strong Sell Signal', 'Strong Bearish Change Detected')
alertcondition(ta.crossover(sig, 0), 'Buy Signal', 'Bullish Change Detected')
alertcondition(ta.crossunder(sig, 0), 'Sell Signal', 'Bearish Change Detected')
alertcondition(ta.crossover(sig, 1) or ta.crossover(sig, 0), "All Buy Signals", "Any Bullish Change Detected")
alertcondition(ta.crossunder(sig, -1) or ta.crossunder(sig, 0), "All Sell Signals", "Any Bearish Change Detected")
color sdoColor = sig > 1 ? color.green : sig > 0 ? color.lime : sig < -1 ? color.maroon : sig < 0 ? color.red : na
barcolor(bar ? sdoColor : na)
plot(sdo, "Stochastic Distance Oscillator", sdoColor, linewidth=2)
This file is under the MIT License; it is a port of the original by cheatcountry, with the original licence header kept and the changes made for FloScript noted in the file.
- v2
Library refresh 2026-10-14
- v1
Library refresh 2026-10-12
Disclaimer. Scripts are written and published by members, or ported by FloSignals from open-source originals, and are their authors' own work and opinion. FloSignals does not review them for correctness and nothing in a script is financial advice or a recommendation to buy or sell anything — read the Risk Disclaimer. Posting here is under the Community Rules; a script that is not the poster's to post can be reported as the Copyright & Takedowns page says.

Comments (0)
No comments yet. Members can leave one.