Here's the "trigger" logic.
Trigger an entry when...
(1) today's close is greater than yesterday's high and
(2) today's close is greater than today's open and
(3) today's low is greater than yesterday's low.
When these conditions are met, enter at a stop price of today's high + $0.05.
The attached screen shot shows an example when the entry should have occurred at the trigger price of $11.74 on bar 3426 (April 22), which hit a high price of $11.75, but instead the entry triggered at the open on the subsequent bar (April 23).
Here's my current code, which isn't working as expected. A bunch of the code enclosed within "{Debugging Code}" start/end tags and can be ignored.
Code: Select all
[ProcessMouseEvents=true]
variables: Close_GT_Yes_High( false ), // Today's close is Greater Than (GT) yesterday's high
Close_GT_Open( false ), // Today's close is GT today's open
Low_GT_Yes_Low( false ), // Today's low is GT yesterday's low
BuyTrigger(false), // Are all UE conditions true?
TriggerBarHigh(0), // High price of the 'triger' bar
TriggerBuyPrice(0); // $0.05 above trigger bar high
Close_GT_Yes_High = Close > high[1];
Close_GT_Open = Close > Open;
Low_GT_Yes_Low = Low > Low[1];
{Debugging Code}
{The CheckCommentary condition only evaluates the commentary on the currently selected bar;
allows for much faster execution}
If CheckCommentary Then Begin
{BarStatus=2 condition only provides commentary on the close value; if IOG is enables
and this condition is not enabled, the commentary evaluates 4 times - once for
open, high, low and close}
If barstatus=2 then begin
Commentary("Section 01: After Initial varible assignment / inspection", newline);
Commentary("Current Bar Number: ", Currentbar:4:0, newline);
Commentary("Close_GT_Yes_High: ", Close_GT_Yes_High, newline);
Commentary("Close_GT_Open: ", Close_GT_Open, newline);
Commentary("Low_GT_Yes_Low: ", Low_GT_Yes_Low, newline);
Commentary("Section 01: End", newline, newline);
end;
End;
{End Debugging Code}
if Close_GT_Yes_High and
Close_GT_Open and
Low_GT_Yes_Low then
begin
BuyTrigger = true;
TriggerBarHigh = high;
TriggerBuyPrice = TriggerBarHigh + 0.05;
{Debugging Code}
If CheckCommentary Then Begin
If barstatus=2 then begin
Commentary("Section 02: Conditions for buy met", newline);
Commentary("Current Bar Number: ", Currentbar:4:0, newline);
Commentary("BuyTrigger: ", BuyTrigger, " ", newline);
Commentary("TriggerBarHigh: ", TriggerBarHigh , " ", newline);
Commentary("TriggerBuyPrice: ", TriggerBuyPrice , " " , newline);
Commentary("Section 02: End", newline, newline);
end;
end;
{End Debugging Code}
end
else
begin
BuyTrigger = false;
TriggerBarHigh = 0;
TriggerBuyPrice = 0;
{Debugging Code}
If CheckCommentary Then Begin
If barstatus=2 then begin
Commentary("Section 03: Conditions for buy NOT met", newline);
Commentary("Current Bar Number: ", Currentbar:4:0, newline);
Commentary("BuyTrigger: ", BuyTrigger, " ", newline);
Commentary("TriggerBarHigh: ", TriggerBarHigh , " ", newline);
Commentary("TriggerBuyPrice: ", TriggerBuyPrice , " ", newline);
Commentary("Section 03: End", newline, newline);
end;
end;
{End Debugging Code}
end;
if BuyTrigger then
begin
Buy ( "DAW_UE" ) next bar at TriggerBuyPrice stop ;
BuyTrigger= false ;
end ;