Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
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
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (SBGuy), 652 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
How to control entry/exit price? #477487
07/02/19 06:07
07/02/19 06:07
Joined: Jun 2019
Posts: 6
J
JesseL Offline OP
Newbie
JesseL  Offline OP
Newbie
J

Joined: Jun 2019
Posts: 6
Hi,

I'm testing a simple strategy with daily bars. Enter long if today's high is the highest in 20 days, and exit long if today's low is the lowest in 50 days. I want the order and fill prices are the price at the moment when the crossing happens in the day. I tried to use TradePriceOpen and TradePriceClose to set the order price, but the printed TradePriceClose and TradePriceOpen are not the cross level as expected. So are they supposed to use to set the order and fill prices? If not, how to set the order and fill prices? Thanks!

Code
    if (NumOpenLong > 0)   // long position
    {
        if (priceLow() < LL(50-1, 1))  // exit triggered
            {
                TradePriceClose = LL(50-1, 1);
                printf(" Exit Long low=%f order_price=%f ", priceLow(), TradePriceClose);
                exitLong();
                printf(" TradeLots=%d NumOpenLong=%d", TradeLots, NumOpenLong);
            }
    }
    else  if (priceHigh() > HH(20-1, 1))  // entry long triggered
    {
            TradePriceOpen = HH(20-1, 1);
            printf(" Enter Long high=%f order_price=%f q_order=%d", priceHigh(), TradePriceOpen, q_order);
            enterLong(q_order);
            printf(" TradeLots=%d NumOpenLong=%d", TradeLots, NumOpenLong);
    }

Last edited by JesseL; 07/02/19 06:08.
Re: How to control entry/exit price? [Re: JesseL] #477490
07/02/19 09:53
07/02/19 09:53
Joined: Jul 2000
Posts: 27,978
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,978
Frankfurt
For triggering exactly at the crossing, use a tick() function. And it's priceClose(), not TradePriceClose.

Re: How to control entry/exit price? [Re: jcl] #477492
07/02/19 14:38
07/02/19 14:38
Joined: Jun 2019
Posts: 6
J
JesseL Offline OP
Newbie
JesseL  Offline OP
Newbie
J

Joined: Jun 2019
Posts: 6
The data are daily bars, so priceClose() returns EOD price. How can tick() works? Do I have to use tick data?

Re: How to control entry/exit price? [Re: JesseL] #477497
07/02/19 16:01
07/02/19 16:01
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Offline
Serious User
AndrewAMD  Offline
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
priceClose() is different in tick() vs. in run().

In your context, you can use M1 data and use TICKS mode, which will be close enough for your purposes. Using actual tick data would work too, but it would be overkill for a daily bar system.

Re: How to control entry/exit price? [Re: JesseL] #477498
07/02/19 16:51
07/02/19 16:51
Joined: Jun 2019
Posts: 6
J
JesseL Offline OP
Newbie
JesseL  Offline OP
Newbie
J

Joined: Jun 2019
Posts: 6
Please forgive the newbie. I'm confused. Can I use only daily EOD data, not 1min or tick data, with tick() to implement this?
Since I know the exact trade prices, LL(50-1, 1) and HH(20-1, 1), can I just directly set the order or trade price with daily data only, like a limit order?

Last edited by JesseL; 07/02/19 19:12.
Re: How to control entry/exit price? [Re: JesseL] #477507
07/03/19 09:46
07/03/19 09:46
Joined: Jul 2000
Posts: 27,978
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,978
Frankfurt
When you have only EOD data, you can obviously not trigger exactly at the crossing, no matter in which way, at least not in the backtest.

Re: How to control entry/exit price? [Re: JesseL] #478557
11/07/19 17:56
11/07/19 17:56
Joined: Aug 2017
Posts: 294
Netherlands
G
Grant Offline
Member
Grant  Offline
Member
G

Joined: Aug 2017
Posts: 294
Netherlands
What I don't get is this, when Zorro is able to export the exact entry price fillings (testtrades.csv file), then why can't I have access to this data without guesstimating them? I've made a comparison between the estimated fillings ('AskPrice' for long trades and 'AskPrice - Spread' in the Tick() function) and the actual entry fillings from testtrades.csv and found out that 90% of the long entries and 74% of the short entries differ (80 trades with EURUSD_2015.t6) data.

Re: How to control entry/exit price? [Re: JesseL] #478558
11/08/19 14:16
11/08/19 14:16
Joined: Jul 2000
Posts: 27,978
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,978
Frankfurt
Maybe you missed this page: https://manual.zorro-project.com/trade.htm

Re: How to control entry/exit price? [Re: jcl] #478562
11/09/19 15:33
11/09/19 15:33
Joined: Aug 2017
Posts: 294
Netherlands
G
Grant Offline
Member
Grant  Offline
Member
G

Joined: Aug 2017
Posts: 294
Netherlands
I've tried using a TMF but for some reason the TradePriceOpen/PriceTradeEntry returns a 0-value.

Code
double PriceTradeEntry;


int PlaceEntry()
	{
	Lots = 1;
	PriceTradeEntry = TradePriceOpen;
	return 16;
	}

enterLong(PlaceEntry);
printf("\nPriceTradeEntry: %.5f", PriceTradeEntry);

Re: How to control entry/exit price? [Re: JesseL] #478569
11/10/19 10:30
11/10/19 10:30
Joined: Apr 2008
Posts: 585
Austria
Petra Offline
Support
Petra  Offline
Support

Joined: Apr 2008
Posts: 585
Austria
The manual is your friend

"All trade variables listed above can only be accessed inside a TMF, inside a trade enumeration loop, or when ThisTrade was explicitely set to a valid TRADE* pointer. In all other cases they have invalid content."

I suppose a 0-value is invalid content, which means you did not access the variable correctly. A TMF makes no sense here, I would set ThisTrade directly from enterLong. And check if it is nonzero and your trade was really entered, otherwise you wont get an entry price, right? laugh


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1