Instrument specific indicators?

Posted By: CL1

Instrument specific indicators? - 08/27/13 10:00

Hi, I am new to Zorro and find it to be very impressive! I create strategies for trading currencies, using 8 major pairs.

I create my own indicator, called "SSI", which I is constructed from all currency pairs and is not generic: the pairs to use and formula for each have to be hard coded. So far, I am unsure how to create indicators that require specific currency pairs or how to call them, as Zorro appears to create generic indicators.

1) How do I create an indicator that uses each of 8 currency pairs, but is individual to each of these pairs?
For example, in Python I have been using:

dict={"EUR/USD", "EUR/CHF", etc}
for currency in dict:
dataframe["SSI_"+str(currency)] = my calculation based on currency

Then, later I loop through the currency dictionary and inspect the value of SSI in the main trading portion.

2) If one could do this, how would one refer to the specific currency of interest with respect to the indicator? Meaning, if I have a EUR/USD strategy, how could I insist on using "SSI_EUR/USD" as in the Python example? It would be fine to have individual strategies created for each of the 8 pairs, but I am unclear how to refer to the appropriate variable.

Thanks for any help you can provide. I am quite sure this is possible, and for my strategies there are other variables that are generic that have to be optimized per currency pair, so solving this is a necessary first step.

Best, /CL
Posted By: jcl

Re: Instrument specific indicators? - 08/27/13 10:14

Welcome to Zorro. The simplest way is to check the currency inside the indicator. For instance:

Code:
if(Asset == "EUR/USD") {
  ...
} else if(Asset == "EUR/CHF") {
  ...
} etc.

Posted By: CL1

Re: Instrument specific indicators? - 08/27/13 10:41

Hi jcl,

Thanks for the quick reply! That answers my second question. To make each individual SSI indicator (ie. "SSI_EUR/CHF"), how do I refer to the other 7 pairs in indicator.c?

In short, can one pass 8 sets of prices to indicators.c?

Thanks,
/CL
Posted By: jcl

Re: Instrument specific indicators? - 08/27/13 11:06

Better do not add it to indicators.c. This is a standard include file, so at the next Zorro update your changes will be gone. Use your own include file for your indicators, or just put them into your main script.

For passing many different asset prices to an indicator, use the "loop" function. It is explained in workshop 5.

Posted By: CL1

Re: Instrument specific indicators? - 09/09/13 06:46

Hi, thanks but this doesn't give the desired effect. A toy example where I want to return a series that is the average price of EUR/USD and GBP/USD:

var ind1(var* Data) {
var temp_EURUSD;
var temp_GBPUSD;
if(Asset == "EUR/USD") {
temp_EURUSD=Data[0];
} else if(Asset == "GBP/USD") {
temp_GBPUSD=Data[0];
}
return (temp_EURUSD+temp_GBPUSD)/2; }

function run() {
set(PLOTPRICE+PLOTNOW);
PlotBars = 10000;
var* Price = series(price());

while(asset(loop("EUR/USD","GBP/USD"))) {
vars s1=series(ind1(Price));
plot("s1",s1[0],NEW,BLUE); }
}

Here I get a plot of the second currency chosen (GBP/USD) and this currency divided by 2 in the plot. So the second currency is not passed, presumably because each currency in the loop is executed individually?

How can I get this kind of indicator to work? Thanks!
Posted By: jcl

Re: Instrument specific indicators? - 09/09/13 12:04

Yes. You must declare the variables static, otherwise they have no content at the begin of the function.

static var temp_EURUSD;
static var temp_GBPUSD;
Posted By: CL1

Re: Instrument specific indicators? - 09/09/13 12:31

I made the change.

Now I get the price graph of the last pair in the function (GBP/USD), and the function output plot gives the price of the last pair in the "while" loop. Since it is not the average, or half of the price of the last pair, can one conclude that each loop in the function takes only a single pair at a time (and thus plots the last pair in the "while" loop)?

Maybe I am missing something?
Posted By: jcl

Re: Instrument specific indicators? - 09/09/13 13:19

Yes, the price is also set up at a wrong place - you must first call asset before you can get its price. Anything asset-dependent must be inside the loop and not outside.
Posted By: CL1

Re: Instrument specific indicators? - 09/09/13 13:30

Now it works!

Thanks!!
Posted By: CL1

Re: Instrument specific indicators? - 09/21/13 21:03

Hi, 2 questions related to this:

1) How does one plot the equity curves, etc. for ALL trades across all pairs? Now it seems like the pair indicated in the Zorro GUI determines which price plot, equity, etc. are displayed. It would be much more useful to have a plot of overall equity.

2) My pairs have an variable that will differ in optimized value between them. Instead of running an optimization many times with one pair being optimized, is it possible to have multiple variables (for each pair) and optimize all at the same time? In short, can 10 variables be optimized simultaneously, if they are all independent? Zorro documentation points to optimizing one after another, which would take substantially longer.

Thanks
Posted By: dusktrader

Re: Instrument specific indicators? - 09/21/13 22:09

Hi CL1,
I'm pretty sure the equity curve shown is always for the entire portfolio of assets. Only the price curve is for the single asset.

Also, I believe the answer to your question about optimizing is that it will correctly handle and optimize each parameter and asset. For example: 2 parameters logic + 3 assets in portfolio = 6 different parameters to optimize (someone please correct if I'm wrong).

There was a post recently where I understood how multi-param optimizes work and it might help you. Basically during each pass, the optimizer only looks to vary one parameter - while all others are static at their start value. Therefore, you might get better results to first individually determine the best 'start' values and then setup the ongoing multi-param optimize.

Hope that made sense...
© 2024 lite-C Forums