NexusFi: Find Your Edge


Home Menu

 





Code thinkscript hammer and star candlesticks


Discussion in ThinkOrSwim

Updated
      Top Posters
    1. looks_one sraman with 1 posts (0 thanks)
    2. looks_two fdomario with 1 posts (0 thanks)
    3. looks_3 TrendFollower1 with 1 posts (0 thanks)
    4. looks_4 caseyjames with 1 posts (0 thanks)
    1. trending_up 7,211 views
    2. thumb_up 2 thanks given
    3. group 7 followers
    1. forum 4 posts
    2. attach_file 0 attachments




 
Search this Thread

Code thinkscript hammer and star candlesticks

  #1 (permalink)
caseyjames
los angeles, ca
 
Posts: 1 since Jul 2018
Thanks Given: 0
Thanks Received: 0

I'm trying to plot arrows on hammers/stars with wicks that are 4x bigger than bodies. Up arrow under hammer, Down arrow above star. Have this so far, but don't see what's wrong.

I'd also like it to plot while it's forming.

Also also, I'd like to add it's only plots if the (high - low) > (High - low) for x amount of bars before it.

Thanks

Casey

# Calculate the length of the candle's wicks
def UpperWick = high - Max(open, close);
def LowerWick = Min(open, close) - low;

# Calculate the length of the candle's body
def CandleBody = AbsValue(open - close);

# Compare the wicks to the body to ensure that one wick is 4x longer than the body
# also compare the other wick to ensure that it is a "small" wick
def Hammer = (lowerWick / CandleBody >= 4) and (upperWick / CandleBody <= 0.5);
def Star = (upperWick / CandleBody >= 4) and (lowerWick / CandleBody <= 0.5);

plot signal = Hammer or Star;

signal.DefineColor("Above", GetColor(7));
signal.DefineColor("Below", GetColor(8));
signal.AssignValueColor(if Hammer then signal.Color("Above") else signal.Color("Below"));


signal.SetPaintingStrategy(if Hammer
then PaintingStrategy.BOOLEAN_ARROW_UP
else PaintingStrategy.BOOLEAN_ARROW_DOWN);

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Futures True Range Report
The Elite Circle
Ninja Mobile Trader VPS (ninjamobiletrader.com)
Trading Reviews and Vendors
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
Deepmoney LLM
Elite Quantitative GenAI/LLM
Exit Strategy
NinjaTrader
 
  #2 (permalink)
fdomario
Salisbury
 
Posts: 1 since Dec 2018
Thanks Given: 0
Thanks Received: 0

I would suggest you to break this to two separate indicators, I have given the code for Hammer below, use the same in reverse for Star. All the best.

plot Data = close;
# Length of the candle's wick
def UpperWick = high - Max(open, close);
def LowerWick = Min(open, close) - low;

# Length of the candle's body
def CandleBody = AbsValue(open - close);

# Compare body to wicks
def Hammer = (lowerWick / CandleBody >= 1.5) and (upperWick / CandleBody <= 1);

plot signal = Hammer;

signal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
signal.AssignValueColor(Color.GREEN );

Reply With Quote
  #3 (permalink)
sraman
washington, D.C.
 
Posts: 22 since Jul 2018
Thanks Given: 0
Thanks Received: 11


You do not need to calculate candle body height. There is already a function or the height of the candle. It is
BodyHeight();

Reply With Quote
  #4 (permalink)
 
TrendFollower1's Avatar
 TrendFollower1 
Austin, TX
 
Experience: Advanced
Platform: ThinkOrSwim
Trading: Currency, index, commodity futures
Posts: 9 since Mar 2012
Thanks Given: 18
Thanks Received: 8


caseyjames View Post
I'm trying to plot arrows on hammers/stars with wicks that are 4x bigger than bodies. Up arrow under hammer, Down arrow above star. Have this so far, but don't see what's wrong.

I'd also like it to plot while it's forming.

Also also, I'd like to add it's only plots if the (high - low) > (High - low) for x amount of bars before it.

Thanks

Casey

# Calculate the length of the candle's wicks
def UpperWick = high - Max(open, close);
def LowerWick = Min(open, close) - low;

# Calculate the length of the candle's body
def CandleBody = AbsValue(open - close);

# Compare the wicks to the body to ensure that one wick is 4x longer than the body
# also compare the other wick to ensure that it is a "small" wick
def Hammer = (lowerWick / CandleBody >= 4) and (upperWick / CandleBody <= 0.5);
def Star = (upperWick / CandleBody >= 4) and (lowerWick / CandleBody <= 0.5);

plot signal = Hammer or Star;

signal.DefineColor("Above", GetColor(7));
signal.DefineColor("Below", GetColor(8));
signal.AssignValueColor(if Hammer then signal.Color("Above") else signal.Color("Below"));


signal.SetPaintingStrategy(if Hammer
then PaintingStrategy.BOOLEAN_ARROW_UP
else PaintingStrategy.BOOLEAN_ARROW_DOWN);

--------

In case anyone is interested in this today, there are free thinkscript codes for hammers and shooting stars at the thinkscript_cloud OneNote site and at usethinkscript.com. I've been searching and these are the best sources I was able to find.

First site:
https://onedrive.live.com/redir?resid=2FF733D1BA1E1E79%21404&authkey=%21ABOXXFyQg1iUqFk&page=View&wd=target%2810.%20Candles%2FCandles.one%7C6f42f5bf-f3f4-4815-b9d5-f9254d971ee1%2FLess%20Restritive%20Hammer%20_DMonkey%7C03591753-1602-49ae-96dd-0b7ea82c8254%2F%29

Second site:
https://usethinkscript.com/

Reply With Quote
  #5 (permalink)
 
lukeskywalker1's Avatar
 lukeskywalker1 
Los Angeles (CA)
 
Experience: Master
Platform: ThinkOrSwim
Trading: Currency Future, Stocks
Posts: 34 since Apr 2019
Thanks Given: 1
Thanks Received: 40

Hi Casey

I changed your code a bit. I hope that now everything works exactly as you wanted.

input showArrows = yes;
input x = 5; #bars amount

# Calculate the length of the candle's wicks
def UpperWick = high - Max(open, close);
def LowerWick = Min(open, close) - low;

# Calculate the length of the candle's body
def CandleBody = bodyheight();
def range = High - low;
def cond = range == highest(range,x);

# Compare the wicks to the body to ensure that one wick is 4x longer than the body
# also compare the other wick to ensure that it is a "small" wick
def Hammer = (lowerWick / CandleBody >= 4) and (upperWick / CandleBody <= 0.5);
def Star = (upperWick / CandleBody >= 4) and (lowerWick / CandleBody <= 0.5);


#plot Arrows

plot UpArrow = Hammer and cond;
plot DnArrow = Star and cond;

UpArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
UpArrow.SetDefaultColor(Color.VIOLET);
UpArrow.SetLineWeight(3);
UpArrow.SetHiding(!showArrows);

DnArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_Down);
DnArrow.SetDefaultColor(color.Orange);
DnArrow.SetLineWeight(3);
DnArrow.SetHiding(!showArrows);

Visit my NexusFi Trade Journal Reply With Quote
Thanked by:




Last Updated on June 23, 2021


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts