Gamestudio Links
Zorro Links
Newest Posts
FXCM: "Can't connect to price server"
by jcl. 06/19/19 15:47
Data Execution Prevention Strikes Again
by Dooley. 06/19/19 15:38
assert
by jcl. 06/19/19 14:59
Bring the old grin back!
by Michael_Schwarz. 06/19/19 07:56
Help with calculation
by Qw3rty. 06/18/19 08:01
AUM Magazine
Latest Screens
The Space Between
Pogostuck: Rage With Your Friends
Worst Case Z
AckCon'18 - Lotter vs the World 2 - Preview Release
Who's Online Now
13 registered members (AndrewAMD, Kaga, JeyKey II, Dooley, Grat, kvm, alibaba, Ayumi, MatPed, 1 invisible), 632 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Qw3rty, Dal, Carson, giantj, dh85
18236 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Asset list #467940
09/08/17 20:17
09/08/17 20:17
Joined: Aug 2017
Posts: 98
Spain
B
brax Offline OP
Junior Member
brax  Offline OP
Junior Member
B

Joined: Aug 2017
Posts: 98
Spain
┐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.

Re: Asset list [Re: brax] #467941
09/08/17 21:10
09/08/17 21:10
Joined: Feb 2017
Posts: 664
Chicago
AndrewAMD Online
User
AndrewAMD  Online
User

Joined: Feb 2017
Posts: 664
Chicago
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
}


Last edited by AndrewAMD; 09/08/17 21:31.
Re: Asset list [Re: AndrewAMD] #467957
09/10/17 20:41
09/10/17 20:41
Joined: Aug 2017
Posts: 98
Spain
B
brax Offline OP
Junior Member
brax  Offline OP
Junior Member
B

Joined: Aug 2017
Posts: 98
Spain
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();
   }
}


Re: Asset list [Re: brax] #467958
09/11/17 00:40
09/11/17 00:40
Joined: Feb 2017
Posts: 664
Chicago
AndrewAMD Online
User
AndrewAMD  Online
User

Joined: Feb 2017
Posts: 664
Chicago
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.

Re: Asset list [Re: AndrewAMD] #467965
09/11/17 10:03
09/11/17 10:03
Joined: Aug 2017
Posts: 98
Spain
B
brax Offline OP
Junior Member
brax  Offline OP
Junior Member
B

Joined: Aug 2017
Posts: 98
Spain
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.


Last edited by brax; 09/11/17 10:03.
Re: Asset list [Re: brax] #467966
09/11/17 10:48
09/11/17 10:48
Joined: Feb 2017
Posts: 664
Chicago
AndrewAMD Online
User
AndrewAMD  Online
User

Joined: Feb 2017
Posts: 664
Chicago
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.

Re: Asset list [Re: AndrewAMD] #467973
09/11/17 17:35
09/11/17 17:35
Joined: Aug 2017
Posts: 98
Spain
B
brax Offline OP
Junior Member
brax  Offline OP
Junior Member
B

Joined: Aug 2017
Posts: 98
Spain
Thank you very much! This is what i was looking for.

Now my code looks way more elegant! laugh

Re: Asset list [Re: brax] #467974
09/11/17 18:43
09/11/17 18:43
Joined: Feb 2017
Posts: 664
Chicago
AndrewAMD Online
User
AndrewAMD  Online
User

Joined: Feb 2017
Posts: 664
Chicago
Yay! Actually, I might use this setup myself, especially for larger portfolio jobs.

Re: Asset list [Re: AndrewAMD] #477153
05/24/19 15:45
05/24/19 15:45
Joined: Oct 2018
Posts: 11
J
JamesHH Offline
Newbie
JamesHH  Offline
Newbie
J

Joined: Oct 2018
Posts: 11
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?


Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1