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)...
function run()
{
set(PARAMETERS+FACTORS+LOGFILE);
LookBack = 100;
StartDate = 20130601;
EndDate = 20131230;
var BreakoutValue;
int MarginFactor = slider(1,500,100,10000,"Margin","Margin");
int StopFactor = optimize(1,1,8);
Stop = StopFactor * ATR(10);
Trail = StopFactor * ATR(10);
BarPeriod = 1440;
BreakoutValue = 0.3 * (priceHigh(1)-priceLow(1));
var shortentry = priceOpen() - (0.3 * (priceHigh(1)-priceLow(1)));
if ( TRUE )
{
Entry = shortentry;
enterShort();
}
for(open_trades)
if(TradeIsOpen and TradeResult > 0)
exitTrade(ThisTrade);
plot("shortentry",shortentry,0,BLUE);
// plot("BreakoutValue",BreakoutValue,NEW,BLUE);
PlotScale = -10;
PlotWidth = 1400;
PlotHeight1 = 500;
}