Intraday Scalping Strategy For ThinkOrSwim

mikewest

Member
VIP
# This strategy counts a number of lower highs then after the last candle that price crosses back above lowest high triggers the buy signal and sell signal if the price crosses below the 9 ema or closes below the close of the last candle.
This is a work in progress to keep a clean chart for intraday trading on one minute chart so I can have multiple charts open on 1 screen and just see the labels if they red or green and select the one thats green to open on main screen. I will continue to work on it with help from this group and share my progress here. Thanks to @Svanoy for the coding help which I lack any experience in as I mainly copy and paste. If someone can change the label so it is either buy green or sell red without a black background please post it here thanks. Also Thanks to @koenigbro
Latest Version April3, 2022
http://tos.mx/8sSc848

Code:
input price = close;
input Length = 9;
input averageType = AverageType.WILDERS;

plot MA = MovingAverage(averageType, price, Length);

input ConsecutiveBarsDown = 2;
input Trigger_Line = high;

input ConsecutiveBarsUp = 2;
input Trigger_Line2 = Low;

def Condition = high < high[1];

def Condition2 = low > low[1];

def CBD = Sum(Condition, ConsecutiveBarsDown);
plot CBDP = if CBD == ConsecutiveBarsDown then CBD else Double.NaN;
CBDP.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);

def CBU = Sum(Condition, ConsecutiveBarsUp);
plot CBUP = if CBU == ConsecutiveBarsUp then CBU else Double.NaN;
CBUP.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);

def BuyLine;
if close[1] > BuyLine[1] {
BuyLine = Double.NaN;
} else if CBD == ConsecutiveBarsDown {
BuyLine = Trigger_Line;
} else {
BuyLine = BuyLine[1];
}

plot BuyLinePlot = BuyLine;
BuyLinePlot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BuyLinePlot.AssignValueColor(Color.WHITE);

def Buy = close > BuyLine;
plot BP = Buy;
BP.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
BP.AssignValueColor(Color.UPTICK);
BP.SetLineWeight(5);

def sell = close < close[2] or close crosses below MA;

def SellLine;
if close[1] < SellLine[1] {
SellLine = Double.NaN;
} else if CBU == ConsecutiveBarsUp {
SellLine = Trigger_Line2;
} else {
SellLine = SellLine[1];
}

plot SellLinePlot = SellLine;
SellLinePlot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
SellLinePlot.AssignValueColor(Color.YELLOW);

def Sell2 = close < SellLine;
plot SL = Sell2;
SL.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
SL.AssignValueColor(Color.DOWNTICK);
SL.SetLineWeight(5);

def Buy2 = close > close[2] or close crosses above MA;

AddOrder(OrderType.BUY_TO_OPEN, condition = Buy,  tradeSize = 1, tickcolor = Color.CYAN, arrowcolor = Color.BLUE, "Buy");
AddOrder(OrderType.SELL_TO_CLOSE, condition = sell,  tradeSize = 1, tickcolor = Color.DARK_ORANGE, arrowcolor = Color.RED, "Sell");

AddLabel(yes, if Buy then "BUY" else if sell then "SELL" else "Nothing",
if sell then Color.RED else if Buy then Color.GREEN else Color.BLACK);


AddOrder(OrderType.SELL_TO_OPEN, condition = Sell2, tradeSize = 1, tickcolor = Color.RED, arrowcolor = Color.PINK, “Sell”);
AddOrder(OrderType.BUY_TO_CLOSE, condition = buy2,  tradeSize = 1, tickcolor = Color.VIOLET, arrowcolor = Color.LIME, “Buy”);

AddLabel(yes, if Sell2 then “SELL” else if buy2 then “BUY” else "Nothing",
if buy2 then Color.LIME else if sell2 then Color.RED else Color.BLACK);

# Alerts

Alert(Buy, "buy to open", Alert.Bar, Sound.Chimes);
Alert(Sell, "sell to close", Alert.Bar, Sound.Bell);

Alert(Buy2, "buy to close", Alert.Bar, Sound.Chimes);
Alert(Sell2, "sell to open", Alert.Bar, Sound.Bell);

FnAQWyf.png
 
Last edited by a moderator:

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

# This strategy counts a number of lower highs then after the last candle that price crosses back above lowest high triggers the buy signal and sell signal if the price crosses below the 9 ema or closes below the close of the last candle.
This is a work in progress to keep a clean chart for intraday trading on one minute chart so I can have multiple charts open on 1 screen and just see the labels if they red or green and select the one thats green to open on main screen. I will continue to work on it with help from this group and share my progress here. Thanks to @Svanoy for the coding help which I lack any experience in as I mainly copy and paste. If someone can change the label so it is either buy green or sell red without a black background please post it here thanks.
http://tos.mx/sHUUG8C
Ruby:
#Intraday Scalping Strategy
#@Svanoy
input price = close;
input Length = 9;
input averageType = AverageType.wilders;

plot MA = MovingAverage(averageType, price, Length);

input ConsecutiveBarsDown = 3;
input Trigger_Line = high;

def Condition = high < high[1];

def CBD = Sum(Condition,ConsecutiveBarsDown);
plot CBDP = if CBD == ConsecutiveBarsDown then CBD else Double.NaN;
CBDP.setPaintingStrategy(PaintingStrategy.VALUES_BELOW);

def BuyLine;
if close[1] > BuyLine[1] {
BuyLine = Double.NaN;
} else if CBD == ConsecutiveBarsDown {
BuyLine = Trigger_Line;
} else {
BuyLine = BuyLine[1];}

plot BuyLinePlot = BuyLine;
BuyLinePlot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BuyLinePlot.AssignValueColor(Color.WHITE);

def Buy = close > BuyLine;
plot BP = Buy;
BP.SetpaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
BP.AssignValueColor(Color.UPTICK);
BP.SetLineWeight(5);

def sell = close < close[1] or close crosses below MA;

AddOrder(OrderType.BUY_TO_OPEN, condition = Buy, price = BuyLine[1], tradeSize = 100, tickcolor = Color.CYAN, arrowcolor = Color.BLUE, "Buy");
AddOrder(OrderType.SELL_TO_CLOSE, condition = Sell, price = open, tradeSize = 100, tickcolor = Color.DARK_ORANGE, arrowcolor = Color.RED, "Sell");

Addlabel(yes, if buy then "BUY" else if sell then "SELL" else "Nothing",
if sell then color.red else if buy then color.GREEN else color.black);


FnAQWyf.png
Great strategies, thank you very much for sharing with us.. i will like to know if you can add the Short version, because i see is only for long entry.. thank you in advance
 
Hello,

I added short trades and also sound alerts as well so you will hear a sound once a trade is either entered or exited according to the strategy.
The code to the entire updated strategy is below:

Code:
input price = close;
input Length = 9;
input averageType = AverageType.WILDERS;

plot MA = MovingAverage(averageType, price, Length);

input ConsecutiveBarsDown = 2;
input Trigger_Line = high;

input ConsecutiveBarsUp = 2;
input Trigger_Line2 = Low;

def Condition = high < high[1];

def Condition2 = low > low[1];

def CBD = Sum(Condition, ConsecutiveBarsDown);
plot CBDP = if CBD == ConsecutiveBarsDown then CBD else Double.NaN;
CBDP.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);

def CBU = Sum(Condition, ConsecutiveBarsUp);
plot CBUP = if CBU == ConsecutiveBarsUp then CBU else Double.NaN;
CBUP.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);

def BuyLine;
if close[1] > BuyLine[1] {
    BuyLine = Double.NaN;
} else if CBD == ConsecutiveBarsDown {
    BuyLine = Trigger_Line;
} else {
    BuyLine = BuyLine[1];
}

plot BuyLinePlot = BuyLine;
BuyLinePlot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BuyLinePlot.AssignValueColor(Color.WHITE);

def Buy = close > BuyLine;
plot BP = Buy;
BP.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
BP.AssignValueColor(Color.UPTICK);
BP.SetLineWeight(5);

def sell = close < close[2] or close crosses below MA;

def SellLine;
if close[1] < SellLine[1] {
    SellLine = Double.NaN;
} else if CBU == ConsecutiveBarsUp {
    SellLine = Trigger_Line2;
} else {
    SellLine = SellLine[1];
}

plot SellLinePlot = SellLine;
SellLinePlot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
SellLinePlot.AssignValueColor(Color.YELLOW);

def Sell2 = close < SellLine;
plot SL = Sell2;
SL.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
SL.AssignValueColor(Color.DOWNTICK);
SL.SetLineWeight(5);

def Buy2 = close > close[2] or close crosses above MA;

AddOrder(OrderType.BUY_TO_OPEN, condition = Buy,  tradeSize = 1, tickcolor = Color.CYAN, arrowcolor = Color.BLUE, "Buy");
AddOrder(OrderType.SELL_TO_CLOSE, condition = sell, tradeSize = 1, tickcolor = Color.DARK_ORANGE, arrowcolor = Color.RED, "Sell");

AddLabel(yes, if Buy then "BUY" else if sell then "SELL" else "Nothing",
if sell then Color.RED else if Buy then Color.GREEN else Color.BLACK);


AddOrder(OrderType.SELL_TO_OPEN, condition = Sell2,  tradeSize = 1, tickcolor = Color.RED, arrowcolor = Color.PINK, “Sell”);
AddOrder(OrderType.BUY_TO_CLOSE, condition = buy2,  tradeSize = 1, tickcolor = Color.VIOLET, arrowcolor = Color.LIME, “Buy”);

AddLabel(yes, if Sell2 then “SELL” else if buy2 then “BUY” else "Nothing",
if buy2 then Color.LIME else if sell2 then Color.RED else Color.BLACK);

# Alerts

Alert(Buy, "buy to open", Alert.Bar, Sound.Chimes);
Alert(Sell, "sell to close", Alert.Bar, Sound.Bell);

Alert(Buy2, "buy to close", Alert.Bar, Sound.Chimes);
Alert(Sell2, "sell to open", Alert.Bar, Sound.Bell);
 
Last edited by a moderator:
Awesome strategy. Just wondering if the " trigger_line " can use 9 EMA instead of high/low of BAR? I mean if the close price above 9 EMA then triggers buy signal ( shows trigger_ line) , as long as the price above 9 ema ,hold it. until below 9EMA,out. If so, do you know how to change the code? thanks .
 
Hello,

I added short trades and also sound alerts as well so you will hear a sound once a trade is either entered or exited according to the strategy.
The code to the entire updated strategy is below:

input price = close;
input Length = 9;
input averageType = AverageType.WILDERS;

plot MA = MovingAverage(averageType, price, Length);

input ConsecutiveBarsDown = 2;
input Trigger_Line = high;

input ConsecutiveBarsUp = 2;
input Trigger_Line2 = Low;

def Condition = high < high[1];

def Condition2 = low > low[1];

def CBD = Sum(Condition, ConsecutiveBarsDown);
plot CBDP = if CBD == ConsecutiveBarsDown then CBD else Double.NaN;
CBDP.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);

def CBU = Sum(Condition, ConsecutiveBarsUp);
plot CBUP = if CBU == ConsecutiveBarsUp then CBU else Double.NaN;
CBUP.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);

def BuyLine;
if close[1] > BuyLine[1] {
BuyLine = Double.NaN;
} else if CBD == ConsecutiveBarsDown {
BuyLine = Trigger_Line;
} else {
BuyLine = BuyLine[1];
}

plot BuyLinePlot = BuyLine;
BuyLinePlot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BuyLinePlot.AssignValueColor(Color.WHITE);

def Buy = close > BuyLine;
plot BP = Buy;
BP.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
BP.AssignValueColor(Color.UPTICK);
BP.SetLineWeight(5);

def sell = close < close[2] or close crosses below MA;

def SellLine;
if close[1] < SellLine[1] {
SellLine = Double.NaN;
} else if CBU == ConsecutiveBarsUp {
SellLine = Trigger_Line2;
} else {
SellLine = SellLine[1];
}

plot SellLinePlot = SellLine;
SellLinePlot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
SellLinePlot.AssignValueColor(Color.YELLOW);

def Sell2 = close < SellLine;
plot SL = Sell2;
SL.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
SL.AssignValueColor(Color.DOWNTICK);
SL.SetLineWeight(5);

def Buy2 = close > close[2] or close crosses above MA;

AddOrder(OrderType.BUY_TO_OPEN, condition = Buy, price = close, tradeSize = 1, tickcolor = Color.CYAN, arrowcolor = Color.BLUE, "Buy");
AddOrder(OrderType.SELL_TO_CLOSE, condition = sell, price = close, tradeSize = 1, tickcolor = Color.DARK_ORANGE, arrowcolor = Color.RED, "Sell");

AddLabel(yes, if Buy then "BUY" else if sell then "SELL" else "Nothing",
if sell then Color.RED else if Buy then Color.GREEN else Color.BLACK);


AddOrder(OrderType.SELL_TO_OPEN, condition = Sell2, price = close, tradeSize = 1, tickcolor = Color.RED, arrowcolor = Color.PINK, “Sell”);
AddOrder(OrderType.BUY_TO_CLOSE, condition = buy2, price = close, tradeSize = 1, tickcolor = Color.VIOLET, arrowcolor = Color.LIME, “Buy”);

AddLabel(yes, if Sell2 then “SELL” else if buy2 then “BUY” else "Nothing",
if buy2 then Color.LIME else if sell2 then Color.RED else Color.BLACK);

# Alerts

Alert(Buy, "buy to open", Alert.Bar, Sound.Chimes);
Alert(Sell, "sell to close", Alert.Bar, Sound.Bell);

Alert(Buy2, "buy to close", Alert.Bar, Sound.Chimes);
Alert(Sell2, "sell to open", Alert.Bar, Sound.Bell);
I don't get anything here?
The Open Shared Version didn't work either http://tos.mx/sHUUG8C - is there a problem with TOS on Weekends
The Shares function has been slow or had problems for me lately.
 
changed the label to remove the black box.
input price = close;
input Length = 9;
input averageType = AverageType.WILDERS;

plot MA = MovingAverage(averageType, price, Length);

input ConsecutiveBarsDown = 2;
input Trigger_Line = high;

input ConsecutiveBarsUp = 2;
input Trigger_Line2 = Low;

def Condition = high < high[1];

def Condition2 = low > low[1];

def CBD = Sum(Condition, ConsecutiveBarsDown);
plot CBDP = if CBD == ConsecutiveBarsDown then CBD else Double.NaN;
CBDP.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);

def CBU = Sum(Condition, ConsecutiveBarsUp);
plot CBUP = if CBU == ConsecutiveBarsUp then CBU else Double.NaN;
CBUP.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);

def BuyLine;
if close[1] > BuyLine[1] {
BuyLine = Double.NaN;
} else if CBD == ConsecutiveBarsDown {
BuyLine = Trigger_Line;
} else {
BuyLine = BuyLine[1];
}

plot BuyLinePlot = BuyLine;
BuyLinePlot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BuyLinePlot.AssignValueColor(Color.WHITE);

def Buy = close > BuyLine;
plot BP = Buy;
BP.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
BP.AssignValueColor(Color.UPTICK);
BP.SetLineWeight(5);

def sell = close < close[2] or close crosses below MA;

def SellLine;
if close[1] < SellLine[1] {
SellLine = Double.NaN;
} else if CBU == ConsecutiveBarsUp {
SellLine = Trigger_Line2;
} else {
SellLine = SellLine[1];
}

plot SellLinePlot = SellLine;
SellLinePlot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
SellLinePlot.AssignValueColor(Color.YELLOW);

def Sell2 = close < SellLine;
plot SL = Sell2;
SL.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
SL.AssignValueColor(Color.DOWNTICK);
SL.SetLineWeight(5);

def Buy2 = close > close[2] or close crosses above MA;

AddOrder(OrderType.BUY_TO_OPEN, condition = Buy, open[-1], tradeSize = 1, tickcolor = Color.CYAN, arrowcolor = Color.BLUE, "Buy");
AddOrder(OrderType.SELL_TO_CLOSE, condition = sell, open[-1], tradeSize = 1, tickcolor = Color.DARK_ORANGE, arrowcolor = Color.RED, "Sell");

AddLabel(if Sell or buy then yes else no, if Buy then "BUY1" else if sell then "SELL1" else "Nothing",
if sell then Color.RED else if Buy then Color.GREEN else Color.BLACK);


AddOrder(OrderType.SELL_TO_OPEN, condition = Sell2, open[-1], tradeSize = 1, tickcolor = Color.RED, arrowcolor = Color.PINK, “Sell”);
AddOrder(OrderType.BUY_TO_CLOSE, condition = buy2, open[-1], tradeSize = 1, tickcolor = Color.VIOLET, arrowcolor = Color.LIME, “Buy”);

AddLabel(if Sell2 or buy2 then yes else no , if Sell2 then “SELL2” else if buy2 then “BUY2” else "Nothing",
if buy2 then Color.LIME else if sell2 then Color.RED else Color.BLACK);

# Alerts

Alert(Buy, "buy to open", Alert.Bar, Sound.Chimes);
Alert(Sell, "sell to close", Alert.Bar, Sound.Bell);

Alert(Buy2, "buy to close", Alert.Bar, Sound.Chimes);
Alert(Sell2, "sell to open", Alert.Bar, Sound.Bell);
 
Last edited by a moderator:
Does this repaint?
The indicator does not repaint.
But the strategy portion of this code was not written correctly.
So favorable results were overstated. All the scripts in this thread have been edited,
You will need to copy & paste the edited version.
The strategy now reflects more realistic returns.
 
Last edited:
changed the label to remove the black box.
@samer800, I am getting these errors with this code:

Parameter already defined: arrowcolor
Expected class com.devexperts.tos.thinkscript.data.CustomColor at 67:1
Expected class com.devexperts.tos.thinkscript.data.CustomColor at 68:1
Expected class com.devexperts.tos.thinkscript.data.CustomColor at 74:1
Expected class com.devexperts.tos.thinkscript.data.CustomColor at 75:1
 
@samer800, I am getting these errors with this code:

Parameter already defined: arrowcolor
Expected class com.devexperts.tos.thinkscript.data.CustomColor at 67:1
Expected class com.devexperts.tos.thinkscript.data.CustomColor at 68:1
Expected class com.devexperts.tos.thinkscript.data.CustomColor at 74:1
Expected class com.devexperts.tos.thinkscript.data.CustomColor at 75:1
Find the fixed code here:
https://usethinkscript.com/threads/intraday-scalping-strategy-for-thinkorswim.10698/#post-99959
 
@all Also, it looks like the Moving average filter does not really work here, which is ok. I suggest take only long trades whenever the Daily chart is in an uptrend and only short trades when it is in a downtrend.
It will prevent unnecessary trades and losses and will put more odds in your favor. It is profitable either way, but it surely shows more profit when you trade with the daily bias.

Good luck.
 

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
337 Online
Create Post

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