Multi-bar Engulfing Pattern

ksle2011

New member
Anyone can help fix the code below by adding Weekly changes? Thank you.



# YTD Return
# Mobius
# 06.15.2015

declare hide_on_intraday;

input price = close;
input length = 1;
input displace = 0;
input Show_Labels = yes;

def newyear = if getYear() != getYear()[1] then 1 else 0;
def newmonth = if getMonth() != getMonth()[1] then 1 else 0;
def yo = compoundValue(1, if newyear then open else yo[1], open);
def mo = compoundValue(1, if newmonth then open else mo[1], open);
def yearopen = yo;
def monthopen = mo;
def SMA = Average(price[-displace], length);
def yochange = (sma - yearopen) / yearopen ;
def mochange = (close - monthopen) / monthopen;

AddLabel(Show_Labels, concat("Year % change = ", AsPercent(yochange)), color.white);
AddLabel(Show_Labels, "Month % change = " + (AsPercent(mochange)), color.white);
 
Solution
@wherdendorf
ouUtOKd.png

Ruby:
def GreenBar = open<=close;
def RedBar = open>close;

def USignal;
If RedBar {
USignal = open;
}else if RedBar[1] and open >= close[1] {
USignal = 0;
}else If USignal[1] and GreenBar and !RedBar[1] and close >= USignal[1] and close[1] < USignal[1]{
USignal = Double.NaN;
}else{
USignal = USignal[1];}

plot line = if IsNaN(Usignal) then USignal[1] else Double.NaN;
line.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

#AddChartBubble(yes,high,Signal,color.white);
plot UpSignal = if !IsNaN(USignal[1]) and IsNaN(USignal) then USignal[1] else Double.NaN;
UpSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
That sure is a nice looking chart. Thanks for you prompt attention to my problem. I see that even auto buy buys at the next candle. That means that all automated backtesting will produce garbage results. I have been backtesting manually for months now (way to much screen time). I did put a label on the chart based on the horizontal line script. This does flash every time the line appears, which is what I want. So now I guess I will have to set up Auto hot keys to react to the change then put in orders. I think I would have to paper trade for a couple of months to get real time results. Thanks to Svanoy for doing all the heavy lifting on this subject. He even posted his ahk script on the algo trading thread. The finish line has been pushed farther down the road, but thanks to your help it is a lot closer. Again....Thank you my friend for your work. I will keep you updated on my progress.
 
I see that even auto buy buys at the next candle. That means that all automated backtesting will produce garbage results.
I am struggling with the same issue.
https://usethinkscript.com/threads/...-fatal-flaw-of-thinkscript.13475/#post-113259

I want my trade to execute now, on the current bar when my condition becomes true (like in real trading) so that I can more accurately backtest and forward test strategies.

But what you said above is not what I am seeing when I test the code from Svanoy/halcyonguy. What I see is that the text (e.g. -1 Sell) appears above the new bar (I'm not sure this issue can be fixed) but the actual order execution price if you look at the P/L report is the close price of the previous bar where the condition became true.

So the text graphics on the chart are 'wrong' but the P/L report appears to be correct. Essentially the P/L report is being tweaked to reflect where you want the trade to happen in real life. Please take another look and let me know if you agree. Thanks
 

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