Three-bar High/Low

thiagofnsouza

New member
Hey guys,

I'm new here and i'm not a programmer. i'm just a hard-working person who tries a lot a do a lot of research to code with a lot of errors. That being said, i'm trying to do TOS coding the famous Larry Williams strategy.

The strategy is to buy at the price of the three-bar moving average of the lows if the trend is positive, and take profits at the three-bar moving average of the highs.

Sell signals are just the opposite. This means you will sell short at the three-bar moving average of the highs (if the trend is negative) and take profits at the three-bar moving average of the lows.

The way i have setted the trend is EMA9, but when i run the code, not every time the code plot a order at the market and he is buying/selling in a non sense target sometimes. Can you guys help me?

Here's my code:

input price = close;
input priceLast = PriceType.LAST;
input priceH = high;
input priceL = low;
input Media3High = 3;
input Media3Low = 3;
input length = 9;
input displace = 0;
input averageType = AverageType.SIMPLE;
input averageType2 = AverageType.EXPONENTIAL;

def bid = close (priceType = priceLast);
def ask = close (priceType = priceLast);

plot avgSELL = MovingAverage(averageType, high[-displace], Media3High);
plot avgBUY = MovingAverage(averageType, low[-displace], Media3Low);

plot AVG = MovingAverage(averageType2, price[-displace], length);
AVG.AssignValueColor(if AVG > AVG[1] then Color.GREEN else if AVG < AVG[1] then Color.RED else Color.YELLOW);
AVG.SetLineWeight(2);

avgBUY.AssignValueColor(Color.GREEN);
avgSELL.AssignValueColor(Color.RED);

def buy = ask or bid crosses avgBUY;
def sell = ask or bid crosses avgSELL;

AddOrder(OrderType.BUY_AUTO, buy, avgBUY, 1, tickcolor = Color.GREEN, arrowcolor = Color.GREEN);

AddOrder(OrderType.SELL_AUTO, sell, avgSELL, 1, tickcolor = Color.RED, arrowcolor = Color.WHITE);


---------------------------------------------------------------------------------------------------------------------------
thanks in advance.
 
Last edited by a moderator:
Solution
Hey guys,

I'm new here and i'm not a programmer. i'm just a hard-working person who tries a lot a do a lot of research to code with a lot of errors. That being said, i'm trying to do TOS coding the famous Larry Williams strategy.

The strategy is to buy at the price of the three-bar moving average of the lows if the trend is positive, and take profits at the three-bar moving average of the highs.

Sell signals are just the opposite. This means you will sell short at the three-bar moving average of the highs (if the trend is negative) and take profits at the three-bar moving average of the lows.

The way i have setted the trend is EMA9, but when i run the code, not every time the code plot a order at the market and he is...
Hey guys,

I'm new here and i'm not a programmer. i'm just a hard-working person who tries a lot a do a lot of research to code with a lot of errors. That being said, i'm trying to do TOS coding the famous Larry Williams strategy.

The strategy is to buy at the price of the three-bar moving average of the lows if the trend is positive, and take profits at the three-bar moving average of the highs.

Sell signals are just the opposite. This means you will sell short at the three-bar moving average of the highs (if the trend is negative) and take profits at the three-bar moving average of the lows.

The way i have setted the trend is EMA9, but when i run the code, not every time the code plot a order at the market and he is buying/selling in a non sense target sometimes. Can you guys help me?

Here's my code:

input price = close;
input priceLast = PriceType.LAST;
input priceH = high;
input priceL = low;
input Media3High = 3;
input Media3Low = 3;
input length = 9;
input displace = 0;
input averageType = AverageType.SIMPLE;
input averageType2 = AverageType.EXPONENTIAL;

def bid = close (priceType = priceLast);
def ask = close (priceType = priceLast);

plot avgSELL = MovingAverage(averageType, high[-displace], Media3High);
plot avgBUY = MovingAverage(averageType, low[-displace], Media3Low);

plot AVG = MovingAverage(averageType2, price[-displace], length);
AVG.AssignValueColor(if AVG > AVG[1] then Color.GREEN else if AVG < AVG[1] then Color.RED else Color.YELLOW);
AVG.SetLineWeight(2);

avgBUY.AssignValueColor(Color.GREEN);
avgSELL.AssignValueColor(Color.RED);

def buy = ask or bid crosses avgBUY;
def sell = ask or bid crosses avgSELL;

AddOrder(OrderType.BUY_AUTO, buy, avgBUY, 1, tickcolor = Color.GREEN, arrowcolor = Color.GREEN);

AddOrder(OrderType.SELL_AUTO, sell, avgSELL, 1, tickcolor = Color.RED, arrowcolor = Color.WHITE);


---------------------------------------------------------------------------------------------------------------------------
thanks in advance.

are you trying to compare bid and ask to a number?

def buy = ask or bid crosses avgBUY;
def sell = ask or bid crosses avgSELL;

this won't work as intended.
The or will make the formula treat the ask as a 1 or 0 value Instead of checking if it crosses an average.
You would have to spell it out completely, like,
= (ask crosses avgbuy) or (bid crosses avgbuy);
 
Solution

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
284 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