Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, Ayumi), 853 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
lorikob361, LucasJoshua, Baklazhan, Hanky27, firatv
19054 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Multiple assets in a single algo #457054
12/22/15 05:05
12/22/15 05:05
Joined: Feb 2014
Posts: 73
Montreal, Qc Canada
F
Finstratech Offline OP
Junior Member
Finstratech  Offline OP
Junior Member
F

Joined: Feb 2014
Posts: 73
Montreal, Qc Canada
Please help,
My single strategy with multiple assets in a loop such as:

while(loop(
"EUR/USD",
"USD/CHF",
"GBP/USD"))

does not work. It only gives results for a selected asset from the scroll box.

What changes should I make?
Thanks

Re: Multiple assets in a single algo [Re: Finstratech] #457059
12/22/15 16:51
12/22/15 16:51
Joined: Dec 2013
Posts: 568
Fuerth, DE
Sphin Offline
User
Sphin  Offline
User

Joined: Dec 2013
Posts: 568
Fuerth, DE
Did you try it with:

while(asset(loop("EUR/USD","USD/CHF","GBP/USD")))

? If this does not work too, I propose you post the whole code, you can surely leave out the strategy-part but the loop-part would be the interesting one.

Re: Multiple assets in a single algo [Re: Sphin] #457060
12/22/15 17:03
12/22/15 17:03
Joined: May 2015
Posts: 390
Czech Republic
G
Grat Offline
Senior Member
Grat  Offline
Senior Member
G

Joined: May 2015
Posts: 390
Czech Republic
I have ale this problem:
<code>
#define nORD 10

int nIndex = 1;
TRADE* myOrder[nORD][3];

function openLong(){
// first try, if have all asset OK
// only all 3 asset open together

if ( asset("EUR/USD")==0) return;
printf("\nPrice EUR(USD: %f",price(0));

if ( asset("EUR/GBP")==0) return;
printf("\nPrice EUR/GBP: %f",price(0));

if ( asset("GBP/USD")==0) return;
printf("\nPrice GBP/USD: %f",price(0));

// open order
asset("EUR/USD");
myOrder[nIndex][0]=enterLong(10);
printf("\nPrice EUR/USD: %f ID:%s",price(0),TradeID);
// next line i trying before - also not working
// printf("\nPrice EUR/USD: %f ID:%s",price(0),myOrder[nIndex][1]->nID);


asset("EUR/GBP");
myOrder[nIndex][1]=enterShort(7);
printf("\nCena EUR/GBP: %f ID:%s",price(0),myOrder[nIndex][1]->nID);

asset("GBP/USD");
myOrder[nIndex][2]=enterShort(7);
printf("\nCena GBP/GBP: %f ID:%s",price(0),myOrder[nIndex][2]->nID);

aIndex[nIndex]=1;
//printf("58 --- open long %d ----",nIndex);

}
</code>

output in diag:

Price EUR(USD: 1.125805
Price EUR/GBP: 0.734388
Price GBP/USD: 1.531332
Trade: units 871.00 price 1.12579 lots 10
[EUR/USD::L1001] Long 10@1.1258 at 05:00
Price EUR/UES: 1.125805 ID:(null) <= from this: printf("\nPrice EUR/USD: %f ID:%s",price(0),TradeID);
Trade: units 926.30 price 0.73469 lots 7
[EUR/GBP::S1002] Short 7@0.7347 at 05:00

during this line is crash script
printf("\nCena EUR/GBP: %f ID:%s",price(0),myOrder[nIndex][1]->nID);
problem is in => myOrder[nIndex][1]->nID

this problem is only in the test mode, in the trade mode working normal.

Milan

Re: Multiple assets in a single algo [Re: Grat] #457061
12/22/15 18:21
12/22/15 18:21
Joined: Dec 2013
Posts: 568
Fuerth, DE
Sphin Offline
User
Sphin  Offline
User

Joined: Dec 2013
Posts: 568
Fuerth, DE
I'm not really a hero of variables but you try to print an int with %s, isn't %d the right way?

Re: Multiple assets in a single algo [Re: Sphin] #457064
12/22/15 20:57
12/22/15 20:57
Joined: Feb 2014
Posts: 73
Montreal, Qc Canada
F
Finstratech Offline OP
Junior Member
Finstratech  Offline OP
Junior Member
F

Joined: Feb 2014
Posts: 73
Montreal, Qc Canada
Hello Sphin,
I have tried both ways and it still doesn't work. I find that your suggested line works in strategies with multiple algos. I need it to work on a single algo.

Please take a look at an example below.
Thanks

Code:
// Trade Every Minute for Test Purposes ///////////////////

function run()
{
 //while(asset(loop("EUR/USD","USD/CHF","GBP/USD")))
		
   while(loop("EUR/USD","USD/CHF","GBP/USD"))
		
		
	BarPeriod = 60;
	NumYears = 1;
	Weekend = 0;
	Verbose = 15;
	//asset("EUR/USD");
	//set(NFA);
	//if(is(FIRSTRUN)) brokerCommand(SET_MAGIC,4711007);
	set(LOGFILE);
	MaxBars = 400;
	

	Lots = 5;
	Stop = TakeProfit = 10*ATR(20);
	if(NumOpenTotal > 2) {
		exitLong();
		exitShort();
	} else if (!is(LOOKBACK)) {
		printf("\nLots %.0f, Stop %.5f, PIPCost %.4f, Risk %.2f",
			Lots, Stop, PIPCost, Lots*(Stop+Spread)/PIP*PIPCost);
		if(price(0) > price(1)) 
		//if(random() > 0) 
			enterLong();
		else 
			enterShort();
	}
	
}


Re: Multiple assets in a single algo [Re: Finstratech] #457065
12/22/15 21:21
12/22/15 21:21
Joined: Dec 2013
Posts: 568
Fuerth, DE
Sphin Offline
User
Sphin  Offline
User

Joined: Dec 2013
Posts: 568
Fuerth, DE
I don't know if this is what you want but this way at least a portfolio is traded:

Code:
function run()
{
 	
	BarPeriod = 60;
	NumYears = 1;
	Weekend = 0;
	Verbose = 15;
	//asset("EUR/USD");
	//set(NFA);
	//if(is(FIRSTRUN)) brokerCommand(SET_MAGIC,4711007);
	set(LOGFILE);
	MaxBars = 400;
	
     while(asset(loop("EUR/USD","USD/CHF","GBP/USD"))) {
		
	Lots = 5;
	Stop = TakeProfit = 10*ATR(20);
	if(NumOpenTotal > 2) {
		exitLong();
		exitShort();
	} else if (!is(LOOKBACK)) {
		printf("\nLots %.0f, Stop %.5f, PIPCost %.4f, Risk %.2f",
			Lots, Stop, PIPCost, Lots*(Stop+Spread)/PIP*PIPCost);
		if(price(0) > price(1)) 
		//if(random() > 0) 
			enterLong();
		else 
			enterShort();
	}
      }	
}



Organizing and structuring portfolio trading is pretty good explained in workshop 6.

Re: Multiple assets in a single algo [Re: Sphin] #457066
12/22/15 21:37
12/22/15 21:37
Joined: Feb 2014
Posts: 73
Montreal, Qc Canada
F
Finstratech Offline OP
Junior Member
Finstratech  Offline OP
Junior Member
F

Joined: Feb 2014
Posts: 73
Montreal, Qc Canada
Sphin, yes that's what I wanted.

Oh the headaches this curvy bracket caused me.

Thanks a lot.

ps. I was referring to workshop 6 among other "Tips and Tricks".

Re: Multiple assets in a single algo [Re: Sphin] #457071
12/23/15 00:54
12/23/15 00:54
Joined: Feb 2014
Posts: 73
Montreal, Qc Canada
F
Finstratech Offline OP
Junior Member
Finstratech  Offline OP
Junior Member
F

Joined: Feb 2014
Posts: 73
Montreal, Qc Canada
Well, this is embarrassing. This fix did not work with an example I was working on!

It seems that set(TICKS) flag is preventing it from working.
When the flag is commented out, it only trades one asset.
When the flag is not commented out, testing does not work at all.

See code below.

JCL please help.

(edit) PS. This is Renko bar code from the manual with random trading algo also from the manual.

Code:
int bar(vars Open, vars High, vars Low, vars Close)
{	
	var BarRange = 0.0030;
	var OpenDiff;
	var CloseDiff;
	
	OpenDiff = abs(Close[0]-Open[1]);
	CloseDiff = abs(Close[0]-Close[1]);
	if(OpenDiff < CloseDiff) {
	// If this matches we have a valley or peak
	  Open[0] = Open[1];
	} else {                              
	// This is for when we are moving with the trend
	  Open[0] = round(Close[1],BarRange);
	}
	if(Close[0]-Open[0] >= BarRange) {  // Going up
	  Close[0] = Open[0]+BarRange;
	  High[0] = Close[0];
	  Low[0] = Open[0];
	  return 1;
	}
	if(Open[0]-Close[0] >= BarRange) { // Going Down
	  Close[0] = Open[0]-BarRange;
	  High[0] = Open[0];
	  Low[0] = Close[0];
	  return 1;
	}
	return 4;
}

function run()
{
	set(PLOTNOW);
	set(TICKS);
	BarPeriod = 60;
	StartDate = 2015;
  	Weekend = 0;
	Verbose = 15;
	
	//asset("EUR/USD");
	//set(NFA);
	//if(is(FIRSTRUN)) brokerCommand(SET_MAGIC,4711007);
	set(LOGFILE);
  
   vars Open = series(priceOpen());
	vars High = series(priceHigh());
	vars Low = series(priceLow());
	vars Close = series(priceClose());
	vars Price = series(price());
	ColorUp = BLUE;
	ColorDn = MAGENTA;

	
	while(asset(loop("EUR/USD","GBP/USD","AUD/USD","USD/CAD"))){

	Lots = 10;
	Stop = 5*ATR(20);
	TakeProfit = 5*ATR(20);
	if(NumOpenTotal > 2) {
		exitLong();
		exitShort();
	} else if (!is(LOOKBACK)) {
		printf("\nLots %.0f, Stop %.5f, PIPCost %.4f, Risk %.2f",
			Lots, Stop, PIPCost, Lots*(Stop+Spread)/PIP*PIPCost);
		if(price(0) > price(1))//&& between(Close[0],rRealLowerBand,rRealUpperBand)) 
		//if(random() > 0) 
			enterLong();
		else 
			enterShort();
	}
  }
  
	PlotScale = 6;
	PlotWidth = 10000;
	PlotHeight1 = 500;
	PlotHeight2 = 200;
}


Last edited by Finstratech; 12/23/15 00:57.
Re: Multiple assets in a single algo [Re: Finstratech] #457072
12/23/15 08:27
12/23/15 08:27
Joined: May 2015
Posts: 390
Czech Republic
G
Grat Offline
Senior Member
Grat  Offline
Senior Member
G

Joined: May 2015
Posts: 390
Czech Republic
Hi,

try this code:

....
if (!is(LOOKBACK)){

while(asset(loop("EUR/USD","GBP/USD","AUD/USD","USD/CAD"))){
printf("\nPrice %s: %f",Asset,price(0));
....
....
} // end while
}// end if

Milan


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1