ChartArt

Daily Close Comparison Strategy (by ChartArt via sirolf2009)

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:

ANN


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

ANN Strategy
Remove from Favorite Scripts Add to Favorite Scripts
//@version=2
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: 
// https://www.tradingview.com/u/ChartArt/
// 
//  __             __  ___       __  ___ 
// /  ` |__|  /\  |__)  |   /\  |__)  |  
// \__, |  | /~~\ |  \  |  /~~\ |  \  |  
// 
// 

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)
    delta=today-yesterday
    percentage=delta/yesterday
    
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)
ChartArt
9 months ago
I forgot before publishing to change the equity of the strategy to use e.g. $10000, that's why the net profit is shown as only $0.98 on EURUSD. With $10000 it would be a theoretical net profit of $198000.
+1 Reply
ChartArt
9 months ago
Again - as mentioned in the description - this strategy REPAINTS.

Every other strategy I have released so far does not repaint. But this strategy is repainting. Which means the buy (long), sell (short) alerts can often change during live trading, because it uses the current daily close which is only final at the market close at the end of the day. Therefore this strategy is most reliable nearing the end of the current trading day and least reliable at the start of the trading day.
Reply
ChartArt ChartArt
9 months ago
Here is how this repainting of the strategy looks like in live trading. When the higher time-frame (in this case the daily close on a 1-minute chart) is near to change the trend direction - several long and short alerts will show up until the market finally goes in a new direction.

snapshot



After reloading - while still on the same not yet closed daily candle - the repainting already removes the uptrend alert on the indicator: When reloading this chart on the next day after the daily candle has closed all of the alert noise will be gone, too.

snapshot
Reply
iykedy ChartArt
9 months ago
@ChartArt I have a similar problem with a strategy that uses 2 timeframes too. Given this problem, how would you trade this strategy?
Reply
lux5romtripp iykedy
9 months ago
im also interested in this question
Reply
LiLina ChartArt
8 months ago
Sorry I'm new to this and my programming knowledge is quite rusty. Could you confirm whether my understanding is correct: if I use like 5 min timeframe chart, every 5 mins there would be a new current close price (not the daily close price, just the 5min close price), and the code would think that is the "daily close price" at that time and therefore it will change the judgement on long/short? But throughout the day, when the price is lower than the previous day close, it doesn't go short...
+1 Reply
ChartArt LiLina
6 months ago
No. This script compares only the daily close price. The lines in the script are:

yesterday=security(tickerid, 'D', close)
today=security(tickerid, 'D', close)

It does not matter if you are on a 3 minute or 15 minute or 240 minute time-frame chart. The script always only compares the daily close price of yesterday with the final close of today. And since today has not closed while running the script live it repaints in backtesting.
Reply
ChartArt ChartArt
6 months ago
And yes the script uses in live trading the new information it gets in the interval of you chart. So when you are on a 3 minute time-frame it compares the daily close price every 3 minutes and on a 240 min chart every 4 hours. But since the daily closes only once per day the information is invalid all the time in live trading and only reliable in backtesting.

To avoid many changing signals in live trading using the 60 minute chart gives less wrong signals per hour than lower time-frames like the 15 minute chart. Equally using the 4 hour chart gives less wrong signals per day than the 1 hour chart, simply because the 1 hour changes the signal every hour and the 4 hour changes the signal only every 4 hours. But therefore wrong signals remain wrong also longer on a 4 hour chart versus a 1 hour or 15 minute chart.
Reply
Hello ChartArt. I've been working on this strategy for a very long time, I've done some changes that I haven't published because I want to perfect it before giving it to the public. I've talked to Sirolf about the strategy, he gave me information and with that information I creating a better version. I just made some changes a day or so and I haven't received many repaints. Obviously it still repaints but not as much. Please message me so we can create this amazing script into an artwork. Also I've changed "yesturday" to today, and today to "hourly". It helps alot, well that I believe. Also does the step have to be 0.0001. I put the step to 1 only. Shoot me a message, let's talk thanks.
Reply
I can work on this, see what I can do!

ANN Strategy Indicator 3.2 (Rebuilt By Kevin Manrrique)
Reply
AugustinC
6 months ago
Do you guys know how to program an alert for this strategy ?
Reply
I made alerts for this strategy for a person in the community. So I'll also share it to everyone, thank you.

https://docs.google.com/document/d/1Qg7sLQz_791uP4I1euNCkIWDQo54hzIGrXjQ87paZnc/edit?usp=sharing
+1 Reply
AugustinC TradeWithConfidence
6 months ago
Many thanks Kevin
Reply
ChartArt TradeWithConfidence
6 months ago
Thank you for sharing the alert of your script version.
Reply
AugustinC
6 months ago
Can we avoid false signals if we have the same signal on 2 or 3 other timeframes ?
Reply
ChartArt AugustinC
6 months ago
No, because the daily is not closed until the trading day is over ... which is always in the future and therefore a problem which can not be solved ... unless you revive Albert Einstein from the dead to build a time-machine.
Reply
AugustinC ChartArt
6 months ago
Ok. And which timeframe is better for this strategy ? Daily ?
Larger is the timeframe, better are the signals ?
Reply
ChartArt AugustinC
6 months ago
When you use a 5 minute time-frame in live trading the right and wrong signals change more often, because the update frequency is higher. When you use a 4 hour chart the right and wrong signals change less often.

I recommend to avoid using the daily and also the weekly and monthly, because in backtesting the performance is on these high time-frames more often very bad (unprofitable). For example when you test the strategy on the Facebook (FB) stock the daily is unprofitable, the 4 hour and lower time-frames are profitable. Therefore using the 1 hour to 4 hour charts is "better" than using the daily chart.
+1 Reply
AugustinC ChartArt
6 months ago
Ok thanks ; )
I will use 2 or 4h
Reply
LuCi
6 months ago
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
Reply
LuCi LuCi
6 months ago
*chartart thanks for your hard work and contribution!
Reply
cjszbd
4 months ago
Hello,

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

Thanks,
Charles
Reply
ChartArt cjszbd
3 months ago
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.
Reply
Stylo
3 months ago
The strategy is not working. Signals are not reliable, can appear and disappear, a delay of several bars. Checked on the hourly timeframe
Reply
ChartArt Stylo
3 months ago
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)
The Always Winning Holy Grail Strategy - Not (by ChartArt)
Reply
giorsims PRO ChartArt
3 months ago
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)
yesterday=mod
today=mod

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.
Reply
giorsims PRO giorsims
3 months ago
sorry, suppose to be yesterday=mod, today=mod
+1 Reply
Ideas Scripts Chart
United States
United Kingdom
India
España
Italia
Brasil
Россия
Türkiye
日本
한국
Home Stock Screener Economic Calendar How It Works Chart Features House Rules Moderators For the WEB Widgets Stock Charting Library Priority Support Feature Request Blog & News FAQ Help & Wiki Twitter
Private Messages Chat Ideas Published Followers Following Priority Support Public Profile Profile Settings Billing Sign Out