Gamestudio Links
Zorro Links
Newest Posts
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, dr_panther), 1,282 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Issue with Fill and restricting trade numbers #471756
03/19/18 08:48
03/19/18 08:48
Joined: Mar 2017
Posts: 65
G
Ger1 Offline OP
Junior Member
Ger1  Offline OP
Junior Member
G

Joined: Mar 2017
Posts: 65
Hi,

at the moment I am testing strategies for certain stock universes such as the SP500.

I use daily bars, signals occur at the close and I want to open the trade at the next bar's open.
I am able to this by setting Fill=3.

However, this has unintended consequences. I've restricted NumOpenTotal < 5;
This works when Fill is set to its default value but when I set Fill to DELAYED (in order to enter at the open) the more than 5 trades are opened.

Has anyone an idea what the reason for this is?

Re: Issue with Fill and restricting trade numbers [Re: Ger1] #471759
03/19/18 11:00
03/19/18 11:00
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
Sure, as long as the trade is not yet opened, NumOpenTotal is unchanged. You must also check for NumPendingTotal.

Re: Issue with Fill and restricting trade numbers [Re: jcl] #471820
03/21/18 00:37
03/21/18 00:37
Joined: Mar 2017
Posts: 65
G
Ger1 Offline OP
Junior Member
Ger1  Offline OP
Junior Member
G

Joined: Mar 2017
Posts: 65
Thanks jcl, I've tried that before too.

I did following: If((NumOpenTotal+NumPendingTotal)<5 ...

And it works in terms of having not more than 5 open trades.
However, it has unintended consequences. As an example:

Fill = 3;

while(asset(loop("SPX500","US30","NAS100")))
{
Entry = -.008*priceClose();
LifeTime=5;
if((NumOpenTotal+NumPendingTotal)<2) enterLong();
}


If I write the code as above a trade in NAS100 will never be entered as at least 2 pending trades were already entered for SPX500 and US30 (regardless of whether SPX500 and US30 fulfill their entry condition the following bar).

However, that's not what I want. I want to enter 3 pending order but only open maximum 2 trades.

How can that be achieved? I could not find a way with Fill=3.

Thank you.

Re: Issue with Fill and restricting trade numbers [Re: Ger1] #471825
03/21/18 12:47
03/21/18 12:47
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
This is unrelated to pending. If you do not want SPX500 trades to affect NAS100 trades, then do not check for ...Total, but for ...Long and ...Short.

You can get the complete status of all trades with a for(...trades) loop, and this way count and check all conditions that you want.

Re: Issue with Fill and restricting trade numbers [Re: jcl] #471858
03/21/18 21:03
03/21/18 21:03
Joined: Mar 2017
Posts: 65
G
Ger1 Offline OP
Junior Member
Ger1  Offline OP
Junior Member
G

Joined: Mar 2017
Posts: 65
No that's not what I want either.

As in the example above, my intention is following:

1) enterLong at the next day's bar but only if the price is 0.8% lower than today's close

2) do not open more than 2 trades


How can this be achieved. If I use ...Long and ...Short instead of ...Total 2 trades per asset would be opened which ads up to 6 in total.

A specific example, what if only "US30" and "NAS100" fall another 0.8% at the next bar. I only want those 2 to be entered.

What if all 3 fall 0.8% at the next bar. In this case I'd only like to enter "SPX500" and "US30" as I do not want to open more than 2 trades and those 2 assets are the first in the loop.

Thanks a lot!

Re: Issue with Fill and restricting trade numbers [Re: Ger1] #471859
03/21/18 21:49
03/21/18 21:49
Joined: Sep 2003
Posts: 929
Spirit Offline

Moderator
Spirit  Offline

Moderator

Joined: Sep 2003
Posts: 929
You can check in a tmf if 2 trades are open, then cancel all pending trades.

Re: Issue with Fill and restricting trade numbers [Re: Spirit] #471860
03/21/18 23:37
03/21/18 23:37
Joined: Mar 2017
Posts: 65
G
Ger1 Offline OP
Junior Member
Ger1  Offline OP
Junior Member
G

Joined: Mar 2017
Posts: 65
Hi Spirit,

thanks a lot, great advice. I think I got it working.

I used following code:

int tmf()
{
if(NumOpenTotal==2 and TradeIsPending) return 1;
else return 0;
}


function run();
{
...
set(TICKS);
BarPeriod=1440;

Fill = 3;

while(asset(loop("SPX500","US30","NAS100")))
{
Entry = -.008*priceClose();
LifeTime=5;
enterLong(tmf);
}
...
}


Cheers


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