Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (TipmyPip, AndrewAMD, Quad, aliswee, degenerate_762), 970 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 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: 102
Spain
B
Brax Offline OP
Member
Brax  Offline OP
Member
B

Joined: Aug 2017
Posts: 102
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: 1,718
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,718
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: 102
Spain
B
Brax Offline OP
Member
Brax  Offline OP
Member
B

Joined: Aug 2017
Posts: 102
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: 1,718
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,718
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: 102
Spain
B
Brax Offline OP
Member
Brax  Offline OP
Member
B

Joined: Aug 2017
Posts: 102
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: 1,718
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,718
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: 102
Spain
B
Brax Offline OP
Member
Brax  Offline OP
Member
B

Joined: Aug 2017
Posts: 102
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: 1,718
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,718
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: 72
J
JamesHH Offline
Junior Member
JamesHH  Offline
Junior Member
J

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


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1