How to control entry/exit price?

Posted By: JesseL

How to control entry/exit price? - 07/02/19 06:07

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);
    }
Posted By: jcl

Re: How to control entry/exit price? - 07/02/19 09:53

For triggering exactly at the crossing, use a tick() function. And it's priceClose(), not TradePriceClose.
Posted By: JesseL

Re: How to control entry/exit price? - 07/02/19 14:38

The data are daily bars, so priceClose() returns EOD price. How can tick() works? Do I have to use tick data?
Posted By: AndrewAMD

Re: How to control entry/exit price? - 07/02/19 16:01

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.
Posted By: JesseL

Re: How to control entry/exit price? - 07/02/19 16:51

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?
Posted By: jcl

Re: How to control entry/exit price? - 07/03/19 09:46

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.
Posted By: Grant

Re: How to control entry/exit price? - 11/07/19 17:56

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.
Posted By: jcl

Re: How to control entry/exit price? - 11/08/19 14:16

Maybe you missed this page: https://manual.zorro-project.com/trade.htm
Posted By: Grant

Re: How to control entry/exit price? - 11/09/19 15:33

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);
Posted By: Petra

Re: How to control entry/exit price? - 11/10/19 10:30

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
© 2024 lite-C Forums