[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Coding problem on order entry



PureBytes Links

Trading Reference Links

Hi all,

Was wondering if someone could help me with the following code.

What I'm trying to create is a simple system that places trades based on
breaking specific high or low in n minutes.  In the case of the code below
I'm using 5 minutes after the open as the trigger level.  What I want to do
is set stop orders to go long or short if the stock trades above or below
the five minute high/low.  So far, I have managed to get that working
correctly.  As you can see from the trade summary below for QLGC.

What I'm having problems with is if the stock breaks it high/low and I'm
stopped out.  When that happens I want to reenable my entry stops again for
the long and short side. So, basically if I'm stopped out on a long more
than likely I'm going to get a short entry, but that's not happening.  In
looking at the code below can anyone spot what I'm doing wrong or offer a
better way to accomplish this.

All suggestions are greatly appreciated.

Thanks,
Brian

QLGC
Trade #     Date         Time     Type     Cnts     Price    Commiss.
Slippage     Signal Name Entry P/L Cumulative
1              5/20/2002  08:40    Buy      100      51.12    $0.00
$0.00          Long
                5/20/2002  08:40    LExit    100      51.52    $0.00
$0.00          LongProfit     40.00       40.00
2              5/21/2002  08:40    Buy      100      51.18    $0.00
$0.00          Long
                5/21/2002  08:45    LExit    100      50.93    $0.00
$0.00          LongStop     (25.00)      15.00
3              5/22/2002  08:40    Sell       100     48.12    $0.00
$0.00          Short
                5/22/2002  08:40    SExit    100     48.37    $0.00
$0.00          ShortStop     (25.00)     (10.00)
4              5/23/2002  08:40    Sell       100     48.30    $0.00
$0.00          Short
                5/23/2002  08:45    SExit    100     47.90    $0.00
$0.00          ShortProfit     40.00        30.00




inputs: ProfitTarget(0.40), StopLoss(0.25);
variable: FiveMinH(0), FiveMinL(0), LEntryValid(TRUE), SEntryValid(TRUE),
MP(FALSE), PreviousEntry(False);

{Here is where I set the high/low entry points}
If time = 0835 then
 begin
  FiveMinH = High;
  FiveMinL = Low;
 end;

{I'm using this to verify the high/low entry points.  Simply a debugging
line. }
Print(GetSymbolName, "  ", FiveMinH, "  ", FiveMinL, "  ", Date, "  ",
Time);

{This is where I'm trying to initially set the stop limit orders the first
time around and after a pervious buy/sell was triggered. }
if ((time = 0835) or ((marketposition(0) = 0) and (time > 0835) and
(previousentry=TRUE))) then
 begin
  Buy ("Long") next bar at (FiveMinH) stop ;
  SellShort ("Short") next bar at (FiveMinL) stop;
 end;

{This section sets my profit and stop levels for the trade. }
Sell ("LongProfit") From Entry ("Long") next bar at (FiveMinH +
ProfitTarget) limit;
Sell ("LongStop") From Entry ("Long") next bar at (FiveMinH - StopLoss)
stop;
BuyToCover ("ShortProfit") From Entry ("Short") next bar at (FiveMinL -
ProfitTarget) limit;
BuyToCover ("ShortStop") From Entry ("Short") next bar at (FiveMinL +
StopLoss) stop;

{Here is where I'm exiting no matter what at the end of the day. }
if (time=sess1endtime and marketposition(0) <> 0) then
 begin
  Sell this bar on close;
  buytocover this bar on close;
 end;