Indicator that shows price difference/price difference ratio between two pairs/stocs for zerodha pi - please help

hi,

Looking for an indicator to see the price difference ratio or say spread between two stocks with mean line in between along with 2 standard deviation lines

what I looking for is basically - a price ratio (blue curve) that appears to oscillate around a mean (purple line). And then 1-, 2-, standard deviation lines just to get a feel for how far away from the mean the oscillations might go.

can some one please please code this indicator, I am sure there might be so many other people who are doing pair trading and are trying to find the same kind of indicator but it is not there, so it will help thousands of other zerodha users also

REFERENCES:
http://luminouslogic.com/a-pairs-trading-example.htm
https://www.equityfriend.com/traders-tool/pair-trade-opportunity-and-analysis.html

As far as I know there is no such ready indicator. This needs to be custom built. However, what you can do is, calculate the price difference between two stocks on a historical basis (you can also maintain this on an ongoing basis) and plot a simple bollinger band around it.

Bollinger band on price difference will help you understand how the spread behaves with respect to the mean. As you may know, the upper band is essentially +2SD and lower band is -2SD.

Thats what kartik I am looking for the code for this simple indicator to be built, but I do not know programming/coding so I am not able to build it myself, can you please help with coding it…

@AlgoGeek , can you help him?

Here the problem is we can not get the OHLC data of two different stocks on single chart. so we can not use the indicator and check the prices on same chart,

Alternately there is a compare option on kite charts

In Amibroker it is possible to code and use custom indicators and also there is overlay option where in you can get the data and view two charts data on single chart window

Check the below given Pair trading AFL for amibroker, you can change the scrip names etc., under parameter option by right clicking it

_SECTION_BEGIN(“Future Spread”);
SetChartOptions(0,chartShowArrows|chartShowDates);

_N( Symbol1= ParamStr(“Strike1”, “NIFTY-1M”) );

SetForeign( Symbol1 );
C1 = C;
H1 = H;
L1 = L;
O1 = O;
V1 = V;
RestorePriceArrays();

_N( Symbol2= ParamStr(“Strike2”, “NIFTY-2M”) );

SetForeign( Symbol2 );
C2 = C;
H2 = H;
L2 = L;
O2 = O;
V2 = V;
RestorePriceArrays();

Color = ParamColor( “Color”, colorRed );
Style = ParamStyle( “Style”, styleLine, maskPrice );

PlotOHLC( abs(O1-O2), abs(H1-H2), abs(L1-L2), abs(C1-C2), “(” + Symbol1+" - "+Symbol2 + “) spread”, Color, style );

_SECTION_END();

_SECTION_BEGIN(“Price1”);
Ticker = ParamStr(“Symbol”, Name() );
PlotForeign( Ticker, Ticker, ParamColor(“Color”, colorCycle ), ParamStyle(“Style”) | GetPriceStyle() );
_SECTION_END();

_SECTION_BEGIN(“Price2”);
Ticker = ParamStr(“Symbol”, Name() );
PlotForeign( Ticker, Ticker, ParamColor(“Color”, colorCycle ), ParamStyle(“Style”) | GetPriceStyle() );
_SECTION_END();

hello thank you so much algogeeks for replying and helping

this is 50%, it also requires standard deviation S1 and S2 to make decisions for pair trading…

can you please give me the code for adding this standard deviation in the script

thank you so much