Rajandran R Creator of OpenAlgo - OpenSource Algo Trading framework for Indian Traders. Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Building Algo Platforms, Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in

Codesnippet : Autocorrelation Amibroker AFL and Pinescript Code

53 sec read

“Autocorrelation, also known as serial correlation, is the cross-correlation of a signal with itself. Informally, it is the similarity between observations as a function of the time lag between them” – Wikipedia. Autocorrelation value ranges from +1 to -1. Where autocorrelation above zero indicates a positive correlation and a negative value indicates a negative correlation.

Theoretically speaking, Positive Correlation means the time series is trending in the direction of its lagged time series and generally suits for trend trading. whereas the negative correlation mean the time series is mean reverting against the direction of lagged time series and generally suits for mean reversion trading. And if the auto-correlation value of zero represents random movements in stock price.

Nifty Spot Daily Charts – Tradingview
Autocorrelation - Tradingview

Nifty Futures Daily Charts – Amibroker
Autocorrelation - Amibroker
[wp_ad_camp_5]

The code snippets for Amibroker and Tradingview have given below

Autocorrelation – Pinescript Code (Tradingview)

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © marketcalls_in

//@version=4
study("Autocorrelation - Marketcalls")
len=input(10, minval=1,maxval = 50)
Dayreturn=roc(close,1)
autocorr = correlation(Dayreturn,Dayreturn[1],len)
plot(autocorr, color = color.green , style = plot.style_line , linewidth = 2,title = "Autocorrelation")
hline(0, title='hline1', color=color.red, linestyle=hline.style_dotted, linewidth=2)

You can also access the autocorrelation at tradingview public library

Autocorrelation – AFL Code (Amibroker)

_SECTION_BEGIN("Auto correlation");
Dayreturn=ROC(C,1);
AC = Optimize("AC",10,1,50,1);
AutoCor=Correlation(Dayreturn,Ref(Dayreturn,-1),AC);
Plot(AutoCor,"AutoCorrelation",colorRed);
Plot(0,"",colorGreen,style = styleDots);
_SECTION_END();
Rajandran R Creator of OpenAlgo - OpenSource Algo Trading framework for Indian Traders. Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Building Algo Platforms, Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in

How to Send TradingView Alerts to Telegram Without Any…

If you're a trader using TradingView, you know how crucial it is to stay updated with real-time alerts. Telegram, with its instant messaging capabilities,...
Rajandran R
3 min read

6 Indian Brokers You Can Connect with TradingView to…

TradingView is a globally recognized charting and trading platform that empowers traders with its advanced analytical tools and intuitive interface. For Indian traders, TradingView...
Rajandran R
2 min read

Line Trading – OpenAlgo Automation Module for Amibroker Users

The line Trading Automation tool is designed for Manual traders who want to perform level-based trade execution faster and also bring some advanced trade...
Rajandran R
55 sec read

4 Replies to “Codesnippet : Autocorrelation Amibroker AFL and Pinescript Code”

  1. Hi Rajendran,

    Thanks for taking the lead and sharing such wonderful trading knowledge. You not only have a very generous heart but also from what i have seen you are at the fore front of experimentation vis a vis applying new statistical concepts to trading.. Keep up the great work..

    Sai

  2. Hii…i am student, i want how the play moneybhai game…actually i n’t understand what done in this site with me..plz hlp me..

  3. Hi Mr Rajendiran, I got zero lag macd codes from some where but it is not working in mt4 I need your help to make it work in mt4 please

Leave a Reply

Get Notifications, Alerts on Market Updates, Trading Tools, Automation & More