Gamestudio Links
Zorro Links
Newest Posts
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
folder management functions
by 7th_zorro. 04/15/24 10:10
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
LPDIRECT3DCUBETEXTUR
E9

by Ayumi. 04/12/24 11:00
Sam Foster Sound | Experienced Game Composer for Hire
by titanicpiano14. 04/11/24 14:56
SGT_FW
by Aku_Aku. 04/10/24 16:09
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (7th_zorro, Quad), 373 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
11honza11, ccorrea, sakolin, rajesh7827, juergen_wue
19045 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
IB wrong stop #467082
07/14/17 21:52
07/14/17 21:52
Joined: Nov 2016
Posts: 103
NSW
V
vinsom Offline OP
Member
vinsom  Offline OP
Member
V

Joined: Nov 2016
Posts: 103
NSW
Hi,
I'm getting some wrong stop values with IB.
Happens randomly, now happened with MNST, happened before with other stocks.

I calculate the stop and the trail with the lines below:

Stop=priceClose()-(3*ATR(30));
Trail=ATR(2);

I also tried previously with this line below but getting same errors too:
Stop=3*ATR(30);

This is extracted from the log:

[MNST::L8573] Trail 7@50.4100 Stop 20042.13 at 11:14:42
[MNST::L8573] Trail 7@50.4100 Stop 38037.55 at 11:40:07
Stop 38037.5547 hit at 30823.4707/30823.470730823.4707/30823.4707
BrokerSell MNST: 71774 ms

Anyone from the Zorro team has any idea why is this happening ?
Log file is attached(renamed to .h to allow upload)

Thanks
Vincenzo

Attached Files
MVOreal.h (91 downloads)
Re: IB wrong stop [Re: vinsom] #467141
07/18/17 06:36
07/18/17 06:36
Joined: Jul 2000
Posts: 27,978
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,978
Frankfurt
Can you post the script? Otherwise it's hard to tell where the stop became wrong.

Re: IB wrong stop [Re: jcl] #467175
07/19/17 11:02
07/19/17 11:02
Joined: Nov 2016
Posts: 103
NSW
V
vinsom Offline OP
Member
vinsom  Offline OP
Member
V

Joined: Nov 2016
Posts: 103
NSW
Hi Jcl,
There is only one line of code where I set the Stop equal to a value.
And looks like this is happening only in live trading with IB.
I checked the test log and all stops hit have normal values.

Script is below: Is just the Get Rich slowly modified for trading:

#define LEVERAGE 2 // 1:4 leverage
#define DAYS 252 // 1 year
#define NN 300 // max number of assets

string Names[NN];
vars Returns[NN];
var Means[NN];
var Covariances[NN][NN];
var Weights[NN];

//////////////////////////////////////////////////////

function run()
{
BarPeriod = 1440;
LookBack = DAYS;
NumYears = 5;
Verbose = 30;
set(PRELOAD); // allow extremely long lookback period



var TotalCapital = slider(1,1000,0,10000,"Capital","Total capital to distribute");
var VFactor = slider(2,10,0,100,"Risk","Variance factor");

int N = 0;
assetList("AssetsZ8NasdaqStocks.csv");
while (asset(loop(Assets)))
{
Names[N] =Asset;

Returns[N] = series((priceClose(0)-priceClose(1))/priceClose(1));
if(N++ >= NN) break;
}


int i,j;
for(i=0; i<N; i++)
{
Means[i] = Moment(Returns[i],LookBack,1);
for(j=0; j<N; j++)
Covariances[N*i+j] = Covariance(Returns[i],Returns[j],LookBack);
}

var BestVariance = markowitz(Covariances,Means,N,0.5);
var MinVariance = markowitzReturn(0,0);
markowitzReturn(Weights,MinVariance+VFactor/100.*(BestVariance-MinVariance));

for(i=0; i<N; i++)
{
asset(Names[i]);
Stop=priceClose()-(3*ATR(30));
Trail=ATR(2);
MarginCost = priceClose()/LEVERAGE;
int Position = TotalCapital*Weights[i]/MarginCost;

//printf("n%s: %d Contracts at %.0f$",Names[i],Position,priceClose());

if(tdm() == 1 )
{
if(Position>LotsPool)
{
enterLong(Position-LotsPool);//Position-LotsPool);

}
else if(Position<LotsPool)
{
exitLong(0,0,LotsPool-Position);//0,0,LotsPool-Position);
}
}
}

}



THanks
Vincenzo

Re: IB wrong stop [Re: vinsom] #467213
07/21/17 08:27
07/21/17 08:27
Joined: Jul 2000
Posts: 27,978
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,978
Frankfurt
I see indeed no problem in the code at first glance. The stop is initially ok and then wrong trailed due to a wrong price for MSFT.

Which Zorro version is that? Do you trade via TWS or via Gateway?

Re: IB wrong stop [Re: jcl] #467215
07/21/17 10:01
07/21/17 10:01
Joined: Nov 2016
Posts: 103
NSW
V
vinsom Offline OP
Member
vinsom  Offline OP
Member
V

Joined: Nov 2016
Posts: 103
NSW
Hi Jcl,
Is Zorro 1.58.
And I'm using the Gateway.
For the possible wrong price, is there an outlier control in the IB plugin ?

Thanks
VIncenzo

Re: IB wrong stop [Re: vinsom] #467221
07/21/17 11:31
07/21/17 11:31
Joined: Jul 2000
Posts: 27,978
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,978
Frankfurt
Not in the plugin, but Zorro has an outlier control. It does not look like an outlier, but more like a permanently wrong price. Can you contact Support, and send them the .diag file if you have one?

Re: IB wrong stop [Re: jcl] #467225
07/21/17 12:01
07/21/17 12:01
Joined: Nov 2016
Posts: 103
NSW
V
vinsom Offline OP
Member
vinsom  Offline OP
Member
V

Joined: Nov 2016
Posts: 103
NSW
Just sent to support.
Thanks
Vincenzo


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1