Assistance Required for coding Pairs Trading AFL

#41
Profit sharing Basic intraday call

HI Traderji member i ready to dell all my post regarding call service but i dont know how to dell all post if you know tell me or any other person who have right he can del my all post regarding call service


Thanks
 

pankajpari

RSITradeMaster
#42
Dear Seniors / Experts,
Coming back to you for your help. I want the Pairs Trading AFL with Candlestick. Currently the same is a Line Chart.

I tried working on the same using HHV, Highest, TimeFrameGetPrice, etc. functions, but just couldn't code it.

The following is a small brief on the requirement :
(i) A simple code using the difference between the Open, High, Low and Close of one Scrip with that of the second Scrip (like, 'PH - H' or 'PL - L') will not work [H - High of Scrip 1, L - Low of Scrip 1, PH - High of Scrip 2, PL - Low of Scrip 2].

This is becos, even if Scrip 1 is making a high at say, 12:30 PM, Scrip 2 may not make a high at that exact time (though, it is possible that the Scrip 2 may make a high at an earlier or a later time, say at 12:32 PM, but is its highly unlikely that the high will be exactly at 12:30 PM).

(ii) If the chart is seen in a smaller TF, say, 15 minute TF, one can easily notice the Highs & Lows made by the Current Spread during the day. This is unlike viewing the chart in a Daily TF, where we can notice only one price point of the Current Spread at the extreme right of the chart, which is the CMP / LTP of the Current Spread.

Pls find attached the images of 2 charts, one showing the High made (in 15 Minute TF) on 22nd Nov '12 and the other showing the Low made (in 15 Minute TF) on 22nd Nov '12.

http://i.imgur.com/a0Cnb.png
http://i.imgur.com/gdYH1.png

You may also download the AFL of the Line Chart from the below mentioned link. (In order to view the chart of 'Line with Dots', go to "View > Price Chart Style > Line with Dots" in AmiBroker.

Pankaj Parimal - Pairs Trade (New Updated).txt - 4shared.com - document sharing - download

The attached images are of the pair - Bank Nifty & SBI. The same can be viewed by first selecting the chart of SBI and then using parameters (by right clicking on the chart) to key in the High Priced Scrip, i.e., Bank Nifty.

If one views the chart in a lower TF, say, 1 Minute TF, we can find a more accurate value of High or Low made by the Current Spread during the day.

Though AmiBroker has various functions like, TimeFrameGetPrice, TimeFrameExpand, TimeFrameCompress, HHV, LLV, Highest, Lowest, HighestVisibleValue, LowestVisibleValue, etc., I am not able to use the same to code this requirement.

(iii) The Open and Close values can be got by a simple code like 'PO - O' and 'PC - C', where PO - Opening Price of Scrip 2, PC - Closing Price of Scrip 2, O - Opening Price of Scrip 1 and C - Closing Price of Scrip 1. [But again, as in the case of High & Low, the Opening and the Closing prices of the 2 scrips may not be executed at the same time and may differ a little.]

Request the Seniors to suggest a better way, if any, of retrieving the Opening & Closing prices of Current Spread.

(iv) Once we have the Open, High, Low & Close values of the Current Spread, we can plot the Candlestick of Current Spread.

I would like to request all the seniors & experts to kindly help me with my requirement.

Pls let me know if you require further explanation or are unable to understand my requirement.
 
#43
suggest a better way, if any, of retrieving the Opening & Closing prices of Current Spread.

(iv) Once we have the Open, High, Low & Close values of the Current Spread, we can plot the Candlestick of Current Spread.

I would like to request all the seniors & experts to kindly help me with my requirement.

Pls let me know if you require further explanation or are unable to understand my requirement.
Use the base TF of 1 minute/5mins and plot the chart of required timeframe (15 mins, hourly or daily) using settimeframe/expandtimeframe

Will try n post the code

Thanks
 
Last edited:
#45
hey parttimetrader, would appreciate if you could code the same.... Thnx.
Code:
_SECTION_BEGIN("Pankaj Parimal - Pairs Trade");
//Time Frame to be used is '1/5/10/15 MINUTE'.
// Enter the Variables Here
Mkt=ParamStr("High Priced Scrip", "Enter High Priced Scrip Here");//Enter the High Priced Scrip of the Pair as per the NSE Nomenclature or the nomenclature set by the Data Provider, by right clicking the mouse and selecting 'Parameters'.

n=Param("TM",60,5,24*60,5); // TIME FRAME IN MINUTES

//***Base Market************/
PC=Foreign(Mkt,"C",1);//Closing Price of High Priced Scrip (A) Entered Above
PH=Foreign(Mkt,"H",1);//High 
PL=Foreign(Mkt,"L",1);//Low 
PO=Foreign(Mkt,"O",1);//OPEN 

/***Spread****************/
//Spread of Scrip A & Scrip B (Difference of Closing Price of Scrip A & Scrip B)

n_open=TimeFrameExpand(PO-O,n*in1Minute,expandPoint); // CAN CHANGE TIMEFRAME as inDaily / inHourly
n_high=TimeFrameExpand(PH-H,n*in1Minute,expandPoint);
n_low=TimeFrameExpand(PL-L,n*in1Minute,expandPoint);
n_close=TimeFrameExpand(PC-C,n*in1Minute,expandPoint);

PlotOHLC(n_open,n_high,n_low,n_close,"TM",colorBlack,styleCandle);
_SECTION_END();
See if this works for you

Plots a compressed chart of higher Time Frame on to any smaller TF charts.

Set the chart for 1/5/10/15 mins and choose to plot charts for mins 60/120/360 etc

also can hard code the TF as inHourly/inDaily etc

Thanks
 

pankajpari

RSITradeMaster
#46
Hey Parttime Trader,
Thnx for your efforts but it is not exactly meeting my requirement. What I wanted was the following :
- If you open my AFL in a 15 minute TF with 'View > Price Chart Style > Line with Dots', you will notice the high & low points traced by the Pair Spread during that day.
- What I am looking at is to capture these highest & lowest points and then plot the first point of the day as the Open, Highest point made during the day (as seen in the 15 min TF) as the High, Lowest point made during the day (as seen in the 15 min TF) as the Low and the last point of the day as the Close.
- Further, if we check the same chart in 5 minute TF, we will be able to capture more accurate high & low made during the day. With a 1 minute TF, the high & low points will be even more accurate.
- During Intraday, the LTP (of Spread) should be checked with the previous high or low made.
* At the start of the day, the first point will be the Open, High, Low and Close.
* As and when a higher point is made (as seen in the 15 minute, 5 minute or 1 minute TF), the High will be replaced by that higher point. Similarly, as and when the lower point is made, the Low will be replaced by that lower point.
* Later, if the LTP (of Spread) is higher than the earlier recorded high, the earlier high should be replaced by the LTP (of Spread).
* Similarly, if the LTP (of Spread) is lower than the earlier recorded Low, the earlier low should be replaced by the LTP (of Spread).
* But if the LTP (of Spread) is not higher or lower than the earlier recorded high or low, the earlier high & low will remain the same.
- My requirement is to view the OHLC candle in Daily TF.

If you do not have any issues, kindly PM me your cell number and I will call you to further explain my requirement.
 
#48
I have been trading equities since the last 4 years through various techniques. I have been using Pairs trading techniques and have devised and modified several self made trading models. What you need to understand is the theory behind the concept. You have to partly Discard Fama's efficient market hypothesis. Maybe i ll expand upon the filters to be used and my reasons for not trading this model through charts but through some numbers and intution. Human touch and understanding is equally important here.
 
#50
Hi Pankaipari,

I want to thank you for the Pairs Trading program. It sure looks promising and something Ive wanted to develop for a long-long time. Only my interest is a Pairs Trading program based on Long/Short ETFs. Your program appears to be concentrated on pairs of stock in same or related industries but possibly it could work with long/shorts.
The advantage of Long/Short ETFs ease of trading and bypassing a myriad of brokerage cost. Currently there are over 100 Long/Shot ETFs. I can send you a list if interested.
The move from Long to Short is strongly (or visa versa) based on trend change and anticipating such changes. The Smart Money does it by manipulation which according to VSA principles is done by the Smart Money at the top and is detected by huge volume (selling). My hope is that your program will also work with the Long/Short approach with ETFs. Your response will be extremely appreciated.

Dick Hoierman
Email: [email protected]
Your answer directed to my email will be appreciated
 

Similar threads