tradecombine
Member
This Indicator was born from the discussion here:
https://usethinkscript.com/threads/highest-indicator-value-coding-help.10707/
Here's the complete code:
https://usethinkscript.com/threads/highest-indicator-value-coding-help.10707/
Here's the complete code:
Code:
# Trailing Stop based on highs or lows
# @tradecombine 4/17/22
# requested by @lishuimu88888888
# Reference: https://usethinkscript.com/threads/highest-indicator-value-coding-help.10707/
input length = 3;
input price = close;
def maHigh = highest(high, length);
def maLow = lowest(low, length);
def bp = if maHigh < maHigh[1] then maHigh else bp[1];
def sp = if maLow > maLow[1] then maLow else sp[1];
def state = {default init, short, long};
if (price > bp) {
state = state.long;
} else if (price < sp) {
state = state.short;
} else {
state = state.init;
}
plot BuyStop = if state == state.short && maHigh <= maHigh[1] then maHigh else Double.NaN;
plot SellStop = if state == state.long && maLow >= maLow[1] then maLow else Double.NaN;
BuyStop.SetDefaultColor(GetColor(0));
SellStop.SetDefaultColor(GetColor(1));
Last edited by a moderator: