Gamestudio Links
Zorro Links
Newest Posts
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
Data from CSV not parsed correctly
by jcl. 04/20/24 08:32
Zorro FIX plugin - Experimental
by jcl. 04/20/24 08:30
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (7th_zorro, 1 invisible), 581 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
RiskVal and for(open_trades) #457893
02/05/16 14:22
02/05/16 14:22
Joined: Feb 2016
Posts: 5
O
Opentrades Offline OP
Newbie
Opentrades  Offline OP
Newbie
O

Joined: Feb 2016
Posts: 5
Hello,

I have some difficulties to use the variable RiskVal. It works as expected for a simple 1 lot entry/Exit system, but with a more complex system with multiple entry conditions and part Exit it does not. It seems to be a summation of all risks (open and closed). Even when there ist no open trade the risk in nonzero.
Therefore i tried to use a for(open_trades) command. I copied the second example from the manual (Sum of Open profits) into my script - Without modifications. The Script crashs with error111.
Both problems occur in Zorro 1.34 and 1.4.
Question: can anyone explain this behaviour? Hopefully someone can help me to solve these problems.

Regards, Opentrades

Re: RiskVal and for(open_trades) [Re: Opentrades] #457909
02/06/16 09:33
02/06/16 09:33
Joined: Feb 2016
Posts: 5
O
Opentrades Offline OP
Newbie
Opentrades  Offline OP
Newbie
O

Joined: Feb 2016
Posts: 5
Here is an example script based on the Luxor example script.

The commented out entry condition cause an error of the for(open_trades) loop. The TradeProfit keyword cause this error. Why?
The riskVal increases in this example code. Why?
Any comment is appreciated. Thanks.
Regards, Opentrades

script:
// Luxor system by Jaeckle/Tomasini /////////////
// Make a system profitable by creative selection
// of start and end date

function run()
{
StartDate = 2004;
EndDate = 2015;
BarPeriod = 30;
LookBack = 30;
asset("GBP/USD");

// no trade costs...
Spread = 0;
Slippage = 0;
RollLong = RollShort = 0;

vars Price = series(priceClose()),
Fast = series(SMA(Price,3)),
Slow = series(SMA(Price,30));

static var BuyLimit,SellLimit,BuyStop,SellStop;

if(crossOver(Fast,Slow)) {
BuyStop = priceHigh() + 1*PIP;
BuyLimit = priceHigh() + 5*PIP;
}
if(crossUnder(Fast,Slow)) {
SellStop = priceLow() - 1*PIP;
SellLimit = priceLow() - 5*PIP;
}

if(!NumOpenLong && Fast[0] > Slow[0] && Price[0] < BuyLimit)
enterLong(2,BuyStop,2*ATR(20));
// if(TradeProfit>0&&NumOpenLong>0 && Fast[0] > Slow[0] && Price[0] < BuyLimit)
// enterLong(2,BuyStop,2*ATR(20));
if(!NumOpenShort && Fast[0] < Slow[0] && Price[0] > SellLimit)
exitLong(0,0,1);
if(NumOpenLong>3 && Fast[0] < Slow[0] && Price[0] > SellLimit)
exitLong();
var val = 0;
string CurrentAsset = Asset;
for(open_trades)
if(strstr(Asset,CurrentAsset) && TradeIsOpen && !TradeIsPhantom)
val += TradeResult;


PlotWidth = 1000;
PlotBars = 800; // plot all
plot("Risk", RiskVal,NEW,GREEN);
plot("nLong", NumOpenLong,NEW,GREEN);
plot("value", val,NEW,GREEN);
}

Re: RiskVal and for(open_trades) [Re: Opentrades] #457910
02/06/16 09:48
02/06/16 09:48
Joined: Jul 2000
Posts: 27,982
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,982
Frankfurt
Thanks for the info. I believe you've found a bug with RiskVal. It does not calculate the risk of partially closed trades. I'll put up a notice for the developers to fix this for the next update.

Until then you need indeed a for(open_trades) loop for calculating the current risk. I can't see an obvious bug in the manual example, though. So your crash might have a different reason. The code you've posted doesn't crash here.



Moderated by  Petra 

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