Conditional Horizontal Line

mark.917

Member
The code below is my approximation of Advanced GETs XTL indicator. When a buy or sell condition is met, I would like to plot a horizontal line at the entry price beginning on the setup bar and going to the right. The entry price is one-half the length of the setup bar added to the high for a long and subtracted from the low for a short. The setup bar is when there is a change in bar color from gray to blue/red. Sample chart and description from the GET manual shown below.

Code:
#
# Approximation of the Advanced GET XTL Indicator
# by Mark.917

input length = 20;
input strength = 35;

DefineGlobalColor("Bullish", Color.BLUE);
DefineGlobalColor("Bearish", Color.RED);
DefineGlobalColor("Sideways", Color.GRAY);

def cci = CCI(length);

def trendUp = cci > strength;
def trendDn = cci < -strength;
def noTrend = cci <= strength and cci >= -strength;

AssignPriceColor(if trendUp then globalColor("Bullish")
    else if trendDn then globalColor("Bearish")
        else globalColor("Sideways"));

def longSetup = noTrend[1] and trendUp;
def shortSetup = noTrend[1] and trendDn;
def longEP = high+((high-low)/2);
def longST = low-(high-low);
def shortEP = low-((high-low)/2);
def shortST = high+(high-low);

plot longEntry = if longSetup then longEP else Double.NaN;
plot longStop =  if longSetup then longST else Double.NaN;
plot shortEntry = if shortSetup then shortEP else Double.NaN;
plot shortStop =  if shortSetup then shortST else Double.NaN;

longEntry.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
longEntry.SetDefaultColor(Color.CYAN);
longStop.SetPaintingStrategy(PaintingStrategy.DASHES);
longStop.SetDefaultColor(Color.RED);

shortEntry.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
shortEntry.SetDefaultColor(Color.CYAN);
shortStop.SetPaintingStrategy(PaintingStrategy.DASHES);
shortStop.SetDefaultColor(Color.RED);

#
# end
#

xtl.jpg

The first bar that changes the color is called the FIRST BREAK OUT BAR. Add half the length of this Break Out Bar to obtain a BUY LEVEL.

Buy (go long) when the market penetrates the BUY LEVEL provided the following holds true: a) XTL does not detect and display a bar with the opposite Trend color. In the above illustration, the buy was generated with an Up Trend signal. Therefore, you should not see any Red color bars prior to the prices penetrating the BUY LEVEL. Neutral (Black) bars are okay and does not alter the strategy.
 
Last edited:
I have managed to get the entry price and stop loss to display on the setup bar but now I would like them to extend to the right until price closes above/below entry OR there is a blue/red bar flip. I also feel like this part of the code is clumsy, especially with all the different variable names that seem to be required.

Updated code in post #1.

xtl2.jpg
 
The code below is my approximation of Advanced GETs XTL indicator. When a buy or sell condition is met, I would like to plot a horizontal line at the entry price beginning on the setup bar and going to the right. The entry price is one-half the length of the setup bar added to the high for a long and subtracted from the low for a short. The setup bar is when there is a change in bar color from gray to blue/red. Sample chart and description from the GET manual shown below.

Code:
#
# Approximation of the Advanced GET XTL Indicator
# by Mark.917

input length = 20;
input strength = 35;

DefineGlobalColor("Bullish", Color.BLUE);
DefineGlobalColor("Bearish", Color.RED);
DefineGlobalColor("Sideways", Color.GRAY);

def cci = CCI(length);

def trendUp = cci > strength;
def trendDn = cci < -strength;
def noTrend = cci <= strength and cci >= -strength;

AssignPriceColor(if trendUp then globalColor("Bullish")
    else if trendDn then globalColor("Bearish")
        else globalColor("Sideways"));

def longSetup = noTrend[1] and trendUp;
def shortSetup = noTrend[1] and trendDn;
def longEP = high+((high-low)/2);
def longST = low-(high-low);
def shortEP = low-((high-low)/2);
def shortST = high+(high-low);

plot longEntry = if longSetup then longEP else Double.NaN;
plot longStop =  if longSetup then longST else Double.NaN;
plot shortEntry = if shortSetup then shortEP else Double.NaN;
plot shortStop =  if shortSetup then shortST else Double.NaN;

longEntry.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
longEntry.SetDefaultColor(Color.CYAN);
longStop.SetPaintingStrategy(PaintingStrategy.DASHES);
longStop.SetDefaultColor(Color.RED);

shortEntry.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
shortEntry.SetDefaultColor(Color.CYAN);
shortStop.SetPaintingStrategy(PaintingStrategy.DASHES);
shortStop.SetDefaultColor(Color.RED);

#
# end
#

View attachment 19320
The first bar that changes the color is called the FIRST BREAK OUT BAR. Add half the length of this Break Out Bar to obtain a BUY LEVEL.

Buy (go long) when the market penetrates the BUY LEVEL provided the following holds true: a) XTL does not detect and display a bar with the opposite Trend color. In the above illustration, the buy was generated with an Up Trend signal. Therefore, you should not see any Red color bars prior to the prices penetrating the BUY LEVEL. Neutral (Black) bars are okay and does not alter the strategy.

until someone modifies your code, this post might help you
https://usethinkscript.com/threads/having-trouble-with-stop-loss-code.16083/#post-129176
 
]@mark.917 That is a great approximation!!! Excellent (y)

Maybe you can do another approximation of Advanced GETs
MOB indicator, you click a Pivot High (or low) and will predict a price target (likely Support/Resistance in future).

Convert Conditional Horizontal Line into strategy
 
Last edited by a moderator:
]@mark.917 That is a great approximation!!! Excellent (y)

Maybe you can do another approximation of Advanced GETs
MOB indicator, you click a Pivot High (or low) and will predict a price target (likely Support/Resistance in future).
Way back when I was using Metastock I had something very close to the MOB working. Unfortunately I can no longer find that code.
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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