public class MyResponse : ResponseTemplate
{
GenericTracker<decimal> relation = new GenericTracker<decimal>();
TickTracker kt = new TickTracker();
const string [] sym = new string[] { "a","b","c","d"};
const int a = 0;
const int b = 1;
const in c = 2;
const int d = 3;
string relationid = string.Join(",",syms);
override void GotTick(Tick k)
{
// track last/bid/ask
kt.newTick(k);
// compute relation on every tick
relation[relationid] = (kt.Last(sym[a]) + kt.Last(sym[b])/(kt.Last(sym[c])+kt.Last(sym[d]));
// plot it, trade it, etc
sendchartlablel(k.time,relation[relationid]);
}
override void Reset()
{
// track each relationship
relation.addindex(relationid);
// subscribe to ticks for symbols
sendbasket(sym);
}
}
Quote from paranoidone:
I use AmiBroker...
relation = ( Foreign("AAPL", "C") + Foreign("HPQ", "C") ) / ( Foreign("DELL", "C") + Foreign("IBM", "C") );
Plot(relation, "Relation of Stocks", ColorRed, styleLine);
Quote from funnyguy:
Yeah, two lines of code there. One for calculation and another one for plotting.
Code:relation = ( Foreign("AAPL", "C") + Foreign("HPQ", "C") ) / ( Foreign("DELL", "C") + Foreign("IBM", "C") ); Plot(relation, "Relation of Stocks", ColorRed, styleLine);
stock1 = ParamStr("Stock 1", "input here");
stock2 = ParamStr("Stock 2", "input here");
stock3 = ParamStr("Stock 3", "input here");
stock4 = ParamStr("Stock 4", "input here");
relation = ( Foreign(stock1, "C") + Foreign(stock2, "C") ) / ( Foreign(stock3, "C") + Foreign(stock4, "C") );
Plot(relation, "Relation of Stocks", ColorRed, styleLine);