1 registered members (3s05bmmc),
745
guests, and 3
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
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
Grat
Senior Member
|
Senior Member
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: Sphin]
#457064
12/22/15 20:57
12/22/15 20:57
|
Joined: Feb 2014
Posts: 73 Montreal, Qc Canada
Finstratech
OP
Junior Member
|
OP
Junior Member
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
// 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
User
|
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:
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]
#457071
12/23/15 00:54
12/23/15 00:54
|
Joined: Feb 2014
Posts: 73 Montreal, Qc Canada
Finstratech
OP
Junior Member
|
OP
Junior Member
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.
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.
|
|
|
|