RiskVal and for(open_trades)

Posted By: Opentrades

RiskVal and for(open_trades) - 02/05/16 14:22

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
Posted By: Opentrades

Re: RiskVal and for(open_trades) - 02/06/16 09:33

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);
}
Posted By: jcl

Re: RiskVal and for(open_trades) - 02/06/16 09:48

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.

© 2024 lite-C Forums