The entry signal is a stop entry at OPEN - 0.3 * Yesterdays Range. The problem is that the order goes live a bar later. As a result, if the market traded past the entry price on the desired entry day, then we enter at the open of the following bar. If not, then if the market trades through the price that we wanted to enter yesterday, then we enter today at that price.
The attached graph plots the stop entry level with a blue line. You can see that the market enters either at that level on the next bar or at the OPEN if the OPEN is lower than the stop entry.
Here is the code. Don't worry about the IF statement or exit (WIP)...
I am not sure that I understand your problem. Trades open at the moment when the entry condition is met, not earlier and not later. Therefore, aside from spread and slippage, a short trade opens either at its entry stop, or below when the price was already lower at the time when you placed the trade.
If you've set the TICKS flag, you can see the precise open times and entry prices in the log.
Re: Entry price a day late
[Re: jcl]
#429736 09/17/1315:3009/17/1315:30
Ok...I think this points to a misunderstanding that I have about programming with zorro. But that just comes from a hangover from programming with other software.
So to enter the market at, for example, open - 50 pips, I need to put this condition in to the if criteria so that when the market trades at that level, a market order is placed. So what do I put in the if brackets? I have tried some things and they don't seem to work. For example...
var shortentry = priceOpen() - (0.3 * (priceHigh(1)-priceLow(1)));
if (priceClose() == shortentry) { enterShort(); }
Yields no trades. Putting a < such that entering the trade the market trades through the entry level results in the same problem as before. I need to 'priceLast()' rather than a priceClose()...or I need to understand how to reference the last trade price. Does this make sense? I am just trying to get the basic opening range breakout working so that I can apply filters.
Re: Entry price a day late
[Re: DMB]
#429739 09/17/1316:4209/17/1316:42
If you want to enter a trade at a certain price, you normally use an entry stop. For entering when tomorrow's price drops below today's open - 50 pips, the code would look like this:
I'm not sure if you really want this, though. For a range breakout you normally use the current price and not the open from 24 hours ago. A normal entry stop code would look like this:
Entry = priceClose() - 50*PIP; enterShort();
Re: Entry price a day late
[Re: jcl]
#429813 09/19/1305:4209/19/1305:42
I am pleased to say that I have finally got this sorted out. Such a simple problem. I assure you that I am brighter than this. Thanks for your patience. You are right in your second statement. I don't want the offset from yesterday's open. And since yesterday's close is about the same as today's open in 24h and intraday markets, I can use yesterday's close.