BLSH for ThinkorSwim

petergluis

Active member
Buy Low Sell High Strategy for Top Market Cap Stocks from Nifty 50. Buy only after price recovery of 5% from it's 25 Days Lowest price for a small target of 5%. It confirms the trend reversal

I convert BLSH for ThinkorSwim.

https://www.tradingview.com/script/MkrCvQ22-BLSH/

Ruby:
#
#// beardcrack
#study(title="Modified DC for BLSH", shorttitle="BLSH Price Table", overlay=true)
#https://www.tradingview.com/script/MkrCvQ22-BLSH/
def length = 25;
def profit = 5;
def LOW25 = lowest(low, length);
def GTT = LOW25*1.05;
def TARGET = GTT*1.05;
plot lineGTT = GTT;
lineGTT.SetDefaultColor(GetColor(9));
plot LineLowe25 = LOW25;
LineLowe25.SetDefaultColor(GetColor(5));
plot LineTarget = TARGET;
LineTarget.SetDefaultColor(GetColor(6));
 
Last edited by a moderator:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

I add color changes to follow trend changes.
Ruby:
#// beardcrack
#study(title="Modified DC for BLSH", shorttitle="BLSH Price Table", overlay=true)
#https://www.tradingview.com/script/MkrCvQ22-BLSH/
def length = 25;
def profit = 5;
def LOW25 = lowest(low, length);
def GTT = LOW25*1.05;
def TARGET = GTT*1.05;
plot lineGTT = GTT;
lineGTT.AssignValueColor(if lineGTT> lineGTT[1] then Color.GREEN else if lineGTT <lineGTT[1] then Color.MAGENTA else color.light_gray);
lineGTT.SetLineWeight(3);
plot LineLowe25 = LOW25;
LineLowe25.AssignValueColor(if LineLowe25> LineLowe25[1] then Color.light_GREEN else if LineLowe25 <LineLowe25[1] then Color.light_red else color.yellow);
LineLowe25.SetLineWeight(3);
plot LineTarget = TARGET;
LineTarget.AssignValueColor(if LineTarget> LineTarget[1] then Color.dark_GREEN else if LineTarget<LineTarget[1] then Color.red else color.white);
LineTarget.SetLineWeight(4);
 
Last edited:
A combined study with BLSH and Double SuperTrend.
Ruby:
#https://usethinkscript.com/threads/blsh-for-thinkorswim.11013/
#https://usethinkscript.com/threads/double-supertrend-atr-for-thinkorswim.10986/
#https://www.tradingview.com/script/OsKg8IXR-Double-SuperTrend-ATR/
#// beardcrack
#study(title="Modified DC for BLSH", shorttitle="BLSH Price Table", overlay=true)
#https://www.tradingview.com/script/MkrCvQ22-BLSH/
def src = close;
def l = 6;
def std = no;
def bc = no;
def k = 1.0 / l;
def Factor = 3;
def ATR = 12;
def length = 25;
def profit = 5;
def LOW25 = lowest(low, length);
def GTT = LOW25*1.05;
def TARGET = GTT*1.05;
script nz {
    input data = 0;
    def ret_val = if IsNaN(data) then 0 else data;
    plot return = ret_val;
}
def pdm = Max((src - src[1]), 0);
def mdm = Max((src[1] - src), 0);
def pdmS = ((1 - k) * nz(pdmS[1]) + k * pdm);
def mdmS = ((1 - k) * nz(mdmS[1]) + k * mdm);
def s = pdmS + mdmS;
def pdi = pdmS / s;
def mdi = mdmS / s;
def pdiS = ((1 - k) * nz(pdiS[1]) + k * pdi);
def mdiS = ((1 - k) * nz(mdiS[1]) + k * mdi);
def d = AbsValue(pdiS - mdiS);
def s1 = pdiS + mdiS;
def iS = ((1 - k) * nz(iS[1]) + k * d / s1);
def hhv = Highest(iS, l);
def llv = Lowest(iS, l);
def d1 = hhv - llv;
def vI = (iS - llv) / d1;
def vma = (1 - k * vI) * nz(vma[1]) + k * vI * src;
plot line = vma;
line.AssignValueColor(if line> line[1] then Color.GREEN else if line <line[1] then Color.MAGENTA else color.gray);
line.SetLineWeight(4);

script nz {
input data = 0;
input data2 = 0;
def ret_val = if IsNaN(data) then data2 else data;
plot return = ret_val;
}

script MTF_ATR {
    input Length = 12;
    input TF = AggregationPeriod.HOUR;
    input averageType = AverageType.WILDERS;
    plot ATR =
        MovingAverage(
            averageType,
            TrueRange(
                high(period = TF),
                close(period = TF),
                low(period = TF)
            ),
            Length
        )
    ;
}
def Up = hl2 - (Factor * ATR(ATR));
def Dn = hl2 + (Factor * ATR(ATR));

def TUp = if close[1] > TUp[1] then Max(Up, TUp[1]) else Up;
def TDown = if close[1] < TDown[1] then Min(Dn, TDown[1]) else Dn;

def Trend = if close > TDown[1] then 1 else if close < TUp[1] then -1 else nz(Trend[1],1);

def Tsl1 = if Trend == 1 then TUp else TDown;
def Tsl2 = if Trend == 1 then TDown else TUp;

plot p1 = Tsl1;
plot p2 = Tsl2;
p1.AssignValueColor(if p1 < p2  then Color.green else Color.magenta);
p1.SetLineWeight(1);
p2.AssignValueColor(if p1 < p2  then Color.green else Color.magenta);
p2.SetLineWeight(1);

AddCloud(p1,   p2,   Color.light_RED,   Color.light_GREEN);


plot lineGTT = GTT;
lineGTT.AssignValueColor(if lineGTT> lineGTT[1] then Color.GREEN else if lineGTT <lineGTT[1] then Color.MAGENTA else color.light_gray);
lineGTT.SetLineWeight(3);
plot LineLowe25 = LOW25;
LineLowe25.AssignValueColor(if LineLowe25> LineLowe25[1] then Color.light_GREEN else if LineLowe25 <LineLowe25[1] then Color.light_red else color.yellow);
LineLowe25.SetLineWeight(3);
plot LineTarget = TARGET;
LineTarget.AssignValueColor(if LineTarget> LineTarget[1] then Color.dark_GREEN else if LineTarget<LineTarget[1] then Color.red else color.white);
LineTarget.SetLineWeight(4);
 
I combined BLSH, JNSAR-DP and Double SuperTrend into a package for ThinkorSwim.

Ruby:
# © deepphalke
#https://www.tradingview.com/script/lEuCw5DS-JNSAR-DP/
#Peter Luis conversion
# April 24, 2022
#https://usethinkscript.com/threads/blsh-for-thinkorswim.11013/
#https://usethinkscript.com/threads/double-supertrend-atr-for-thinkorswim.10986/
#https://www.tradingview.com/script/OsKg8IXR-Double-SuperTrend-ATR/
#// beardcrack
#study(title="Modified DC for BLSH", shorttitle="BLSH Price Table", overlay=true)
#https://www.tradingview.com/script/MkrCvQ22-BLSH/
#https://usethinkscript.com/threads/jnsar-dp-for-thinkorswim.11058/
def src = hl2;
input displace = 0;
def len = 6;
def w = 4;
def h = high;
def l = low;
def c = close;
def srca = close;
def la = 6;
def std = no;
def bc = no;
def k = 1.0 / la;
def Factor = 3;
def ATR = 12;
def length = 25;
def profit = 5;
def LOW25 = lowest(low, length);
def GTT = LOW25*1.05;
def TARGET = GTT*1.05;
def LinReg = Inertia(src[-displace], len);

def LinReg1 = Inertia(h, 5);
def LinReg2 = Inertia(l, 5);
def LinReg3 = Inertia(c, 5);
def avg = (LinReg1+ LinReg2 + LinReg3 + Inertia(h[1], 5)+ Inertia(l[1], 5)+ Inertia(c[1], 5)+ Inertia(h[2], 5)+ Inertia(l[2], 5)+ Inertia(c[2], 5)+ Inertia(h[3], 5)+ Inertia(l[3], 5)+ Inertia(c[3], 5)+ Inertia(h[4], 5)+ Inertia(l[4], 5)+ Inertia(c[4], 5))/15;

plot Upperband = LinReg1;
Upperband.DefineColor("UpTrend", Color.GREEN);
Upperband.DefineColor("DownTrend", Color.RED);
Upperband.SetLineWeight(1);
Upperband.SetPaintingStrategy(PaintingStrategy.LINE);
Upperband.SetStyle(Curve.FIRM);
Upperband.AssignValueColor(if Upperband > Upperband [1] then Upperband.Color("UpTrend") else Upperband.Color("DownTrend"));
plot lowerband = LinReg2;
lowerband.DefineColor("UpTrend", Color.GREEN);
lowerband.DefineColor("DownTrend", Color.RED);
lowerband.SetLineWeight(1);
lowerband.SetPaintingStrategy(PaintingStrategy.LINE);
lowerband.SetStyle(Curve.FIRM);
lowerband.AssignValueColor(if lowerband  > lowerband  [1] then lowerband.Color("UpTrend") else lowerband.Color("DownTrend"));
Plot midline = LinReg3;
midline.DefineColor("UpTrend", Color.GREEN);
midline.DefineColor("DownTrend", Color.RED);
midline.SetLineWeight(1);
midline.SetPaintingStrategy(PaintingStrategy.LINE);
midline.SetStyle(Curve.FIRM);
midline.AssignValueColor(if midline >midline [1] then midline.Color("UpTrend") else midline.Color("DownTrend"));
input fill = yes;
def nan  =  Double.NaN;
plot LineAvg = avg;
LineAvg.DefineColor("UpTrend", Color.GREEN);
LineAvg.DefineColor("DownTrend", Color.RED);
LineAvg.SetLineWeight(3);
LineAvg.SetPaintingStrategy(PaintingStrategy.LINE);
LineAvg.SetStyle(Curve.FIRM);
LineAvg.AssignValueColor(if LineAvg  > LineAvg [1] then LineAvg.Color("UpTrend") else LineAvg.Color("DownTrend"));

def a = (UpperBand > UpperBand[1] and Midline > Midline[1]);
def b = (UpperBand < UpperBand[1] and LowerBand < LowerBand[1]);
def c1 = (UpperBand > UpperBand[1] and Midline > Midline[1]);
def d = (UpperBand < UpperBand[1] and midline < midline[1]);
def e = average(close)>midline;
def f = midline<average(close);

def Chg      =   If(a, 1, If(b, -1, 0));
def Hold     =   CompoundValue(1, If(Hold[1] == Chg or Chg == 0, Hold[1], If(Chg == 1, 1, -1)), 0);
def Chg_a      =   If((c1 or e), 1, If((d or f), -1, 0));
def Hold_a     =   CompoundValue(1, If(Hold[1] == Chg or Chg == 0, Hold[1], If(Chg == 1, 1, -1)), 0);
def LBUp     =   if fill and Hold[0] == 1 then lowerBand else nan;
def UBUp     =   if fill and Hold[0] == 1 then upperband else nan;
def LBDn     =   if fill and Hold[0] == -1 then lowerband else nan;
def UBDn     =   if fill and Hold[0] == -1 then upperband else nan;
def MBUP     =   if fill and Hold[0] == 1 then midline else nan;
def MBDn     =   if fill and Hold[0] == -1 then Midline else nan;

DefineGlobalColor("Cloud Up", Color.red);
DefineGlobalColor("Cloud_Up", Color.downtick);
DefineGlobalColor("Cloud_Dn", Color.light_green);
DefineGlobalColor("Cloud Dn", Color.cyan);
AddCloud(LBUp, UBUp, GlobalColor("Cloud Up"), GlobalColor("Cloud Dn"));
AddCloud(LBDn, UBDn, GlobalColor("Cloud Dn"), GlobalColor("Cloud Up"));
AddCloud(MBUp, UBUp, GlobalColor("Cloud_Up"), GlobalColor("Cloud_Dn"));
AddCloud(MBDn, UBDn, GlobalColor("Cloud_Dn"), GlobalColor("Cloud_Up"));



script nz {
    input data = 0;
    def ret_val = if IsNaN(data) then 0 else data;
    plot return = ret_val;
}
def pdm = Max((srca - srca[1]), 0);
def mdm = Max((srca[1] - srca), 0);
def pdmS = ((1 - k) * nz(pdmS[1]) + k * pdm);
def mdmS = ((1 - k) * nz(mdmS[1]) + k * mdm);
def s = pdmS + mdmS;
def pdi = pdmS / s;
def mdi = mdmS / s;
def pdiS = ((1 - k) * nz(pdiS[1]) + k * pdi);
def mdiS = ((1 - k) * nz(mdiS[1]) + k * mdi);
def da = AbsValue(pdiS - mdiS);
def s1 = pdiS + mdiS;
def iS = ((1 - k) * nz(iS[1]) + k * da / s1);
def hhv = Highest(iS, la);
def llv = Lowest(iS, la);
def d1 = hhv - llv;
def vI = (iS - llv) / d1;
def vma = (1 - k * vI) * nz(vma[1]) + k * vI * src;
plot line = vma;
line.AssignValueColor(if line> line[1] then Color.GREEN else if line <line[1] then Color.MAGENTA else color.gray);
line.SetLineWeight(4);

script nz {
input data = 0;
input data2 = 0;
def ret_val = if IsNaN(data) then data2 else data;
plot return = ret_val;
}

script MTF_ATR {
    input Length = 12;
    input TF = AggregationPeriod.HOUR;
    input averageType = AverageType.WILDERS;
    plot ATR =
        MovingAverage(
            averageType,
            TrueRange(
                high(period = TF),
                close(period = TF),
                low(period = TF)
            ),
            Length
        )
    ;
}
def Up = hl2 - (Factor * ATR(ATR));
def Dn = hl2 + (Factor * ATR(ATR));

def TUp = if close[1] > TUp[1] then Max(Up, TUp[1]) else Up;
def TDown = if close[1] < TDown[1] then Min(Dn, TDown[1]) else Dn;

def Trend = if close > TDown[1] then 1 else if close < TUp[1] then -1 else nz(Trend[1],1);

def Tsl1 = if Trend == 1 then TUp else TDown;
def Tsl2 = if Trend == 1 then TDown else TUp;

plot p1 = Tsl1;
plot p2 = Tsl2;
p1.AssignValueColor(if p1 < p2  then Color.green else Color.magenta);
p1.SetLineWeight(1);
p2.AssignValueColor(if p1 < p2  then Color.green else Color.magenta);
p2.SetLineWeight(1);

AddCloud(p1,   p2,   Color.light_RED,   Color.light_GREEN);

plot lineGTT = GTT;
lineGTT.AssignValueColor(if lineGTT> lineGTT[1] then Color.GREEN else if lineGTT <lineGTT[1] then Color.MAGENTA else color.light_gray);
lineGTT.SetLineWeight(3);
plot LineLowe25 = LOW25;
LineLowe25.AssignValueColor(if LineLowe25> LineLowe25[1] then Color.light_GREEN else if LineLowe25 <LineLowe25[1] then Color.light_red else color.yellow);
LineLowe25.SetLineWeight(3);
plot LineTarget = TARGET;
LineTarget.AssignValueColor(if LineTarget> LineTarget[1] then Color.dark_GREEN else if LineTarget<LineTarget[1] then Color.red else color.white);
LineTarget.SetLineWeight(4);
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
385 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top