Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
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
1 registered members (henrybane), 1,182 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19053 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
logging SPREAD at short trades entry #485373
03/02/22 15:56
03/02/22 15:56
Joined: Dec 2021
Posts: 12
Z
Zendrix Offline OP
Newbie
Zendrix  Offline OP
Newbie
Z

Joined: Dec 2021
Posts: 12
Hello everybody,

I am facing a problem in logging trades for a sharp understanding, what Zorro is dealing with the broker exactly. Ordering, entering, exiting via MT4-bridge works reliable fine.

I enter a trade via

ASSET_long_Ask_at_EntryCmd = priceClose(0);
enterLong(MyTMF_long);


or…

ASSET_short_Ask_at_EntryCmd = priceClose(0);
enterShort(MyTMF_short);


Exactly one command line before enterXX() command is triggered, I record the current valid ASK tick value at which zorro decides to trade.
In the TMFs (I use one TMF for long + one for short) I then let zorro pass me the real ASK at which the broker booked the trade into my account :

<TMF short>

if(TradeIsEntry)
{

ASSET_short_Ask_at_EntryBroker = TradePriceOpen;

}


For long and short trades, zorro can calculate the real slippage for each trade, so I can adjust my trade- and stop- planning.


BUT :

to be in full control of an active trade, I also need to know values of SPREAD during entry and exit. According zorro’s manual TMF-variables


####SNIP###

TradeSpread
The ask-bid spread at the trade opening time for short trades, or at the current and trade closing time for long trades.

###SNAP###




…I try to operate the same way as I did with ASK values.
Tracking the „real SPREAD-value“ works well with all LONG trades, where SPREAD is charged during exit.

But it does not work during the entry of SHORT trades.
I can not get the "SPREAD-value“ from the related trade returned to zorro, via the following code the return value is always zero (0.0)


<TMF short>

if(TradeIsEntry)
{

ASSET_short_Spread_at_EntryBroker = TradeSpread;

}





…the same code inside the long-Trade TMF during exit works fine


<TMF long>

if(TradeIsClosed)
{

ASSET_long_Spread_at_ExitBroker = TradeSpread;

}



Can anybody give me a hint, what I am doing wrong.

Regards
Hendrix

Re: logging SPREAD at short trades entry [Re: Zendrix] #485382
03/03/22 18:46
03/03/22 18:46
Joined: Apr 2008
Posts: 586
Austria
Petra Offline
Support
Petra  Offline
Support

Joined: Apr 2008
Posts: 586
Austria
TradeSpread is not the real entry spread, it is the ask bid difference at the time of entry. I think the broker API plugin does not return the entry spread, only the entry price.

Re: logging SPREAD at short trades entry [Re: Zendrix] #485383
03/03/22 19:26
03/03/22 19:26
Joined: Aug 2017
Posts: 296
Netherlands
G
Grant Offline
Member
Grant  Offline
Member
G

Joined: Aug 2017
Posts: 296
Netherlands
I believe that using 'AskPrice - TradePriceOpen' is pretty accurate, but not always 100%. Maybe Petra can confirm this?

Last edited by Grant; 03/03/22 20:57.
Re: logging SPREAD at short trades entry [Re: Zendrix] #485385
03/04/22 08:43
03/04/22 08:43
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
It is indeed so. The entry price is accurate because it's returned from the broker API, but the spread is not. The spread is taken at the time of entry, but it is not 100% identical to the entry spread due to slippage.

Re: logging SPREAD at short trades entry [Re: Zendrix] #485390
03/04/22 16:42
03/04/22 16:42
Joined: Dec 2021
Posts: 12
Z
Zendrix Offline OP
Newbie
Zendrix  Offline OP
Newbie
Z

Joined: Dec 2021
Posts: 12
Thank you very much for your answers,

I learned : TradeSpread returns the Spread valid at time of trade, not a real Spread returned by Borker API -> I will deal with that.

You have any ideas, why TradeSpread does not return any values during my short_entry_example ?
(tested with different brokers, and different assets, always 0.0)

Is my coding, usage or understanding for TradeSpread wrong ?

best regards
Hendrix

Re: logging SPREAD at short trades entry [Re: Zendrix] #485411
03/08/22 15:17
03/08/22 15:17
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
Short trades enter at bid, so their trade spread is calculated at exit. For getting the ask-bid spread at entry time, use the "Spread", not the "TradeSpread" variable.


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1