Asset list

Posted By: Brax

Asset list - 09/08/17 20:17

ŋIs there a way to define my portfolio assets in an array for using it in the asset loop? ŋCould i obtain the corresponding index for an asset in the array given its name?

Something like a HashTable or so, I know 'Assets' exists, but seems to be read only.

Thanks.
Posted By: AndrewAMD

Re: Asset list - 09/08/17 21:10

Like this?

Code:
int i,j;
string as[2], al[2];
as[0] = "EUR/USD";
as[1] = "USD/JPY";
al[0] = "TRND";
al[1] = "CNTR";
// portfolio loop
while(asset(loop(as[0],as[1])))
while(algo(loop(al[0],al[1])))
{
if(Asset == as[0]) i=0; // etc
if(Algo == al[0]) j=0; // etc
}

Posted By: Brax

Re: Asset list - 09/10/17 20:41

Well, not really...

The point is not having to repeat the listing in array initialization, loops, an so on.

I think, given the tools that zorro provides, the best option itīs just using a for loop and using the index for selecting assets and avoiding switch statements.

Code:
int i,j;
string as[2], al[2];
int lt[2];
as[0] = "EUR/USD";
as[1] = "USD/JPY";
al[0] = "TRND";
al[1] = "CNTR";
lt[0] = 10;
lt[1] = 20;

// portfolio loop
for(i=0;i!=2;i++)
{
   asset(as[i]);
   Lots = lt[i]; //Avoiding switchs
   for(j=0;j!=2;j++)
   {
      algo(al[j]);
      
      if(algo == "CNTR")
         tradeCounterTrend();
      elseif(algo == "TRND")
         tradeTrend();
   }
}

Posted By: AndrewAMD

Re: Asset list - 09/11/17 00:40

Did you know that the loop() function serves a special purpose for Zorro, particularly for portfolio trading?

Sure, a for loop will cycle you through the assets, but now your portfolio functionality is gone! (See workshop 6: Portfolio Trading)

One other approach would be to create a custom asset list csv and invoke it with assetList, and then determine which number of asset you are on with LoopNum1 or LoopNum2.

But definitely consider using loop() when portfolio trading.
Posted By: Brax

Re: Asset list - 09/11/17 10:03

Yes, iīve always used loop() in my scripts, using for() was just a "solution" for my addressed question.

I hadnīt realized about Loop1 and LoopNum1, but then the point would be to define Assets directly in the script, not in a separate csv.

I think itīd be more practical and quick.

Thanks.

Posted By: AndrewAMD

Re: Asset list - 09/11/17 10:48

In that case, use a blank Asset list by default, define your assets entirely in your script with AssetAdd, then use loop(Assets). You can coordinate the assets in whichever way you please.
Posted By: Brax

Re: Asset list - 09/11/17 17:35

Thank you very much! This is what i was looking for.

Now my code looks way more elegant! laugh
Posted By: AndrewAMD

Re: Asset list - 09/11/17 18:43

Yay! Actually, I might use this setup myself, especially for larger portfolio jobs.
Posted By: JamesHH

Re: Asset list - 05/24/19 15:45

Originally Posted By: AndrewAMD
In that case, use a blank Asset list by default, define your assets entirely in your script with AssetAdd, then use loop(Assets). You can coordinate the assets in whichever way you please.


I tried this approach: In the main() function, I loaded a file with an empty asset list using assetList and then called assetAdd with each of the assets. However, this only added the assets to the GUI, and Assets remains empty with NumAssetsListed == 0 (so of course loop(Assets) does not work).

Could this be a bug in Zorro version 2.03 that I am using?
© 2024 lite-C Forums