Daily Close Comparison Strategy (by ChartArt via sirolf2009)

8184 31 1141
Comparing daily close prices as a strategy.

This strategy is equal to the very popular "ANN Strategy" coded by sirolf2009(1) which calculates the percentage difference of the daily close price, but this bar-bone version works completely without his Artificial Neural Network (ANN) part.

Main difference besides stripping out the ANN is that my version uses close prices instead of OHLC4 prices, because they perform better in backtesting. And the default threshold is set to 0 to keep it simple instead of 0.0014 with a larger step value of 0.001 instead of 0.0001. Just like the ANN strategy this strategy goes long if the close of the current day is larger than the close price of the last day. If the inverse logic is true, the strategy goes short (last close larger current close). (2)

This basic strategy does not have any stop loss or take profit money management logic. And I repeat, the credit for the fundamental code idea goes to sirolf2009.

(2) Because the multi-time-frame close of the current day is future data, meaning not available in live-trading (also described as repainting), is the reason why this strategy and the original "ANN Strategy" coded by sirolf2009 perform so excellent in backtesting.

All trading involves high risk; past performance is not necessarily indicative of future results. Hypothetical or simulated performance results have certain inherent limitations. Unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not actually been executed, the results may have under- or over-compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profits or losses similar to those shown.

(1) You can get the original code by sirolf2009 including the ANN as indicator here:

(1) and this is sirolf2009's very popular strategy version of his ANN:

Remove from Favorite Scripts Add to Favorite Scripts
strategy("Daily Close Comparison Strategy (by ChartArt)", shorttitle="CA_-_Daily_Close_Strat", overlay=false)

// ChartArt's Daily Close Comparison Strategy
// Version 1.0
// Idea by ChartArt on February 28, 2016.
// This strategy is equal to the very
// popular "ANN Strategy" coded by sirolf2009,
// but without the Artificial Neural Network (ANN).
// Main difference besides stripping out the ANN
// is that I use close prices instead of OHLC4 prices.
// And the default threshold is set to 0 instead of 0.0014
// with a step of 0.001 instead of 0.0001.
// This strategy goes long if the close of the current day
// is larger than the close price of the last day.
// If the inverse logic is true, the strategy
// goes short (last close larger current close).
// This simple strategy does not have any
// stop loss or take profit money management logic.
// List of my work: 
//  __             __  ___       __  ___ 
// /  ` |__|  /\  |__)  |   /\  |__)  |  
// \__, |  | /~~\ |  \  |  /~~\ |  \  |  

threshold = input(title="Price Difference Threshold", type=float, defval=0, step=0.001)

getDiff() =>
    yesterday=security(tickerid, 'D', close[1])
    today=security(tickerid, 'D', close)
closeDiff = getDiff()
buying = closeDiff > threshold ? true : closeDiff < -threshold ? false : buying[1]

hline(0, title="zero line")

bgcolor(buying ? green : red, transp=25)
plot(closeDiff, color=silver, style=area, transp=75)
plot(closeDiff, color=aqua, title="prediction")

longCondition = buying
if (longCondition)
    strategy.entry("Long", strategy.long)

shortCondition = buying != true
if (shortCondition)
    strategy.entry("Short", strategy.short)
Hello! the indicator redraws your testimony?
sir this stretegy is repaint??? and if i want to compare hour closed instead of daily close is it posible??? if it posible then pls help me ...
@shiv_n, It is a repaint, probably does not work with version 3 of pine script
The strategy is not working. Signals are not reliable, can appear and disappear, a delay of several bars. Checked on the hourly timeframe
Off course it is not working in live trading the same as in backtesting. Please read the description text I wrote underneath the indicator and please also read my second comment underneath the strategy post. I mentioned several times that this strategy REPAINTS. Which is the effect you are describing.

This is the only strategy I shared on Tradingview which repaints and which is why I warned so many times about this problem.
You can read more about the repainting issue of certain strategies when you go to this other strategy linked below:

(This other strategy below does not repaint by the way. It wins all the time by only closing trades when the targeted profit has been achieved. I just deemed it a good place to discuss this related issue of strategies which seem to work so great in backtesting)
Hi, I tried changing the lines to:
threshold = input(title="Threshold", type=float, defval=0, step=1)

getDiff() =>
mod = ema(security(tickerid, 'D', close),2)

Basically, putting ema inside I hope would make it stabilized and pushing yesterday/today 1 day further with close price, should really make the signal fully rely on past data, not on evolving/live data. Please tell me your view.
sorry, suppose to be yesterday=mod, today=mod
+2 Reply

Will the strategy "repaint" when used on a daily chart?

ChartArt cjszbd
Good question. I can't say for sure how it behaves on the daily. But I can tell you that using it on the weekly and monthly charts stops it from repainting, because now you are on higher time-frames than the strategy itself, which always only uses daily close prices.
Hi all!
I'm trying to study this strategy .. I'm testing strategy ann (version 1.00) ---> sirolf2009 thanks for your work and idea!
I read all the comments and I came to ANN Strategy Indicator 3.2 (Rebuilt By Kevin Manrrique) ----> Kevin thanks for your hard work and contribution!
I re-read all the comments and ended up here at the Daily Close Comparison Strategy by ChartArt ----> chartartfor your hard work and contribution!!
but now I am a little confused. I will test all three strategies and will compare ANN1 with daily close of 1H end of the day signal, and ann rebuilt by kevin on 60min used for intraday positions.
I wanted to ask if it was possible to encode these three strategies as indicators of mt4. it's possible?
thank you all for your input and work. sorry for my English
EN English
EN English (UK)
EN English (IN)
DE Deutsch
FR Français
ES Español
IT Italiano
PL Polski
TR Türkçe
RU Русский
PT Português
ID Bahasa Indonesia
MS Bahasa Melayu
TH ภาษาไทย
VI Tiếng Việt
JA 日本語
KO 한국어
ZH 简体中文
ZH 繁體中文
Home Stock Screener Forex Signal Finder Cryptocurrency Signal Finder Economic Calendar How It Works Chart Features House Rules Moderators Website & Broker Solutions Widgets Stock Charting Library Feature Request Blog & News FAQ Help & Wiki Twitter
Profile Profile Settings Account and Billing My Support Tickets Contact Support Ideas Published Followers Following Private Messages Chat Sign Out