Is it possible to Code for divergence between 2 symbols ?

mohan.sic

Well-Known Member
#1
Good morning

Need a code in afl to identify divergences between 2 symbols.

Idea to test and see if any good divergences between 2 identically moving symbols can result in trend reversal.

Example: Two directly correlated symbols like - " Nifty future and Nifty BEES"

Divergence code should not be the issue here but is it feasible to code between 2 symbols?

We need to have multiple pairs in the code and each symbol in the pair should be compared only against other symbol in the same pair for divergences.

Examples of pairs:
1. " Nifty future and Nifty BEES"
2. " Bank Nifty future and Bank BEES"
3. " NTPC and Power Grid"
4. " ONGC and Gail"


Any coding experts please let me know the feasibility on this.

Thank you.
 

CougarTrader

Well-Known Member
#3
Idea to test and see if any good divergences between 2 identically moving symbols can result in trend reversal.
the idea is faulty and illogical at its very proposition itself... if two data points move identically, the iota of divergence that appears to incur would vanish immediately...

what you are looking for is a divergence analysis of futures contract and its underlying stock (also known as risk-free ARBITRATION)...

-> Such ARBITRATION is carried out using long stocks and its corresponding short futures; you would need very large capital (north of 10 Cr minimum) and uncanny ability to handle physical settlement (big trading desks do this to make lakhs every month "risks free")... this is one of many "artificial" "silent regulator" reasons for which we witness bloody volatile monthly expiries...

-> Such ARBITRATION can also be carried out by being "synthetically long" using options (BUY ATM CE & SELL ATM PE) and its corresponding short futures... need ability to meet exchange's all margin requirement during the last expiry week of a month (equivalent to physical settlement) ... but never go for physical settlement, close positions on the monthly expiry day around 15:20 - 15:25... I occasionally do this (twice or thrice a year - chances are very rare - need to be a spider to silently observe prices around 15:15 every trading day) when returns are favorable pounce for at least >= 1.5% on total deployed cash which is technically risk-free... only risk is if you fail to meet margin requirements during expiry week then you'll have to close position that could result in a small loss or no profit or very less profit...

For e.g. below wherever this ADANIENT stock goes, one to make profit only with this arbitrage... but keep physical settlement margin requirements rule in mind... simply...
if I hold Long futures or Long ITM Call or Short ITM Put position then long stock will be assigned
if I hold Short futures or Short ITM Call or Long ITM Put position then short stock will be assigned

accordingly margin needs to brought, generally:
Expiry (E) - 4 = 20% of VAR + ELM (Friday EOD)
Expiry (E) - 3 = 40% of VAR + ELM (Monday EOD)
Expiry (E) - 2 = 60% of VAR + ELM (Tuesday EOD)
Expiry (E) - 1 = 80% of VAR + ELM (Wednesday EOD)

1674820830933.png


[I have not taken this trade because of less return against required margin to deploy]

-> Such ARBITRATIONS need simple school-level algebra only, but clarity of derivative concepts is "absolutely" a must!

-> With very less margin one can opt to play between two instrument pair for now in India (but reward would be peanuts only so not worth venturing which you are eventually trying to achieve):
1) NIFTY front month future and equal amount of NIFTYBEES
2) BANKNIFTY front mnth future and equal amount of BANKBEES

my 2 cents only....
 

mohan.sic

Well-Known Member
#4
the idea is faulty and illogical at its very proposition itself... if two data points move identically, the iota of divergence that appears to incur would vanish immediately...

what you are looking for is a divergence analysis of futures contract and its underlying stock (also known as risk-free ARBITRATION)...

-> Such ARBITRATION is carried out using long stocks and its corresponding short futures; you would need very large capital (north of 10 Cr minimum) and uncanny ability to handle physical settlement (big trading desks do this to make lakhs every month "risks free")... this is one of many "artificial" "silent regulator" reasons for which we witness bloody volatile monthly expiries...

-> Such ARBITRATION can also be carried out by being "synthetically long" using options (BUY ATM CE & SELL ATM PE) and its corresponding short futures... need ability to meet exchange's all margin requirement during the last expiry week of a month (equivalent to physical settlement) ... but never go for physical settlement, close positions on the monthly expiry day around 15:20 - 15:25... I occasionally do this (twice or thrice a year - chances are very rare - need to be a spider to silently observe prices around 15:15 every trading day) when returns are favorable pounce for at least >= 1.5% on total deployed cash which is technically risk-free... only risk is if you fail to meet margin requirements during expiry week then you'll have to close position that could result in a small loss or no profit or very less profit...

For e.g. below wherever this ADANIENT stock goes, one to make profit only with this arbitrage... but keep physical settlement margin requirements rule in mind... simply...
if I hold Long futures or Long ITM Call or Short ITM Put position then long stock will be assigned
if I hold Short futures or Short ITM Call or Long ITM Put position then short stock will be assigned


accordingly margin needs to brought, generally:
Expiry (E) - 4 = 20% of VAR + ELM (Friday EOD)
Expiry (E) - 3 = 40% of VAR + ELM (Monday EOD)
Expiry (E) - 2 = 60% of VAR + ELM (Tuesday EOD)
Expiry (E) - 1 = 80% of VAR + ELM (Wednesday EOD)

View attachment 48770

[I have not taken this trade because of less return against required margin to deploy]

-> Such ARBITRATIONS need simple school-level algebra only, but clarity of derivative concepts is "absolutely" a must!

-> With very less margin one can opt to play between two instrument pair for now in India (but reward would be peanuts only so not worth venturing which you are eventually trying to achieve):
1) NIFTY front month future and equal amount of NIFTYBEES
2) BANKNIFTY front mnth future and equal amount of BANKBEES

my 2 cents only....

That's good info and thanks for taking time to detail it...
My query was entirely on different idea. I guess you mistook it for Arbitrage/pair trading related.
As said in the post - "
"Idea to test and see if any good divergences between 2 identically moving symbols can result in trend reversal"

So it is for normal day trading on one symbol of the pair.

For example, a negative divergence rule like - "Nifty made a new day high which is not seen in Nifty Bees"
In this case I would consider the new high made by Nifty as a weak move and expect a reversal or a pull back.
 

CougarTrader

Well-Known Member
#5

mohan.sic

Well-Known Member
#6
No, did not...

View attachment 48778

I was asking you to not waste time on fantasies... such a divergence pattern does not exist...

as you said correctly:

I completely understand what you are trying to say and the concern not to waste the time.

But what I want to know is the feasibility to code this. Can you let me know if this can be coded?

Don't worry about the result or if the idea is valid or fantasy. I am saying this because I am completely attentive of what am asking, and I guess below reasons may give you some confidence in the query-

1. The main reason your chart has no divergences is because - The divergence I am taking about on identical symbols is illogical and will not hold for long time. Hence, we can't find them on eod charts, but they appear on shorter time frames like 1 mt mainly due to reasons like sudden market movements and during price spikes after extended moves. After some time, they seem to disappear (they don't actually) but our eye cannot catch them in the middle of charts due to identical movements between the symbols.

2. To put it simple in the query I have taken example of " Nifty & Nifty BEES" but once if the code is feasible, it can be used on any combination like the ones mentioned in earlier post or something like "Nifty & Nifty ITM CE" etc.

Please don't worry about the logic behind or sensibility of the testing method but can this be coded in afl?
 

mohan.sic

Well-Known Member
#7
Below is Nifty and Nifty BEES intraday 1 mt chart on 24th Jan. You can find couple of divergences here.
I am talking about this kind of div's between identical symbols which appear of lower time frames.

Please note - The chart is not meant to discuss about method. So, one should think that this kind of signals can be used directly for trading. It won't work that way. This is just to assess if ami code can be done for this.

1674905929311.png