Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (opm), 778 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Duplicate elements in all_trades w/ Entry + EntryTime limits #446526
10/20/14 02:37
10/20/14 02:37
Joined: Sep 2013
Posts: 504
California
G
GPEngine Offline OP
User
GPEngine  Offline OP
User
G

Joined: Sep 2013
Posts: 504
California
This simple Strategy does enterLong unconditionally at every bar. Then in EXITRUN it prints to file one line for every value in the all_trades list. I ran it against EUR/USD using official data. Then I analyzed the output, counting the occurrences of Bar# in the file.

Observed:
Repeated values for Bar # in the output, each with different values for TradeProfit.

Expected:
No more than one value per bar in the simulation, with an reliable & final value for TradeProfit..
Code:
#define BUFFSIZE_S 300
char value[BUFFSIZE_S];

function write_line() {
  sprintf(value, "%u,%f\n", TradeBarOpen, (var)TradeUnits);
  file_append("all_trades.txt", value);
}

function run() {
  StartDate = 20140801;
  EndDate = 20140901;
  EntryTime = 2;

  var atrx = ATR(200);
  Entry = atrx * 1.0;
  Stop = atrx * 3.5;

  if (is(INITRUN)) {
    file_delete("all_trades.txt");
  }

  enterLong();

  if (is(EXITRUN)) {
    for (all_trades) {
      write_line();
    }
  }
}

Code:
$ cut -d',' -f1 all_trades.txt | sort | uniq -c | sort -rn | head
      3 807
      2 993
      2 990
      2 985
      2 972
      2 957
      2 953
      2 921
      2 836
      2 783

Code:
$ grep 807 all_trades.txt 
807,772.900024,0.000000
807,772.900024,-2.858410
807,772.900024,-2.866854



What's happening, here?

Re: Duplicate elements in all_trades w/ Entry + EntryTime limits [Re: GPEngine] #446602
10/22/14 17:23
10/22/14 17:23
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
Hm, can you explain the problem in more detail? Trades usually have different profits - that's due to the asset price differences at entry and exit. And there can be several trades at the same bar. What did you expect instead and why?

Re: Duplicate elements in all_trades w/ Entry + EntryTime limits [Re: jcl] #446613
10/23/14 04:07
10/23/14 04:07
Joined: Sep 2013
Posts: 504
California
G
GPEngine Offline OP
User
GPEngine  Offline OP
User
G

Joined: Sep 2013
Posts: 504
California
How can there be three trades opened at bar 807?

There is only one entry command per bar and EntryTime = 2
so there can be at most 2 pending trades in a given bar.
In bar 807 there were at least 3. How is that possible?

Re: Duplicate elements in all_trades w/ Entry + EntryTime limits [Re: GPEngine] #446616
10/23/14 10:44
10/23/14 10:44
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
EntryTime = 2 can delay a trade by 0, 1, or 2 bars. After 2 bars the trade is cancelled. I have not examined the pending machanism in detail, so I can only make an educated guess here, but I suppose the 3 trades on bar 807 come from the current, the previous, and the previous-plus-one bar. At least that's what I normally would expect from my understanding of pending trades.

You can easily test this by setting EntryTime = 1 - you should then have only 2 trades on bar 807.

Re: Duplicate elements in all_trades w/ Entry + EntryTime limits [Re: jcl] #446620
10/23/14 14:23
10/23/14 14:23
Joined: Sep 2013
Posts: 504
California
G
GPEngine Offline OP
User
GPEngine  Offline OP
User
G

Joined: Sep 2013
Posts: 504
California
Good guess, but no.
With EntryTime = 1, there is only at most 1 trade opened per bar, including 807.
Code:
$ grep 807 all_trades.txt 
807,772.900024,-2.866854

According to your description, with one enter* command per bar,
  • With EntryTime = 2, at a given bar opened trades could come from the current, the previous, and the previous-plus-one bar
  • With EntryTime = 1, at a given bar opened trades could come from the current, and the previous bar

This implies that
  • With EntryTime = 0, at a given bar opened trades could come from the current bar

But a simple test proves that EntryTime = 0 makes Zorro NEVER enter any trades.

Re: Duplicate elements in all_trades w/ Entry + EntryTime limits [Re: GPEngine] #446621
10/23/14 14:56
10/23/14 14:56
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
Your code can indeed not open a trade at the same bar because you're using an entry distance. This adds something to the price. So the price can never met this condition immediately and enter a trade.

For opening 3 trades at one bar, you had to use an absolute entry limit, not a distance. Your current code can only open 2. The 3 trades on bar 807 are apparently caused by your enumeration code that also writes never entered trades. Write only open and closed trades -> see TradeIsOpen and TradeIsClosed.

Re: Duplicate elements in all_trades w/ Entry + EntryTime limits [Re: jcl] #446634
10/24/14 03:35
10/24/14 03:35
Joined: Sep 2013
Posts: 504
California
G
GPEngine Offline OP
User
GPEngine  Offline OP
User
G

Joined: Sep 2013
Posts: 504
California
I see. Sorry for wasting your time on this.

First, I was once again confused by TradeBarOpen. I will try to understand and remember that it is the time the trade is Opened, not the time the trade is Entered, and that there is no such thing as TradeBarEntry. I guess if I want to record the Entry bar number for each trade, for later tracking, I will have to store it myself in one of the TradeVar positions.

Then, as you figured out, I was confused about EntryTime. I had never seen EntryTime = 0 produce any trades, but clearly it can. I wonder why the default is 1 and not 0.

Re: Duplicate elements in all_trades w/ Entry + EntryTime limits [Re: GPEngine] #446643
10/24/14 12:57
10/24/14 12:57
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
The default is 1 because that's what you normally want - at 0, the trade would either enter or not, but would not wait.


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