NexusFi: Find Your Edge


Home Menu

 





Pairs trading


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one asieretxebe with 5 posts (1 thanks)
    2. looks_two SMCJB with 2 posts (1 thanks)
    3. looks_3 Quick Summary with 1 posts (0 thanks)
    4. looks_4 drm7 with 1 posts (1 thanks)
    1. trending_up 2,642 views
    2. thumb_up 3 thanks given
    3. group 3 followers
    1. forum 7 posts
    2. attach_file 0 attachments




 
Search this Thread

Pairs trading

  #1 (permalink)
asieretxebe
Bilbao , Spain
 
Posts: 4 since Mar 2017
Thanks Given: 2
Thanks Received: 1

Happy new year to all traders!
I´ve been trading for a while now but I´m quite new still to automated trading and even if I read a hundred posts and manuals I can´t find the solution. A bit of help would be very much appreciated.

Goal:
backtest an arbitrage strategy that trades 2 instruments at the exact same time

Strategy core : if %change tickerA +% change ticker B < -1 then buy. exit when >0

Issues:
-even if there are 2 data sources in a chart just data 1 is traded
-If I open 2 charts ( to combine the 2 performance reports manually afterwards) with tickerA as data 1 and tickerB as data2 in one of them, and tickerB as data 1 , tickerA as data2 in the other one , the resulting operations are different. ( if A +B = x; then B+A should be X as well, but it´s not)
-maybe tradestation does not plot prices if there are no trades, and there´s a false signal because ticker A does not have price and B does??(I have no clue)
I have tried using portfolio maestro with all possible combinations (using 2 separate strategies for each data, combining everything…) and same problem, entries and exits don´t match in booth instruments.


Possible solutions that I don´t know how to code:
-Strategy that enters / exits positions in ticker B just when the same happens in ticker A ( For live trading I can use macros , but I have no idea for normal backtest or portfolio maestro)
-Something that gets the exact time of positions in A and then replicates in B...

Code till now:

inputs: variable1 (100000) , variable2 (-1) , variable3 (0);

Value1 = ((open-CloseD(1))/CloseD(1)) ;
Value2 = ((open data2-(CloseD(1) data2))/CloseD(1) data2) ;
value3 = ((value1 +value2)*100);
value4 = (Round(((variable1)/closeD(1)),0));

Condition1 = marketposition = 0 and Value3<variable2 ;
Condition2 = MarketPosition = 1 and value3>variable3 or ( Time >2150);

If condition1 then buy (value4) shares next bar at market;
If condition2 then sell all shares next bar at market;

Sorry for the long post, and thank you so much in advance for any help or ideas!!!
[][]

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Trade idea based off three indicators.
Traders Hideout
ZombieSqueeze
Platforms and Indicators
Better Renko Gaps
The Elite Circle
Cheap historycal L1 data for stocks
Stocks and ETFs
Quant vue
Trading Reviews and Vendors
 
  #3 (permalink)
 
SMCJB's Avatar
 SMCJB 
Houston TX
Legendary Market Wizard
 
Experience: Advanced
Platform: TT and Stellar
Broker: Advantage Futures
Trading: Primarily Energy but also a little Equities, Fixed Income, Metals and Crypto.
Frequency: Many times daily
Duration: Never
Posts: 5,049 since Dec 2013
Thanks Given: 4,388
Thanks Received: 10,207


Try using 2 workspaces each with 3 data sources.
First workspace your data sources are Ticker A, Ticker A (again) and Ticker B.
Second workspace your data sources are Ticker B, Ticker A and Ticker B (again).

Make all your calculations/decisions based upon data feeds 2 and 3, which are the same on both workspaces. So same code for both except when you buy on 1/A you sell on 2/B. This has worked for me in previously.

Reply With Quote
Thanked by:
  #4 (permalink)
drm7
Virginia
 
Posts: 49 since Oct 2010
Thanks Given: 192
Thanks Received: 47

I am not familiar with the Tradestation platform, but can you create a synthetic security with the pair, then trade it using a mean-reverting technical indicator to make it more straightforward? (e.g. stochastics, RSI, bollinger bands, etc.)

Security A = Ticker1 - Ticker 2

Buy when RSI(14) of Security A = 25, sell @ 75

You would have to balance the dollar amounts of the securities according to their relative notional value and volatility as well.

Reply With Quote
Thanked by:
  #5 (permalink)
 
SMCJB's Avatar
 SMCJB 
Houston TX
Legendary Market Wizard
 
Experience: Advanced
Platform: TT and Stellar
Broker: Advantage Futures
Trading: Primarily Energy but also a little Equities, Fixed Income, Metals and Crypto.
Frequency: Many times daily
Duration: Never
Posts: 5,049 since Dec 2013
Thanks Given: 4,388
Thanks Received: 10,207


drm7 View Post
I am not familiar with the Tradestation platform, but can you create a synthetic security

You can create an indicator that would display your synthetic security but can't trade it. In tradestation a workspace will only trade the instrument displayed in data1 and it has to be a single real security.

Reply With Quote
  #6 (permalink)
asieretxebe
Bilbao , Spain
 
Posts: 4 since Mar 2017
Thanks Given: 2
Thanks Received: 1


SMCJB View Post
Try using 2 workspaces each with 3 data sources.
First workspace your data sources are Ticker A, Ticker A (again) and Ticker B.
Second workspace your data sources are Ticker B, Ticker A and Ticker B (again).

Make all your calculations/decisions based upon data feeds 2 and 3, which are the same on both workspaces. So same code for both except when you buy on 1/A you sell on 2/B. This has worked for me in previously.

Good idea that could solve the problem. Thanks! I will test it on monday and update

Reply With Quote
  #7 (permalink)
asieretxebe
Bilbao , Spain
 
Posts: 4 since Mar 2017
Thanks Given: 2
Thanks Received: 1


SMCJB View Post
Try using 2 workspaces each with 3 data sources.
First workspace your data sources are Ticker A, Ticker A (again) and Ticker B.
Second workspace your data sources are Ticker B, Ticker A and Ticker B (again).

Make all your calculations/decisions based upon data feeds 2 and 3, which are the same on both workspaces. So same code for both except when you buy on 1/A you sell on 2/B. This has worked for me in previously.


drm7 View Post
I am not familiar with the Tradestation platform, but can you create a synthetic security with the pair, then trade it using a mean-reverting technical indicator to make it more straightforward? (e.g. stochastics, RSI, bollinger bands, etc.)

Security A = Ticker1 - Ticker 2

Buy when RSI(14) of Security A = 25, sell @ 75

You would have to balance the dollar amounts of the securities according to their relative notional value and volatility as well.

Yes I could build sinthetic data but I keep having the same. Problem. When comparing ticker A to sinthetic data X and ticker B to sinthetic data X

Reply With Quote
  #8 (permalink)
asieretxebe
Bilbao , Spain
 
Posts: 4 since Mar 2017
Thanks Given: 2
Thanks Received: 1


SMCJB View Post
Try using 2 workspaces each with 3 data sources.
First workspace your data sources are Ticker A, Ticker A (again) and Ticker B.
Second workspace your data sources are Ticker B, Ticker A and Ticker B (again).

Make all your calculations/decisions based upon data feeds 2 and 3, which are the same on both workspaces. So same code for both except when you buy on 1/A you sell on 2/B. This has worked for me in previously.

I tried adding the 3 datas and it works even for portfolio maestro. Thank you so much !!

Reply With Quote
Thanked by:




Last Updated on January 7, 2019


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts