Question:
The trading system should enter at the market when one average
crosses another, but I get filled on the Close or High, how
can I get what I want?
Perspective:
The problem here is that the query parser is not able to
determine what the correct entry price should be in all cases.
( because of the potential complexity of the WHEN condition )
Concept of how to do it:
What we need to do is tell the MIM what the price should be
in the order block.
Use both entry_stop and limit to get the fill at the
correct price, and dont forget about gap openings.
Example 1 - the concept
Suppose that the price to get in at is 10.
1: ORDER 1.1:Buy 1 contract of IBM
Enter with entry_stop at 10
limit at 10
Example 2 - dealing with a gap opening
Now suppose the market opens above 10, then we want
to get in on the open, so replace 10 with...
if Open of IBM > 10 then Open of IBM else 10 endif
...which will return 10 or the Open, which ever is appropriate.
1: ORDER 1.1:Buy 1 contract of IBM
Enter with entry_stop at
if Open of IBM > 10 then Open of IBM else 10 endif
limit at
if Open of IBM > 10 then Open of IBM else 10 endif
Example 3 - actual query
Order block 1.1: shows the behavior without the fix
Order block 1.2: shows the result of the new order block language.
1: ORDER
1.1: Buy 1 contract of IBM
Enter on the market
Exit on the market
1.2: Buy 1 contract of IBM
Enter with entry_stop at 10 day average of IBM 1 day ago
limit at IF
Open of IBM is more than 10 day average of IBM 1 day ago
THEN Open of IBM
ELSE 10 day average of IBM 1 day ago
ENDIF
WHEN
Date is from 2/1/98 to 4/1/98
AND
High of IBM crosses above 10 day average of IBM 1 day ago
EXIT
High of IBM crosses below 10 day average of IBM 1 day ago
SHOW
prevHigh: High of IBM 1 day ago
Avg2cross: 10 day average of IBM 1 day ago
Open: Open of IBM
High: High of IBM
Low: Low of IBM
Close: Close of IBM
WHEN
Date is from 2/1/98 to 4/1/98
AND {
High of IBM crosses above 10 day average of IBM 1 day ago
OR
High of IBM crosses below 10 day average of IBM 1 day ago }
Results:
| Date |
Day |
prevHigh |
Avg2cross |
Open |
High |
Low |
Close |
| |
|
|
|
|
|
|
|
| 02/02/1998 |
Mon |
49.7813 |
49.7569 |
50.0000 |
50.6250 |
50.0000 |
50.2813 |
| 03/03/1998 |
Tue |
52.2813 |
51.6313 |
50.0000 |
51.2500 |
49.9063 |
51.0625 |
| 03/04/1998 |
Wed |
51.2500 |
51.6375 |
51.0000 |
51.6563 |
49.5000 |
49.5000 |
| 03/05/1998 |
Thu |
51.6563 |
51.4500 |
50.0938 |
50.1875 |
49.1563 |
49.4688 |
| 03/12/1998 |
Thu |
49.9375 |
50.1406 |
49.5938 |
50.3125 |
49.0938 |
50.1250 |
5 Occurrences
P&L Trades:
| Type |
InDate |
InReason |
OutDate |
OutReason |
Num |
InPrice |
OutPrice |
Move |
%Move |
Profit |
CumProfit |
| |
|
|
|
|
|
|
|
|
|
|
|
| Buy |
02/02/1998 |
When 1.1 |
03/03/1998 |
Exit 1 |
1 |
50.2813 |
51.0625 |
0.7813 |
1.5538 |
0.7813 |
0.7813 |
| Buy |
02/02/1998 |
When 1.2 |
03/03/1998 |
Exit 1 |
1 |
50.0000 |
51.0625 |
1.0625 |
2.1250 |
1.0625 |
1.8438 |
| Buy |
03/04/1998 |
When 1.1 |
03/05/1998 |
Exit 1 |
1 |
49.5000 |
49.4688 |
-0.0313 |
-0.0631 |
-0.0313 |
1.8125 |
| Buy |
03/04/1998 |
When 1.2 |
03/05/1998 |
Exit 1 |
1 |
51.6375 |
49.4688 |
-2.1688 |
-4.2000 |
-2.1688 |
-0.3563 |
| Buy |
03/12/1998 |
When 1.1 |
05/26/1998 |
Exit 1 |
1 |
50.1250 |
60.5000 |
10.3750 |
20.6983 |
10.3750 |
10.0187 |
| Buy |
03/12/1998 |
When 1.2 |
05/26/1998 |
Exit 1 |
1 |
50.1406 |
60.5000 |
10.3594 |
20.6606 |
10.3594 |
20.3781 |
|