Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Calculate spread of two symbols, set it as double for use as input for indicator
Hi
I use spread (difference) of two symbols as input for another indicator.
Based on testing and a number of posts in this and other forums, it seems there are a couple of indicators (Spread, Pairs) that will do this, but both have programming errors (according to ppl who unlike myself can tell when there is one).
I've compared readings from "Spread3" indicator and "Pairs" indicator, and majority of the time they align, but at times return different result, despite being designed to perform seemingly identical function.
My second issue, is I want to use the spread calculation in Micro Trends easy trader (order management add-on for Ninjatrader), but since Easy trader was compiled WITHOUT the spread indicator present, Easy Trader cant access the return value of the spread (IF its even accurate to begin with).
Could someone advise me on:
1. Can I just declare a "double" which is (symbol1-Symbol2) and use that for input to my indicator to avoid having to access indicators that were not present when EasyTrader was compiled?
(sounds waaayy to simple, so there must be a reason its not done that way. Whats the reason?)
2. The other indicators (Spread, Pairs) seem to have much more code than a simple (symbol1-Symbol2).
I understand its for synchronization.
I'm simply trying to use spread calculation as input.
Any way to accomplish that with ACCURATE result, without calling another indie?
You can get the spread between two symbols, but it will be different in real time than with historic data due to the difference in ticks coming into your PC. For example, I coded an indicator to show the real time difference between the S&P and the Dow. If you are looking at it on a daily or even hourly chart, the two numbers are the same, but when you look shorter term, you see variations because the way the exchange sends the data along with latency, etc. will not give an accurate spread on a time based scale.
The following code plots the ratio between two symbols. You could easily edit it to plot the difference instead. (The SD part is not operating, and can be removed. I just put this out to give an example of how you can make an indicator that plots the difference or ratio of two symbols.)
To fix it, you could simply change the body of the code to read:
That should give you the difference between any two symbols at the current Close. (Closes[1][1]-Closes[2][1]) would give you the difference at the last bar. You can edit the symbols in the Indicator panel, and you can set your code to buy or sell when the difference reaches a predetermined value.
Im not so much after percent difference, as much as the actual spread value.
Its used on a short term 3, 5 and 10 min charts, so intraday accuracy is essential.
In your second post you said "to fix this", was that directed towards your initial tip on inaccuracy of short term data?
I currently get the spread value via Spread and Pairs indicators (which align MOST of the time, which IS the core of my problem as I dont know which I should use).
And as I mentioned, calling for outside indicator is not an option when it comes to integrating it with MicroTrends, so
I'm looking for code I'd need to add to my strategy that will do the calculation of the spread (we can use XXXX and YYYY as symbols for now), and output the result in such way (double or Int?) so it can be used as input for another indicator.
Example: (Please forgive my coding, I'm watching C# tutorials and getting better at this)
Public Int (or double?)
spreadCalc = "xxxx"-"yyyy"
Sorry I wasn't clear what I meant when I said "To fix this." What I meant was to make it give the difference instead of the ratio. By doing Close(XXXX)-Close(YYYY) instead of "100*((Closes[1][0]-Closes[1][1])/Closes[1][1]-(Closes[2][0]-Closes[2][1])/Closes[2][1]);"
I am not familiar with the limitations of MicroTrends, but I think I understand that you are saying it can't call an outside indicator, but you can write your own ninjascript into a Strategy that it executes.
If that's the case, you need to add the extra symbols into the initialization of the strategy with the code
Once you have added those two lines, you can access them by using the "Closes" format as opposed to "Close"
For example, the method to access the XXXX symbol for the present bar would be Closes[1][0], whereas to access the YYYY symbol, you would use Closes[2][0]. Likewise, you can access one bar prior with Closes[1][1] and Closes[2][2], etc. You can also do this with Opens, Highs, Lows, Medians, etc.
Thus, you can write the spread directly into a strategy in the same way that you would write it into an indicator.
Closes[1][0]-Closes[2][0] will give you the "spread" between the two symbols on the present bar if you have COBC set to false, though I would caution you that it is subject to the last reported trade in each symbol, and therefore can be quite off if volume is low and there is significant time between trades.