Trader XO Macro Trend For ThinkOrSwim

xxentre

New member
VIP
This script has two main functions focusing on EMAs (Exponential Moving Average) and Stochastic RSI.
I use this in conjunction with the MACD histogram and ema 200. Although sometimes I ignore the 200.

If going bullish when the MACD histogram turns green and the indicator of the Trade XO has a green arrow and is above 200 ema then take the trade. The opposite for bearish.

Screenshot 2023-12-21 at 2.29.08 PM.png

[@btc_charlie] Trader XO Macro Trend Scanner
https://www.tradingview.com/v/Q95qqFgC/
Can someone convert this Tradingview code to ToS and make a scanner for it:
 
Last edited by a moderator:

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

[@btc_charlie] Trader XO Macro Trend Scanner
https://www.tradingview.com/v/Q95qqFgC/
Can someone convert this Tradingview code to ToS and make a scanner for it:
I use this in conjunction with the MACD histogram only and ema 200. Although sometimes I ignore the 200
If going bullish when the MACD histogram turns green and the indicator of the Trade XO has a green arrow and is above 200 ema then take the trade. The opposite for bearish.
This script has two main functions focusing on EMAs (Exponential Moving Average) and Stochastic RSI.
View attachment 20486


Code:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © btc_charlie / @TheParagonGrp

//@version=5
indicator('[@btc_charlie] Trader XO Macro Trend Scanner', overlay=true)

// Variables
var ok = 0
var countBuy = 0
var countSell = 0
src = input(close, title='OHLC Type')
i_fastEMA = input(12, title='Fast EMA')
i_slowEMA = input(25, title='Slow EMA')
i_defEMA = input(25, title='Consolidated EMA')

// Allow the option to show single or double EMA
i_bothEMAs = input(title='Show Both EMAs', defval=true)

// Define EMAs
v_fastEMA = ta.ema(src, i_fastEMA)
v_slowEMA = ta.ema(src, i_slowEMA)
v_biasEMA = ta.ema(src, i_defEMA)

// Color the EMAs
emaColor = v_fastEMA > v_slowEMA ? color.green : v_fastEMA < v_slowEMA ? color.red : #FF530D

// Plot EMAs
plot(i_bothEMAs ? na : v_biasEMA, color=emaColor, linewidth=3, title='Consolidated EMA')
plot(i_bothEMAs ? v_fastEMA : na, title='Fast EMA', color=emaColor)
plot(i_bothEMAs ? v_slowEMA : na, title='Slow EMA', color=emaColor)

// Colour the bars
buy = v_fastEMA > v_slowEMA
sell = v_fastEMA < v_slowEMA

if buy
    countBuy += 1
    countBuy

if buy
    countSell := 0
    countSell

if sell
    countSell += 1
    countSell

if sell
    countBuy := 0
    countBuy

buysignal = countBuy < 2 and countBuy > 0 and countSell < 1 and buy and not buy[1]
sellsignal = countSell > 0 and countSell < 2 and countBuy < 1 and sell and not sell[1]

barcolor(buysignal ? color.green : na)
barcolor(sellsignal ? color.red : na)

// Plot Bull/Bear

plotshape(buysignal, title='Bull', text='Bull', style=shape.triangleup, location=location.belowbar, color=color.new(color.green, 0), textcolor=color.new(color.black, 0), size=size.tiny)
plotshape(sellsignal, title='Bear', text='Bear', style=shape.triangledown, location=location.abovebar, color=color.new(color.red, 0), textcolor=color.new(color.black, 0), size=size.tiny)

bull = countBuy > 1
bear = countSell > 1

barcolor(bull ? color.green : na)
barcolor(bear ? color.red : na)

// Set Alerts

alertcondition(ta.crossover(v_fastEMA, v_slowEMA), title='Bullish EMA Cross', message='Bullish EMA crossover')
alertcondition(ta.crossunder(v_fastEMA, v_slowEMA), title='Bearish EMA Cross', message='Bearish EMA Crossover')

// Stoch RSI code

smoothK = input.int(3, 'K', minval=1)
smoothD = input.int(3, 'D', minval=1)
lengthRSI = input.int(14, 'RSI Length', minval=1)
lengthStoch = input.int(14, 'Stochastic Length', minval=1)

rsi1 = ta.rsi(src, lengthRSI)
k = ta.sma(ta.stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
d = ta.sma(k, smoothD)

bandno0 = input.int(80, minval=1, title='Upper Band', group='Bands (change this instead of length in Style for Stoch RSI colour to work properly)')
bandno2 = input.int(50, minval=1, title='Middle Band', group='Bands (change this instead of length in Style for Stoch RSI colour to work properly)')
bandno1 = input.int(20, minval=1, title='Lower Band', group='Bands (change this instead of length in Style for Stoch RSI colour to work properly)')

// Alerts

crossoverAlertBgColourMidOnOff = input.bool(title='Crossover Alert Background Colour (Middle Level) [ON/OFF]', group='Crossover Alerts', defval=false)
crossoverAlertBgColourOBOSOnOff = input.bool(title='Crossover Alert Background Colour (OB/OS Level) [ON/OFF]', group='Crossover Alerts', defval=false)

crossoverAlertBgColourGreaterThanOnOff = input.bool(title='Crossover Alert >input [ON/OFF]', group='Crossover Alerts', defval=false)
crossoverAlertBgColourLessThanOnOff = input.bool(title='Crossover Alert <input [ON/OFF]', group='Crossover Alerts', defval=false)

maTypeChoice = input.string('EMA', title='MA Type', group='Moving Average', options=['EMA', 'WMA', 'SMA', 'None'])
maSrc = input.source(close, title='MA Source', group='Moving Average')
maLen = input.int(200, minval=1, title='MA Length', group='Moving Average')

maValue = if maTypeChoice == 'EMA'
    ta.ema(maSrc, maLen)
else if maTypeChoice == 'WMA'
    ta.wma(maSrc, maLen)
else if maTypeChoice == 'SMA'
    ta.sma(maSrc, maLen)
else
    0

crossupCHECK = maTypeChoice == 'None' or open > maValue and maTypeChoice != 'None'
crossdownCHECK = maTypeChoice == 'None' or open < maValue and maTypeChoice != 'None'

crossupalert = crossupCHECK and ta.crossover(k, d) and (k < bandno2 or d < bandno2)
crossdownalert = crossdownCHECK and ta.crossunder(k, d) and (k > bandno2 or d > bandno2)
crossupOSalert = crossupCHECK and ta.crossover(k, d) and (k < bandno1 or d < bandno1)
crossdownOBalert = crossdownCHECK and ta.crossunder(k, d) and (k > bandno0 or d > bandno0)

aboveBandalert = ta.crossunder(k, bandno0)
belowBandalert = ta.crossover(k, bandno1)

bgcolor(color=crossupalert and crossoverAlertBgColourMidOnOff ? #4CAF50 : crossdownalert and crossoverAlertBgColourMidOnOff ? #FF0000 : na, title='Crossover Alert Background Colour (Middle Level)', transp=70)
bgcolor(color=crossupOSalert and crossoverAlertBgColourOBOSOnOff ? #fbc02d : crossdownOBalert and crossoverAlertBgColourOBOSOnOff ? #000000 : na, title='Crossover Alert Background Colour (OB/OS Level)', transp=70)

bgcolor(color=aboveBandalert and crossoverAlertBgColourGreaterThanOnOff ? #ff0014 : crossdownalert and crossoverAlertBgColourMidOnOff ? #FF0000 : na, title='Crossover Alert - K > Upper level', transp=70)
bgcolor(color=belowBandalert and crossoverAlertBgColourLessThanOnOff ? #4CAF50 : crossdownalert and crossoverAlertBgColourMidOnOff ? #FF0000 : na, title='Crossover Alert - K < Lower level', transp=70)

alertcondition(crossupalert or crossdownalert, title='Stoch RSI Crossover', message='STOCH RSI CROSSOVER')
This plots the buy/sell signal on the upper charts

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 a
#// © btc_charlie / @TheParagonGrp
#indicator('[@btc_charlie] Trader XO Macro Trend Scanner', overlay=true)
# -- Converted by Sam4Cok@Samer800    - 01/2024
input highlightBackground = yes;
input src = close; #, title='OHLC Type')
input movAvgType = AverageType.EXPONENTIAL;
input fastLength = 12;#, title='Fast EMA')
input slowLength = 25;#, title='Slow EMA')
input showBothMovAvg = yes;#(title='Show Both EMAs', defval=true)
input ConsolidatedLength = 25;#, title='Consolidated EMA')


def na = Double.NaN;

#// Define EMAs
def v_fastEMA = MovingAverage(movAvgType, src, fastLength);
def v_slowEMA = MovingAverage(movAvgType, src, slowLength);
def v_biasEMA = MovingAverage(movAvgType, src, ConsolidatedLength);

#// Color the EMAs
def emaColor = if v_fastEMA > v_slowEMA then  1 else
               if v_fastEMA < v_slowEMA then -1 else 0;

#// Plot EMAs
plot ConsEMA = if showBothMovAvg then na else v_biasEMA; # 'Consolidated EMA'
plot fastLine = if showBothMovAvg then v_fastEMA else na;#, title='Fast EMA', color=emaColor)
plot slowLine = if showBothMovAvg then v_slowEMA else na;#, title='Slow EMA', color=emaColor)
ConsEMA.SetLineWeight(2);
ConsEMA.AssignValueColor(if emaColor > 0 then Color.GREEN else
                         if emaColor < 0 then Color.RED else Color.GRAY);
fastLine.AssignValueColor(if emaColor > 0 then Color.GREEN else
                         if emaColor < 0 then Color.RED else Color.GRAY);
slowLine.AssignValueColor(if emaColor > 0 then Color.GREEN else
                         if emaColor < 0 then Color.RED else Color.GRAY);
#// Colour the bars
def buy = v_fastEMA > v_slowEMA;
def sell = v_fastEMA < v_slowEMA;

#// Variables
def countBuy;
def countSell;

if buy {
    countBuy  = countBuy[1] + 1;
    countSell = 0;
 } else if sell {
    countSell = countSell[1] + 1;
    countBuy  = 0;
    } else {
    countBuy = countBuy[1];
    countSell = countSell[1];
}

def buysignal = countBuy < 2 and countBuy > 0 and countSell < 1 and buy and !buy[1];
def sellsignal = countSell > 0 and countSell < 2 and countBuy < 1 and sell and !sell[1];

#// Plot Bull/Bear

AddChartBubble(buysignal, low, "Bull", color.green, no);
AddChartBubble(sellsignal, high, "Bear", color.red);

def bull = countBuy > 1 and highlightBackground;
def bear = countSell > 1 and highlightBackground;
def pos = Double.POSITIVE_INFINITY;
def neg = Double.NEGATIVE_INFINITY;

AddCloud(if bull then pos else na, neg, Color.DARK_GREEN);
AddCloud(if bear then pos else na, neg, Color.DARK_RED);
 
Last edited by a moderator:
check the below. scan for buy/sell signal

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 a
#// © btc_charlie / @TheParagonGrp
#indicator('[@btc_charlie] Trader XO Macro Trend Scanner', overlay=true)
# -- Converted by Sam4Cok@Samer800    - 01/2024
input highlightBackground = yes;
input src = close; #, title='OHLC Type')
input movAvgType = AverageType.EXPONENTIAL;
input fastLength = 12;#, title='Fast EMA')
input slowLength = 25;#, title='Slow EMA')
input showBothMovAvg = yes;#(title='Show Both EMAs', defval=true)
input ConsolidatedLength = 25;#, title='Consolidated EMA')


def na = Double.NaN;

#// Define EMAs
def v_fastEMA = MovingAverage(movAvgType, src, fastLength);
def v_slowEMA = MovingAverage(movAvgType, src, slowLength);
def v_biasEMA = MovingAverage(movAvgType, src, ConsolidatedLength);

#// Color the EMAs
def emaColor = if v_fastEMA > v_slowEMA then  1 else
               if v_fastEMA < v_slowEMA then -1 else 0;

#// Plot EMAs
plot ConsEMA = if showBothMovAvg then na else v_biasEMA; # 'Consolidated EMA'
plot fastLine = if showBothMovAvg then v_fastEMA else na;#, title='Fast EMA', color=emaColor)
plot slowLine = if showBothMovAvg then v_slowEMA else na;#, title='Slow EMA', color=emaColor)
ConsEMA.SetLineWeight(2);
ConsEMA.AssignValueColor(if emaColor > 0 then Color.GREEN else
                         if emaColor < 0 then Color.RED else Color.GRAY);
fastLine.AssignValueColor(if emaColor > 0 then Color.GREEN else
                         if emaColor < 0 then Color.RED else Color.GRAY);
slowLine.AssignValueColor(if emaColor > 0 then Color.GREEN else
                         if emaColor < 0 then Color.RED else Color.GRAY);
#// Colour the bars
def buy = v_fastEMA > v_slowEMA;
def sell = v_fastEMA < v_slowEMA;

#// Variables
def countBuy;
def countSell;

if buy {
    countBuy  = countBuy[1] + 1;
    countSell = 0;
 } else if sell {
    countSell = countSell[1] + 1;
    countBuy  = 0;
    } else {
    countBuy = countBuy[1];
    countSell = countSell[1];
}

def buysignal = countBuy < 2 and countBuy > 0 and countSell < 1 and buy and !buy[1];
def sellsignal = countSell > 0 and countSell < 2 and countBuy < 1 and sell and !sell[1];

#// Plot Bull/Bear

AddChartBubble(buysignal, low, "Bull", color.green, no);
AddChartBubble(sellsignal, high, "Bear", color.red);

def bull = countBuy > 1 and highlightBackground;
def bear = countSell > 1 and highlightBackground;
def pos = Double.POSITIVE_INFINITY;
def neg = Double.NEGATIVE_INFINITY;

AddCloud(if bull then pos else na, neg, Color.DARK_GREEN);
AddCloud(if bear then pos else na, neg, Color.DARK_RED);
Aren't we missing the Stoch RSI though? Just wondering...
 
Last edited by a moderator:
Aren't we missing the Stoch RSI though? Just wondering...
The Tradingview OP states:
Stochastic RSI is a separate indicator that can be added
The StochRSI is a built-in ToS indicator
https://tlc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/R-S/StochRSI
you can add it to your chart. Review the interaction. Come back and convey what value it added to your trading (provide an annotated image for a visual of your discussion).
 
Last edited:
The Tradingview OP states:

The StochRSI is a built-in ToS indicator
https://tlc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/R-S/StochRSI
you can add it to your chart. Review the interaction. Come back and convey what value it added to your trading (provide an annotated image for a visual of your discussion).
Based on your experience, we can then merge the two of them for you.
I apologize; didn't know that its a built-in indicator. Thanks.
 
check the below. scan for buy/sell signal

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 a
#// © btc_charlie / @TheParagonGrp
#indicator('[@btc_charlie] Trader XO Macro Trend Scanner', overlay=true)
# -- Converted by Sam4Cok@Samer800    - 01/2024
input highlightBackground = yes;
input src = close; #, title='OHLC Type')
input movAvgType = AverageType.EXPONENTIAL;
input fastLength = 12;#, title='Fast EMA')
input slowLength = 25;#, title='Slow EMA')
input showBothMovAvg = yes;#(title='Show Both EMAs', defval=true)
input ConsolidatedLength = 25;#, title='Consolidated EMA')


def na = Double.NaN;

#// Define EMAs
def v_fastEMA = MovingAverage(movAvgType, src, fastLength);
def v_slowEMA = MovingAverage(movAvgType, src, slowLength);
def v_biasEMA = MovingAverage(movAvgType, src, ConsolidatedLength);

#// Color the EMAs
def emaColor = if v_fastEMA > v_slowEMA then  1 else
               if v_fastEMA < v_slowEMA then -1 else 0;

#// Plot EMAs
plot ConsEMA = if showBothMovAvg then na else v_biasEMA; # 'Consolidated EMA'
plot fastLine = if showBothMovAvg then v_fastEMA else na;#, title='Fast EMA', color=emaColor)
plot slowLine = if showBothMovAvg then v_slowEMA else na;#, title='Slow EMA', color=emaColor)
ConsEMA.SetLineWeight(2);
ConsEMA.AssignValueColor(if emaColor > 0 then Color.GREEN else
                         if emaColor < 0 then Color.RED else Color.GRAY);
fastLine.AssignValueColor(if emaColor > 0 then Color.GREEN else
                         if emaColor < 0 then Color.RED else Color.GRAY);
slowLine.AssignValueColor(if emaColor > 0 then Color.GREEN else
                         if emaColor < 0 then Color.RED else Color.GRAY);
#// Colour the bars
def buy = v_fastEMA > v_slowEMA;
def sell = v_fastEMA < v_slowEMA;

#// Variables
def countBuy;
def countSell;

if buy {
    countBuy  = countBuy[1] + 1;
    countSell = 0;
 } else if sell {
    countSell = countSell[1] + 1;
    countBuy  = 0;
    } else {
    countBuy = countBuy[1];
    countSell = countSell[1];
}

def buysignal = countBuy < 2 and countBuy > 0 and countSell < 1 and buy and !buy[1];
def sellsignal = countSell > 0 and countSell < 2 and countBuy < 1 and sell and !sell[1];

#// Plot Bull/Bear

AddChartBubble(buysignal, low, "Bull", color.green, no);
AddChartBubble(sellsignal, high, "Bear", color.red);

def bull = countBuy > 1 and highlightBackground;
def bear = countSell > 1 and highlightBackground;
def pos = Double.POSITIVE_INFINITY;
def neg = Double.NEGATIVE_INFINITY;

AddCloud(if bull then pos else na, neg, Color.DARK_GREEN);
AddCloud(if bear then pos else na, neg, Color.DARK_RED);
@samer800 is it possible to convert this script for MTF for the colored background?
 
@samer800 is it possible to convert this script for MTF for the colored background?
check the below:

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 a
#// © btc_charlie / @TheParagonGrp
#indicator('[@btc_charlie] Trader XO Macro Trend Scanner', overlay=true)
# -- Converted by Sam4Cok@Samer800    - 01/2024
# updated MTF option by Sam4Cok@Samer800    - 01/2024
input highlightBackground = yes;
input timeframe = {Default "Chart", "Custom"};
input customTimeframe = AggregationPeriod.FIFTEEN_MIN;
input source = FundamentalType.CLOSE; #, title='OHLC Type')
input movAvgType = AverageType.EXPONENTIAL;
input fastLength = 12;#, title='Fast EMA')
input slowLength = 25;#, title='Slow EMA')
input showBothMovAvg = yes;#(title='Show Both EMAs', defval=true)
input ConsolidatedLength = 25;#, title='Consolidated EMA')

def na = Double.NaN;
def chart = timeframe==timeframe."Chart";
def srcHtf = Fundamental(FundamentalType = source, Period = customTimeframe);
def srcTf  = Fundamental(FundamentalType = source);
def src;
Switch (timeframe) {
Case "Custom": src = srcHtf;
Default :  src = srcTf;
}
#// Define EMAs
def v_fastEMA = MovingAverage(movAvgType, src, fastLength);
def v_slowEMA = MovingAverage(movAvgType, src, slowLength);
def v_biasEMA = MovingAverage(movAvgType, src, ConsolidatedLength);

#// Color the EMAs
def emaColor = if v_fastEMA > v_slowEMA then  1 else
               if v_fastEMA < v_slowEMA then -1 else 0;

#// Plot EMAs
plot ConsEMA = if showBothMovAvg then na else v_biasEMA; # 'Consolidated EMA'
plot fastLine = if showBothMovAvg then v_fastEMA else na;#, title='Fast EMA', color=emaColor)
plot slowLine = if showBothMovAvg then v_slowEMA else na;#, title='Slow EMA', color=emaColor)
ConsEMA.SetLineWeight(2);
ConsEMA.AssignValueColor(if emaColor > 0 then Color.GREEN else
                         if emaColor < 0 then Color.RED else Color.GRAY);
fastLine.AssignValueColor(if emaColor > 0 then Color.GREEN else
                         if emaColor < 0 then Color.RED else Color.GRAY);
slowLine.AssignValueColor(if emaColor > 0 then Color.GREEN else
                         if emaColor < 0 then Color.RED else Color.GRAY);
#// Colour the bars
def buy = v_fastEMA > v_slowEMA;
def sell = v_fastEMA < v_slowEMA;

#// Variables
def countBuy;
def countSell;

if buy {
    countBuy  = countBuy[1] + 1;
    countSell = 0;
 } else if sell {
    countSell = countSell[1] + 1;
    countBuy  = 0;
    } else {
    countBuy = countBuy[1];
    countSell = countSell[1];
}

def buysignal = countBuy < 2 and countBuy > 0 and countSell < 1 and buy and !buy[1];
def sellsignal = countSell > 0 and countSell < 2 and countBuy < 1 and sell and !sell[1];

#// Plot Bull/Bear

AddChartBubble(buysignal, low, "Bull", color.green, no);
AddChartBubble(sellsignal, high, "Bear", color.red);

def bull = countBuy > 1 and highlightBackground;
def bear = countSell > 1 and highlightBackground;
def pos = Double.POSITIVE_INFINITY;
def neg = Double.NEGATIVE_INFINITY;

AddCloud(if bull then pos else na, neg, Color.DARK_GREEN);
AddCloud(if bear then pos else na, neg, Color.DARK_RED);

#-- ENd of CODE
 
check the below. scan for buy/sell signal

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 a
#// © btc_charlie / @TheParagonGrp
#indicator('[@btc_charlie] Trader XO Macro Trend Scanner', overlay=true)
# -- Converted by Sam4Cok@Samer800    - 01/2024
input highlightBackground = yes;
input src = close; #, title='OHLC Type')
input movAvgType = AverageType.EXPONENTIAL;
input fastLength = 12;#, title='Fast EMA')
input slowLength = 25;#, title='Slow EMA')
input showBothMovAvg = yes;#(title='Show Both EMAs', defval=true)
input ConsolidatedLength = 25;#, title='Consolidated EMA')


def na = Double.NaN;

#// Define EMAs
def v_fastEMA = MovingAverage(movAvgType, src, fastLength);
def v_slowEMA = MovingAverage(movAvgType, src, slowLength);
def v_biasEMA = MovingAverage(movAvgType, src, ConsolidatedLength);

#// Color the EMAs
def emaColor = if v_fastEMA > v_slowEMA then  1 else
               if v_fastEMA < v_slowEMA then -1 else 0;

#// Plot EMAs
plot ConsEMA = if showBothMovAvg then na else v_biasEMA; # 'Consolidated EMA'
plot fastLine = if showBothMovAvg then v_fastEMA else na;#, title='Fast EMA', color=emaColor)
plot slowLine = if showBothMovAvg then v_slowEMA else na;#, title='Slow EMA', color=emaColor)
ConsEMA.SetLineWeight(2);
ConsEMA.AssignValueColor(if emaColor > 0 then Color.GREEN else
                         if emaColor < 0 then Color.RED else Color.GRAY);
fastLine.AssignValueColor(if emaColor > 0 then Color.GREEN else
                         if emaColor < 0 then Color.RED else Color.GRAY);
slowLine.AssignValueColor(if emaColor > 0 then Color.GREEN else
                         if emaColor < 0 then Color.RED else Color.GRAY);
#// Colour the bars
def buy = v_fastEMA > v_slowEMA;
def sell = v_fastEMA < v_slowEMA;

#// Variables
def countBuy;
def countSell;

if buy {
    countBuy  = countBuy[1] + 1;
    countSell = 0;
 } else if sell {
    countSell = countSell[1] + 1;
    countBuy  = 0;
    } else {
    countBuy = countBuy[1];
    countSell = countSell[1];
}

def buysignal = countBuy < 2 and countBuy > 0 and countSell < 1 and buy and !buy[1];
def sellsignal = countSell > 0 and countSell < 2 and countBuy < 1 and sell and !sell[1];

#// Plot Bull/Bear

AddChartBubble(buysignal, low, "Bull", color.green, no);
AddChartBubble(sellsignal, high, "Bear", color.red);

def bull = countBuy > 1 and highlightBackground;
def bear = countSell > 1 and highlightBackground;
def pos = Double.POSITIVE_INFINITY;
def neg = Double.NEGATIVE_INFINITY;

AddCloud(if bull then pos else na, neg, Color.DARK_GREEN);
AddCloud(if bear then pos else na, neg, Color.DARK_RED);
Cannot get the scan to work. The chart looks great, Thank you

check the below:

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 a
#// © btc_charlie / @TheParagonGrp
#indicator('[@btc_charlie] Trader XO Macro Trend Scanner', overlay=true)
# -- Converted by Sam4Cok@Samer800    - 01/2024
# updated MTF option by Sam4Cok@Samer800    - 01/2024
input highlightBackground = yes;
input timeframe = {Default "Chart", "Custom"};
input customTimeframe = AggregationPeriod.FIFTEEN_MIN;
input source = FundamentalType.CLOSE; #, title='OHLC Type')
input movAvgType = AverageType.EXPONENTIAL;
input fastLength = 12;#, title='Fast EMA')
input slowLength = 25;#, title='Slow EMA')
input showBothMovAvg = yes;#(title='Show Both EMAs', defval=true)
input ConsolidatedLength = 25;#, title='Consolidated EMA')

def na = Double.NaN;
def chart = timeframe==timeframe."Chart";
def srcHtf = Fundamental(FundamentalType = source, Period = customTimeframe);
def srcTf  = Fundamental(FundamentalType = source);
def src;
Switch (timeframe) {
Case "Custom": src = srcHtf;
Default :  src = srcTf;
}
#// Define EMAs
def v_fastEMA = MovingAverage(movAvgType, src, fastLength);
def v_slowEMA = MovingAverage(movAvgType, src, slowLength);
def v_biasEMA = MovingAverage(movAvgType, src, ConsolidatedLength);

#// Color the EMAs
def emaColor = if v_fastEMA > v_slowEMA then  1 else
               if v_fastEMA < v_slowEMA then -1 else 0;

#// Plot EMAs
plot ConsEMA = if showBothMovAvg then na else v_biasEMA; # 'Consolidated EMA'
plot fastLine = if showBothMovAvg then v_fastEMA else na;#, title='Fast EMA', color=emaColor)
plot slowLine = if showBothMovAvg then v_slowEMA else na;#, title='Slow EMA', color=emaColor)
ConsEMA.SetLineWeight(2);
ConsEMA.AssignValueColor(if emaColor > 0 then Color.GREEN else
                         if emaColor < 0 then Color.RED else Color.GRAY);
fastLine.AssignValueColor(if emaColor > 0 then Color.GREEN else
                         if emaColor < 0 then Color.RED else Color.GRAY);
slowLine.AssignValueColor(if emaColor > 0 then Color.GREEN else
                         if emaColor < 0 then Color.RED else Color.GRAY);
#// Colour the bars
def buy = v_fastEMA > v_slowEMA;
def sell = v_fastEMA < v_slowEMA;

#// Variables
def countBuy;
def countSell;

if buy {
    countBuy  = countBuy[1] + 1;
    countSell = 0;
 } else if sell {
    countSell = countSell[1] + 1;
    countBuy  = 0;
    } else {
    countBuy = countBuy[1];
    countSell = countSell[1];
}

def buysignal = countBuy < 2 and countBuy > 0 and countSell < 1 and buy and !buy[1];
def sellsignal = countSell > 0 and countSell < 2 and countBuy < 1 and sell and !sell[1];

#// Plot Bull/Bear

AddChartBubble(buysignal, low, "Bull", color.green, no);
AddChartBubble(sellsignal, high, "Bear", color.red);

def bull = countBuy > 1 and highlightBackground;
def bear = countSell > 1 and highlightBackground;
def pos = Double.POSITIVE_INFINITY;
def neg = Double.NEGATIVE_INFINITY;

AddCloud(if bull then pos else na, neg, Color.DARK_GREEN);
AddCloud(if bear then pos else na, neg, Color.DARK_RED);

#-- ENd of CODE
When I paste this into a scan it states "Exactly one plot expected"
 
Last edited by a moderator:
Cannot get the scan to work. The chart looks great, Thank you

When I paste this into a scan it states "Exactly one plot expected"

Generally, the "exactly one plot expected" is seen when an attempt is made to cut&paste an entire chart study into the scan hacker or watchlist or one of the other ToS widgets.

You can create your own scan with the following instructions:
https://usethinkscript.com/threads/how-to-use-thinkorswim-stock-hacker-scans.284/.

or
You can import this copy of scanner:
shared scan link: http://tos.mx/qy1OXSM Click here for --> Easiest way to load shared links

FYI: If you were trying to scan the MTF version of this thread. The answer is NO.
MTF scripts cannot be used in the scan hacker.

Trader XO Macro Trend SCAN ONLY
bf5KBId.png

Ruby:
# XO Macro Trend Scanner
input movAvgType = AverageType.EXPONENTIAL;
input fastLength = 12;#, title='Fast EMA')
input slowLength = 25;#, title='Slow EMA')

def v_fastEMA = MovingAverage(movAvgType, src, fastLength);
def v_slowEMA = MovingAverage(movAvgType, src, slowLength);

plot buy = v_fastEMA > v_slowEMA;
#plot sell = v_fastEMA < v_slowEMA;

defaults to finding buys.
To scan for sell, change this:
plot buy = v_fastEMA > v_slowEMA;
#plot sell = v_fastEMA < v_slowEMA;
To this:
#plot buy = v_fastEMA > v_slowEMA;
plot sell = v_fastEMA < v_slowEMA;
@xxentre
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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