Buy/Sell by Prakash For ThinkOrSwim

NISSAVINIS

New member
This is a conversion to ThinkOrSwim of a Tradingview script:
https://www.tradingview.com/script/pjK8ksqR-Buy-Sell-by-Prakash-EEE/
Tradingview provides no explanation for how it works or how to use.

C0ad4Og.png
 
Last edited by a moderator:

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

@samer800 Need help in converting below trading view indicator to TOS script
https://www.tradingview.com/script/pjK8ksqR-Buy-Sell-by-Prakash-EEE/

Ruby:
//@version=4




study(title="Buy/Sell by Prakash EEE", overlay=true)

source = input(defval=close, title="Source")

quickEMA = ema(close, 9)
plot(series=quickEMA, color=color.green, linewidth=1)
per1 = input(defval=27, minval=1, title="Fast period")
mult1 = input(defval=1.6, minval=0.1, title="Fast range")
per2 = input(defval=55, minval=1, title="Slow period")
mult2 = input(defval=2, minval=0.1, title="Slow range")
smoothrng(x, t, m) =>
    wper = t * 2 - 1
    avrng = ema(abs(x - x[1]), t)
    smoothrng = ema(avrng, wper) * m
    smoothrng
smrng1 = smoothrng(source, per1, mult1)
smrng2 = smoothrng(source, per2, mult2)
smrng = (smrng1 + smrng2) / 2
rngfilt(x, r) =>
    rngfilt = x
    rngfilt := x > nz(rngfilt[1]) ? x - r < nz(rngfilt[1]) ? nz(rngfilt[1]) : x - r :
       x + r > nz(rngfilt[1]) ? nz(rngfilt[1]) : x + r
    rngfilt
filt = rngfilt(source, smrng)
upward = 0.0
upward := filt > filt[1] ? nz(upward[1]) + 1 : filt < filt[1] ? 0 : nz(upward[1])
downward = 0.0
downward := filt < filt[1] ? nz(downward[1]) + 1 : filt > filt[1] ? 0 : nz(downward[1])
hband = filt + smrng
lband = filt - smrng
longCond = bool(na)
shortCond = bool(na)
longCond := source > filt and source > source[1] and upward > 0 or source > filt and source < source[1] and upward > 0
shortCond := source < filt and source < source[1] and downward > 0 or source < filt and source > source[1] and downward > 0
CondIni = 0
CondIni := longCond ? 1 : shortCond ? -1 : CondIni[1]
long = longCond and CondIni[1] == -1
short = shortCond and CondIni[1] == 1
plotshape(long, title="BUY", text="BUY", style=shape.labelup, textcolor=color.white, size=size.auto, location=location.belowbar, color=color.green, transp=0)
plotshape(short, title="SELL", text="SELL", style=shape.labeldown, textcolor=color.white, size=size.auto, location=location.abovebar, color=color.red, transp=0)
alertcondition(long, title="BUY", message="BUY")
alertcondition(short, title="SELL", message="SELL")
anchor = input(defval = "Session", title="Anchor Period", type=input.string)
MILLIS_IN_DAY = 86400000
dwmBarTime = timeframe.isdwm ? time : time("D")
if na(dwmBarTime)
    dwmBarTime := nz(dwmBarTime[1])
var periodStart = time - time // zero
makeMondayZero(dayOfWeek) => (dayOfWeek + 5) % 7
isMidnight(t) =>
    hour(t) == 0 and minute(t) == 0
isSameDay(t1, t2) =>
    dayofmonth(t1) == dayofmonth(t2) and
  month(t1) == month(t2) and
  year(t1) == year(t2)
isOvernight() =>
    not (isMidnight(dwmBarTime) or security(syminfo.tickerid, "D", isSameDay(time, time_close), lookahead=true))
tradingDayStart(t) =>
    y = year(t)
    m = month(t)
    d = dayofmonth(t)
    timestamp(y, m, d, 0, 0)
numDaysBetween(time1, time2) =>
    y1 = year(time1)
    m1 = month(time1)
    d1 = dayofmonth(time1)
    y2 = year(time2)
    m2 = month(time2)
    d2 = dayofmonth(time2)
    diff = abs(timestamp("GMT", y1, m1, d1, 0, 0) - timestamp("GMT", y2, m2, d2, 0, 0))
    diff / MILLIS_IN_DAY
tradingDay = isOvernight() ? tradingDayStart(dwmBarTime + MILLIS_IN_DAY) : tradingDayStart(dwmBarTime)
isNewPeriod() =>
    isNew = false
    if tradingDay != nz(tradingDay[1])
        if anchor == "Session"
            isNew := na(tradingDay[1]) or tradingDay > tradingDay[1]
        if anchor == "Week"
            DAYS_IN_WEEK = 7
            isNew := makeMondayZero(dayofweek(periodStart)) + numDaysBetween(periodStart, tradingDay) >= DAYS_IN_WEEK
        if anchor == "Month"
            isNew := month(periodStart) != month(tradingDay) or year(periodStart) != year(tradingDay)
        if anchor == "Year"
            isNew := year(periodStart) != year(tradingDay)
    isNew
src = hlc3
sumSrc = float(na)
sumVol = float(na)
sumSrc := nz(sumSrc[1], 0)
sumVol := nz(sumVol[1], 0)
if isNewPeriod()
    periodStart := tradingDay
    sumSrc := 0.0
    sumVol := 0.0
GLlabel=label.new(x=bar_index,y=close,text="  \n\n\n\n\n\n      "+"Prakash\n\n  "+"    EEE" ,
     style=label.style_label_up,
     color=color.new(color.aqua,transp=100),
     textcolor=color.new(color.aqua,transp=30),
     size=size.normal)
label.delete(GLlabel[1])
if not na(src) and not na(volume)
    sumSrc := sumSrc + src * volume
    sumVol := sumVol + volume
vwapValue = sumSrc / sumVol
plot(vwapValue, title="VWAP", color=color.red, linewidth=3)

//EOS
check the below. I added some filters as well.

CSS:
# Indicator for TOS
#study(title="Buy/Sell by Prakash EEE", overlay=true)
# Converted by Sam4Cok@Samer800    - 07/2024
input filterSelect = {Default "Moving Average", "VWAP", "MA & VWAP", "Don't use Filter"};
input source = close; #(defval=close, title="Source")
input fastPeriod = 27; #(defval=27, minval=1, title="Fast period")
input slowPeriod = 55; #, minval=1, title="Slow period")
input fastMultiplier = 1.6; #(defval=1.6, minval=0.1, title="Fast range")
input slowMultiplier = 2.0; #(defval=2, minval=0.1, title="Slow range")
input showRangeFilterLine= yes;
input showVwapLine = yes;
input vwapTimeFrame = {default DAY, WEEK, MONTH};

def na = Double.NaN;
def quickEMA = ExpAverage(source, 9);
def wap = Reference vwap(timeFrame = vwapTimeFrame).price;

DefineGlobalColor("blue"   , CreateColor(33,150,243));
DefineGlobalColor("orange"  , CreateColor(255,152,0));

#smoothrng(x, t, m)
script smoothrng {
    input src  = close;
    input per  = 100;
    input mult = 3;
    def wper = per * 2 - 1;
    def srcDif = AbsValue(src - src[1]);
    def avrng = ExpAverage(srcDif, per);
    def smoothrng = ExpAverage(avrng, wper) * mult;
    plot result = smoothrng;
}
#// Range Filter
#rngfilt(x, r) =>
script rngfilt {
input src  = close;
input r  = 0;
def  rngfilt = CompoundValue(1, if !rngfilt[1] then src else
               if src > rngfilt[1] then
               if (src - r) < rngfilt[1] then rngfilt[1] else (src - r) else
               if (src + r) > rngfilt[1] then rngfilt[1] else (src + r), src);
 plot result = rngfilt;
}
def smrng1 = smoothrng(source, fastPeriod, fastMultiplier);
def smrng2 = smoothrng(source, slowPeriod, slowMultiplier);
def smrng = (smrng1 + smrng2) / 2;
def filt = rngfilt(source, smrng);

def filterUp; def filterDn;
Switch (filterSelect) {
Case "VWAP" :
    filterUp = filt > wap;
    filterDn = filt < wap;
Case "MA & VWAP" :
    filterUp = filt > quickEMA and filt > wap;
    filterDn = filt < quickEMA and filt < wap;
Case "Don't use Filter" :
    filterUp = yes;
    filterDn = yes;
Default :
    filterUp = filt > quickEMA;
    filterDn = filt < quickEMA;
}
def upward = if filt > filt[1] then upward[1] + 1 else
             if filt < filt[1] then 0 else upward[1];
def downward = if filt < filt[1] then downward[1] + 1 else
               if filt > filt[1] then 0 else downward[1];
def col = if upward > 0 then 1 else if downward > 0 then -1 else 0;
def longCond  = source > filt and source > source[1] and upward > 0 and filterUp;
def shortCond = source < filt and source < source[1] and downward > 0  and filterDn;
def CondIni = if longCond then 1 else if shortCond then -1 else CondIni[1];
def long  = longCond and CondIni[1] == -1;
def short = shortCond and CondIni[1] == 1;

plot rfLine = if showRangeFilterLine then filt else na;
plot vwapLine = if showVwapLine then wap else na;
rfLine.AssignValueColor(if col > 0 then GlobalColor("blue") else
                        if col < 0 then GlobalColor("orange") else Color.GRAY);
vwapLine.SetDefaultColor(Color.MAGENTA);

AddChartBubble(long, low, "BUY", Color.GREEN, no);
AddChartBubble(short, high, "Sell", Color.RED);



#-- END of CODE
 

check the below. I added some filters as well.

CSS:
# Indicator for TOS
#study(title="Buy/Sell by Prakash EEE", overlay=true)
# Converted by Sam4Cok@Samer800    - 07/2024
input filterSelect = {Default "Moving Average", "VWAP", "MA & VWAP", "Don't use Filter"};
input source = close; #(defval=close, title="Source")
input fastPeriod = 27; #(defval=27, minval=1, title="Fast period")
input slowPeriod = 55; #, minval=1, title="Slow period")
input fastMultiplier = 1.6; #(defval=1.6, minval=0.1, title="Fast range")
input slowMultiplier = 2.0; #(defval=2, minval=0.1, title="Slow range")
input showRangeFilterLine= yes;
input showVwapLine = yes;
input vwapTimeFrame = {default DAY, WEEK, MONTH};

def na = Double.NaN;
def quickEMA = ExpAverage(source, 9);
def wap = Reference vwap(timeFrame = vwapTimeFrame).price;

DefineGlobalColor("blue"   , CreateColor(33,150,243));
DefineGlobalColor("orange"  , CreateColor(255,152,0));

#smoothrng(x, t, m)
script smoothrng {
    input src  = close;
    input per  = 100;
    input mult = 3;
    def wper = per * 2 - 1;
    def srcDif = AbsValue(src - src[1]);
    def avrng = ExpAverage(srcDif, per);
    def smoothrng = ExpAverage(avrng, wper) * mult;
    plot result = smoothrng;
}
#// Range Filter
#rngfilt(x, r) =>
script rngfilt {
input src  = close;
input r  = 0;
def  rngfilt = CompoundValue(1, if !rngfilt[1] then src else
               if src > rngfilt[1] then
               if (src - r) < rngfilt[1] then rngfilt[1] else (src - r) else
               if (src + r) > rngfilt[1] then rngfilt[1] else (src + r), src);
 plot result = rngfilt;
}
def smrng1 = smoothrng(source, fastPeriod, fastMultiplier);
def smrng2 = smoothrng(source, slowPeriod, slowMultiplier);
def smrng = (smrng1 + smrng2) / 2;
def filt = rngfilt(source, smrng);

def filterUp; def filterDn;
Switch (filterSelect) {
Case "VWAP" :
    filterUp = filt > wap;
    filterDn = filt < wap;
Case "MA & VWAP" :
    filterUp = filt > quickEMA and filt > wap;
    filterDn = filt < quickEMA and filt < wap;
Case "Don't use Filter" :
    filterUp = yes;
    filterDn = yes;
Default :
    filterUp = filt > quickEMA;
    filterDn = filt < quickEMA;
}
def upward = if filt > filt[1] then upward[1] + 1 else
             if filt < filt[1] then 0 else upward[1];
def downward = if filt < filt[1] then downward[1] + 1 else
               if filt > filt[1] then 0 else downward[1];
def col = if upward > 0 then 1 else if downward > 0 then -1 else 0;
def longCond  = source > filt and source > source[1] and upward > 0 and filterUp;
def shortCond = source < filt and source < source[1] and downward > 0  and filterDn;
def CondIni = if longCond then 1 else if shortCond then -1 else CondIni[1];
def long  = longCond and CondIni[1] == -1;
def short = shortCond and CondIni[1] == 1;

plot rfLine = if showRangeFilterLine then filt else na;
plot vwapLine = if showVwapLine then wap else na;
rfLine.AssignValueColor(if col > 0 then GlobalColor("blue") else
                        if col < 0 then GlobalColor("orange") else Color.GRAY);
vwapLine.SetDefaultColor(Color.MAGENTA);

AddChartBubble(long, low, "BUY", Color.GREEN, no);
AddChartBubble(short, high, "Sell", Color.RED);



#-- END of CODE
@samer800 great job. a quick question do you think its possible to add color candles with the signal, meaning if is a BUY paint the candles green and if is a SELL paint the candles red, also add a input to use the signal label and arrow. thank you in advance
 
Last edited by a moderator:
@samer800 another great conversion. Thank you very much. this looks really good for intraday. specially the first hour of trading. is it too much of an ask if there is a scan for it when there is a buy bubble or a sell bubble? Thank you very much.
 
@samer800 great job. a quick question do you think its possible to add color candles with the signal, meaning if is a BUY paint the candles green and if is a SELL paint the candles red, also add a input to use the signal label and arrow. thank you in advance
is there is a scan for it when there is a buy bubble or a sell bubble?

Delete these 2 lines from the end of your script:
AddChartBubble(long, low, "BUY", Color.GREEN, no);
AddChartBubble(short, high, "Sell", Color.RED);

Append this code snippet to the end of your script:
Ruby:
input showBubbles = no ;
input showArrows = yes;
input showLabel = yes;
AddChartBubble(showBubbles and long, low, "BUY", Color.GREEN, no);
AddChartBubble(showBubbles and short, high, "Sell", Color.RED);

plot upArrow = if showArrows then long else double.NaN ;
upArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
upArrow.SetDefaultColor(color.cyan) ;
upArrow.SetLineWeight(3);

plot dnArrow = if showArrows then short else double.NaN ;
dnArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
dnArrow.SetDefaultColor(color.magenta) ;
dnArrow.SetLineWeight(3);

AddLabel(showLabel and (long or short), if long then "buy" else "sell",
                        if long then color.green else color.red);

input SignalCandles = yes ;
AssignPriceColor(if !SignalCandles then color.current else
                 if long then color.green else
                 if short then color.red else color.gray);


To create a scanner for Buy/Sell by Prakash
Follow the instructions above.
Then your scan conditions will be:
upArrow is true
or
dnArrow is true

For a tutorial on how to set up up your scan conditions in the ToS Scan Hacker:
https://usethinkscript.com/threads/how-to-use-thinkorswim-stock-hacker-scans.284/

yKFKfMO.png
 
Last edited by a moderator:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
583 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