Gamestudio Links
Zorro Links
Newest Posts
Z9 getting Error 058
by k_ivan. 04/25/26 19:13
ZorroGPT
by TipmyPip. 04/25/26 16:09
Stooq now requires an API key
by jcl. 04/13/26 09:42
Strange "Alien" Skull created with >Knubber<
by NeoDumont. 04/10/26 18:58
400 free seamless texture pack downl. here !
by NeoDumont. 04/08/26 19:55
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
2 registered members (TipmyPip, 1 invisible), 3,464 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
valino, juergenwue, VladMak, Geir, ondrej
19209 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Please help me understand Virtual Hedging #431613
10/20/13 16:34
10/20/13 16:34
Joined: Sep 2013
Posts: 504
California
G
GPEngine Offline OP
User
GPEngine  Offline OP
User
G

Joined: Sep 2013
Posts: 504
California
I read the manual pages about Virtual Hedging, Phantom, enterLong/Short, and the guide to reading the trade log.
http://zorro-trader.com/manual/en/hedge.htm
http://zorro-trader.com/manual/en/lots.htm#phantom
http://zorro-trader.com/manual/en/buylong.htm
http://zorro-trader.com/manual/en/trading.htm

This is an awesome feature, by the way. I'm very excited by it. laugh

I thought I had a good grasp on Virtual Hedging. But I'm seeing some behavior which surprises me. Can you please explain it?
Using
Code:
set(LOGFILE+TICKS);
Verbose = 2;
BarPeriod = 60;
Hedge = 4;
ExitTime = 2;


I try to enter two positions at a specific 2013 EUR/USD Hourly Bar [2604: Thu 06.06. 12:00]
Code:
enterLong(0, 1.312090, 0, 0.004361);
enterShort(0, 1.312090, 0, 0.002509);



Looking ahead for our reference, the next bar has the following characteristics:
OHLC[-1]: 1.312090 1.316780 1.309290 1.315180
O[-2]: 1.315180
I've chosen values for Entry and TakeProfit based on this advance knowledge, for demonstration purposes.

I expect that, at least in concept, two opposite positions will be entered at next bar's open (1.312090). The Long will exit when (1.312090 + 0.004361 = 1.316451) is reached. The Short will exit when (1.312090 - 0.002509 = 1.309581) is reached. I know these exit conditions will be met within the bar because I've peeked into the future, i.e., L_next=1.309290 < 1.309581 < 1.316451 < H_next=1.316780.

Instead, I find that the exit condition of the Short is not met within the bar. The simulator exits the position, unprofitably, at the start of the next bar (due to ExitTime=2) instead of @1.309581. This results in profit -3.39 at 13:00 instead of +2.23 at 12:32.

Here's the Trade Log:
Code:
[2604: Thu 06.06. 12:00]  1.31133-1.31111-1.31261-1.31209
{EUR/USD::l} Long 1@1.3121 Entry stop
{EUR/USD::l} Entry stop 1.3121 hit at 12:00
{EUR/USD::l0401} Long 1@1.3121 Risk 13 at 12:00
[EUR/USD::L0402] Long 1@1.3121 Risk 263 at 12:00
{EUR/USD::s} Short 1@1.3121 Entry stop
{EUR/USD::s} Entry stop 1.3121 hit at 12:00
{EUR/USD::s0403} Short 1@1.3121 Risk 13 at 12:00
[EUR/USD::L0402] Sell 1@1.3121: -0.18 at 12:00
{EUR/USD::l0401} Target 1@1.3165: +4.23 at 12:48
[EUR/USD::S0504] Short 1@1.3152 Risk 265 at 12:48

[2605: Thu 06.06. 13:00]  -2p 0/2
{EUR/USD::s0403} Cover 1@1.3152: -3.39 at 13:00
[EUR/USD::S0504] Cover 1@1.3152: -0.20 at 13:00



Ignoring this problem for now, there is another confusing thing. Please draw your attention to the Net trades. Why do they both exit at their entry values? Why do the profits of the Phantom trades not sum to roughly the same as the profits of the Net trades? Let me group them by type to make it clearer:
Code:
Phantom Trades:
  Long:
    {EUR/USD::l} Entry stop 1.3121 hit at 12:00
    {EUR/USD::l} Long 1@1.3121 Entry stop
    {EUR/USD::l0401} Long 1@1.3121 Risk 13 at 12:00
    {EUR/USD::l0401} Target 1@1.3165: +4.23 at 12:48
  Short:
    {EUR/USD::s} Entry stop 1.3121 hit at 12:00
    {EUR/USD::s} Short 1@1.3121 Entry stop
    {EUR/USD::s0403} Short 1@1.3121 Risk 13 at 12:00
    {EUR/USD::s0403} Cover 1@1.3152: -3.39 at 13:00

Net Trades:
    [EUR/USD::L0402] Long 1@1.3121 Risk 263 at 12:00
    [EUR/USD::L0402] Sell 1@1.3121: -0.18 at 12:00

    [EUR/USD::S0504] Short 1@1.3152 Risk 265 at 12:48
    [EUR/USD::S0504] Cover 1@1.3152: -0.20 at 13:00



I would expect l0401 + s0403 ~= L0402 + S0504. It doesn't.
l0401 + s0403 = 0.84
L0402 + S0504 = -0.38

What am I missing?
Thanks for your time.

Re: Please help me understand Virtual Hedging [Re: GPEngine] #431627
10/21/13 08:55
10/21/13 08:55
Joined: Jul 2000
Posts: 28,094
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 28,094
Frankfurt
The principle is very simple: Net trades are opened and closed so that the sum of the net lots is at any time identical to the sum of the phantom lots. Of course all trades close at the current price, not at entry price.

Your observation has two reasons. You expect that virtual hedging generates the same profit as real hedging. This is not the case. The profit will be different due to the different number and duration of trades. There is also a second effect that you can see in your example, and that I've added to the manual for clarification:

Quote:
Simulation of virtual hedging in [Test] mode is not 100% accurate when trades open or close inside a bar (f.i. pending trades). Because intrabar simulation handles any trade separately from all other trades (see TMF remarks), the order of opening or closing net trades will be different than in real trading. This can cause a slightly pessimistic simulation. This restriction does not apply to trades that open and close at bar boundaries, i.e. by script commands.


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1