Scalper Buys and Sells

Here’s my incarnation of John Carter’s Scalper Buys and Sells. The methodology is a close approximation of the one described in his book Mastering the Trade. The book is highly recommended. Note the squares are not real-time but will show up once the third bar has confirmed a reversal. (Note: The first posting of this code had a line missing.)

Scalper Buys and Sells

Scalper Buys and Sells

# SCALPERBUYSELL
# http://www.thinkscripter.com
# thinkscripter@gmail.com
# Last Update 04 FEB 2009

def triggerSell = if(if(close[-1] < close,1,0) and (close[-2] < close[-1] or close[-3] <close[-1]),1,0);
def triggerBuy = if(if(close[-1] > close,1,0) and (close[-2] > close[-1] or close[-3] > close[-1]),1,0);

rec buySellSwitch = if(triggerSell, 1, if(triggerBuy, 0, buySellSwitch[1]));

def thirdBarClosed = if(isNan(close[-3]),0,1);

plot SBS = if(triggerSell and thirdBarClosed and !buySellSwitch[1], high, if(triggerBuy and thirdBarClosed and buySellSwitch[1], low, double.nan));
SBS.setStyle(curve.POINTS);
SBS.setPaintingStrategy(paintingStrategy.LINE_VS_SQUARES);
SBS.setLineWeight(2);
SBS.setDefaultColor(color.white);
This entry was posted in Indicator and tagged , , . Bookmark the permalink.

25 Responses to Scalper Buys and Sells

  1. Walstib says:

    This is a very interesting indicator. Realtime would of course be excellent, but that would be impossible.

    What happens if you use 2 bars instead of 3?

    Could you post the code for that so I could do some testing?

    Thanks for all your work!

  2. Walstib says:

    Thanks for the mail. I let you know what i see.

    One question I have, which might add some clarity to this chart, is when the signal shows.

    Lets say I’m using a “day” candlestick chart. On Monday night I look at the chart and I see that the stock had been trending down, yet today, Monday, the day started normal then by mid day it was far below the lower BB. By the end of the day it was back up again.

    For the next 4 days, the stock makes “normal” gains each day.

    Which day of the week, and at what time during the day would the signal appear below the Monday candle showing a buy signal?

    Thanks.

  3. Greg says:

    I have an idea to make this script a little more useful from a timing perspective. Is there a way to make look at multiple time frames, for example, evaluate a 1 minute bar time, a 5 minute bar time, and 15 minute bar time to produce a combined signal?

    For example, once 3 1 minute bars have passed to create a signal, you would get a weak “buy”, or sell, depending on which way you’re going, then if after 3 5 minute bars if the same trend has continued, it would “add” to the signal by making stronger, then the same would hold true for the 15 minute bar. The goal would be to have an indicator that travels along the price bars and changes color depending on the combined 1, 5, and 15 minute bars.

    Does this make sense?

    Thanks for your work you post, btw!

    Also, can you point me into a direction to learn thinkscript? The documentation they provide is rather slim, and trying to hack scripts isn’t very educational because I really don’t understand the syntax to begin with.

    Thanks again.

    Greg

  4. semuren says:

    Greetings ThinkScripter:

    Could you post the modification to make the signal work on two bars?

    Thanks,

    Josh

  5. Greg Hohman says:

    I got very intrigued by this, so I did setup 8 boxes to watch different time frames. I agree 100% with Greg’s idea above…it could be quite useful!! Also, I too would like to know what you find/found with less lookback (do I understand correctly that it uses 3 bars now)? THANKS A MILLION, BEST ONE I THINK.

  6. Batra says:

    Great Job. I modified your script to add the following ..
    1) When the second bar shows the reversal, the color white is painted
    2) the third bar code is the same as what you have except color changes to green.
    Could you verify to see if the logic is right?

    def triggerSell;
    def triggerBuy;
    def BarClosed;
    rec buySellSwitch;

    def isBarThree = if(isNan(close[-3]),0,1);

    if isBarThree {

    triggerSell = if(if(close[-1] < close,1,0) and (close[-2] < close[-1] or close[-3] close,1,0) and (close[-2] > close[-1] or close[-3] > close[-1]),1,0);
    buySellSwitch = if(triggerSell, 1, if(triggerBuy, 0, buySellSwitch[1]));
    BarClosed = if(isNan(close[-3]),0,1);
    } else {
    triggerSell = if(if(close[-1] < close,1,0) and (close[-2] close,1,0) and (close[-2] > close[-1] ),1,0);
    buySellSwitch = if(triggerSell, 1, if(triggerBuy, 0, buySellSwitch[1]));
    BarClosed = if(isNan(close[-2]),0,1);
    };

    plot SBS = if(triggerSell and BarClosed and !buySellSwitch[1], high, if(triggerBuy and BarClosed and buySellSwitch[1], low, double.nan));
    SBS.setStyle(curve.POINTS);
    SBS.setPaintingStrategy(paintingStrategy.LINE_VS_SQUARES);
    SBS.setLineWeight(3);
    SBS.setDefaultColor(if(isBarThree,color.Green, color.White);

  7. thinkscripter says:

    Batra,
    Well….Your syntax looks incorrect and when I pasted that code into ToS and it pitched a fit. Was this code working for you?
    -Eric

  8. batra says:

    eric:

    the last line was creating trouble..and am no expert on thinkscript..I just took your code and tried to fit the new logic..If you have a moment and can fix it..it will be great

  9. thinkscripter says:

    Hmmm…well, the last line is missing a parentheses and I don’t believe you can use setDefaultColor with more than one possible value. You must use assignValueColor.

  10. Jeff says:

    Hi Eric,

    Here’s a similar study that I found from a guy named Joshua Corum several months ago… He calls it the Gatsby Indicator. It is a 3 bar study too… and throws signal dots (red and green). His website is
    ” joshuacorum.spaces.live.com/ ”

    I don’t know if this will look right below… but here it is:

    input signalOffsetFactor = 0.20;
    def signalOffset = AvgTrueRange(high, close, low, 9) * signalOffsetFactor;
    plot Data = hlc3;
    def triggerSell = if(if(close[-1] < high, 1, 0) and (hlc3[-2] < close[-1] or hlc3[-3] low, 1, 0) and (hlc3[-2] > close[-1] or hlc3[-3] > close[-1]), 1, 0);
    rec buySellSwitch = if(triggerSell, 1, if(triggerBuy, 0, buySellSwitch[1]));
    def thirdBarClosed = if(IsNaN(hlc3[-3]), 0, 1);
    plot SBS = if(triggerSell and thirdBarClosed and !buySellSwitch[1], high + signaloffset, if(triggerBuy and thirdBarClosed and buySellSwitch[1], low – signaloffset, double.nan));
    SBS.SetStyle(curve.FIRM);
    SBS.SetPaintingStrategy(paintingStrategy.LINE_VS_POINTS);
    SBS.SetLineWeight(2);
    # SBS.SetDefaultColor(color.white);

    SBS.AssignValueColor(if triggerSell then
    if thirdbarclosed then
    #UpPos
    CreateColor(255, 0, 0) else
    #UpNeg
    CreateColor(255, 0, 0)
    else if Triggerbuy then
    #DnPos
    CreateColor(0, 255, 0) else
    #DnNeg
    CreateColor(0, 255, 0));

  11. elo says:

    ….this one should be simple

    …. how about an indicator which simply indicates that the current bar is not complete…. until it closes

    …. for example…. the current bar flashes…. or is highlighted…. while all completed bars appear normal….

    …. reason for the request….. how many times have you made a trade based on the current bar….. forgetting that it is not complete….
    …. only to watch your trade appear less desirable as the current bar finishes much differently than how you expected it to finish

    • Try this. The final bar is yellow until the next bar appears (i.e. the bar has closed).
      -Eric

      plot null = double.nan;
      assignPriceColor(if isNan(close[-1]) then color.yellow else color.current);

  12. Glenn says:

    Here’s a little tweak I made to your code that filters out some of the extra trades. I like fewer indications with higher probability. I also made the dot smaller and magenta and print the dot further from the high/low for visibility. Note: this version prints the dot on the active bar, not 3 bars back (another preference of mine).

    # SCALPERBUYSELL
    # (c) 2009 http://www.thinkscripter.com
    # thinkscripter@gmail.com
    # Last Update 04 FEB 2009

    def range=high-low;
    def triggerSell = (close < close[1]) and (close< low[1]) and (close[1] < close[2]) and (close[2] close[1]) and (close > high[1]) and (close[1] > close[2])and (close[2] >= close[3]);

    rec buySellSwitch = if(triggerSell, 1, if(triggerBuy, 0, buySellSwitch[1]));

    def thirdBarClosed = if(isNan(close[-3]),0,1);

    plot SBS = if(triggerSell and thirdBarClosed and !buySellSwitch[1], high+range*0.5, if(triggerBuy and thirdBarClosed and buySellSwitch[1], low-range*0.5, double.nan));
    SBS.setStyle(curve.POINTS);
    SBS.setPaintingStrategy(paintingStrategy.LINE_VS_SQUARES);
    SBS.setLineWeight(1);
    SBS.setDefaultColor(color.magenta);

    • Glenn says:

      Hi Eric, this is gonna sound weird, but I just noticed that the version of my code modification (that is waiting for moderation) has a line deleted….?

      Here’s the line, let’s see if it comes thru in this comment:

      def triggerBuy = (close > close[1]) and (close > high[1]) and (close[1] > close[2])and (close[2] >= close[3]);

      If there is not line of code above this line, then the gremlins have struck again… Not sure what to make of it. I noticed several other posts have the triggerBuy line of code missing as well.

      The code listed as “waiting for moderation” is not what I pasted into the submit window. Hmmm…?

  13. Ken Kayser says:

    Hi Eric,

    Just recently discovered you great site and will be making a donation. A couple of comments on the Scalping script:

    According to Carter, we should only be concerned with the current bar and the next 2 bars ([-1] and [-2]). Your script seems to go out another bar [13]. Also, the 3 bars should have consecutive higher or lower closes, hence I don’t understand the “or’s” in the if statements that define the buy and sell switches.

    Finally, I have noticed that the indicator doesn’t pick up the first occuraance if it is a buy signal. I think this is because the buySellSwitch [1] may not be defined at this time. I am a newbee at this so I may be off base.

    Thanks again for the site.

    Ken

  14. stewart says:

    i pasted the script and it doesnt work, there is an issue with def the buy/sell signal or such, anyone work it out who would be willing to share?

  15. ThinkScripter says:

    Please ensure that you use the icons in the upper right of the code window to copy/paste the code. The second icon copies the code straight to your clipboard. If you try to do this manually you will include the line numbers and the code will not work in TOS.

  16. vikas says:

    this is really a good indicator, any idea if we can scan the stocks in TOS using this indicator using the scan tab???

    • ThinkScripter says:

      This indicator is not real-time and cannot be used in scans. A full description of its use is available in Carter’s book.

  17. thinkscripter says:

    You’ve got mail. -TS

  18. thinkscripter says:

    Greg,
    That sounds possible. I’ll toss in in the good ideas pile. Unfortunately, the pile is rather large at this point. :) Unfortunately, the only ThinkScript reference I can find is the one ToS has. I’ve asked for a better reference and never got an answer.
    -TS

  19. Russ says:

    Batra -

    Did you get this code working properly? If so, how do you like it? Will you publish it?

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>