Please could you help me with this? I’ve attached a screenshot that shows two things that I don’t understand. Here is the code:
// HB Doji trade 1hr
// Enter on break after a Doji signal. Stop currently is trailing, optimised to 198 with Doji definitions (in the indicator) 14.5 long and 14.8 short. Currently 35.1%
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// Prevents the system from creating new orders to enter the market or increase position size before the specified time
noEntryBeforeTime = 050000
timeEnterBefore = time >= noEntryBeforeTime
// Prevents the system from placing new orders to enter the market or increase position size after the specified time
noEntryAfterTime = 163000
timeEnterAfter = time < noEntryAfterTime
// Prevents the system from placing new orders on specified days of the week
daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
if barindex>1 then
haclose=(open+close+low+high)/4
haopen=(haopen[1]+haclose[1])/2
xHigh = Max(haOpen, haClose)
//xLow = Min(haOpen, haClose)
hahigh = Max(High,xHigh)
//halow = Min(Low,xLow)
endif
// Conditions to enter long positions
indicator1 = CALL "Heikin Ashi doji entry"[9] //[14.5]
dojiL = (indicator1 >= 0.5)
If hahigh[1]<hahigh[2] and hahigh[2]<hahigh[3] THEN
downtrend = 1
ENDIF
// if you're in a downtrend and get a doji, and break the close of that doji, it's a long entry.
IF dojiL AND downtrend AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THEN
BUY 1 PERPOINT AT hahigh[1] STOP
ENDIF
hsl = haopen[1]
SET STOP LOSS hsl
graph hsl
graph dojiL
I use an indicator, shown in the screenshot, to indicate a doji bar.
Then I enter long if we have been in downtrend, the theory being that after a downtrend, a doji signals a change of direction.
The first thing that I don’t understand is why the buy is at 5108, when I’ve asked it to buy at hahigh, which is my calculation of the heikin ashi high. 5108 is the open of that candle, not even the candlestick high.
The second thing is why a stop is never placed. This trade is never closed, despite my setting a stop loss at hsl, which is shown in the screenshot as 4925.
I’d very much appreciate your help with this – it has been driving me mad all day.
Many thanks.
Hi Roberto – many thanks for your reply.
Perhaps there’s something even more fundamental that I don’t understand, which is when things take place.
I’ve changed my doji indicator so that it takes the trend into account, signalling 1 for a downtrend plus doji, signalling the start of an uptrend, and vice versa. This happens at 06:00 in the attached screenshot. I think that this signal is returned at 05:59:59, so is active 06:00, so that a trade should enter at during the 06:00 bar. However, it doesn’t.
Could you please explain the mistake I’m making here?
Again, many thanks.
This is the new code:
// HB Doji trade 1hr
// Enter on break after a Doji signal.
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// Prevents the system from creating new orders to enter the market or increase position size before the specified time
noEntryBeforeTime = 050000
timeEnterBefore = time >= noEntryBeforeTime
// Prevents the system from placing new orders to enter the market or increase position size after the specified time
noEntryAfterTime = 163000
timeEnterAfter = time < noEntryAfterTime
// Prevents the system from placing new orders on specified days of the week
daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
if barindex>1 then // Don't do this on the first bar of the timeframe
haclose=(open+close+low+high)/4
haopen=(haopen[1]+haclose[1])/2
xHigh = Max(haOpen, haClose)
//xLow = Min(haOpen, haClose)
hahigh = Max(High,xHigh)
//halow = Min(Low,xLow)
endif
// Conditions to enter long positions
indicator1 = CALL "Heikin Ashi doji entry"[9] //[14.5]
dojiL = (indicator1 = 1) // If this returns +1, it's a signal to go long
// if you're in a downtrend and get a doji, and break the high of that doji, it's a long entry.
IF dojiL AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THEN
BUY 1 PERPOINT AT hahigh[1] STOP
hsl = haopen[1]
ENDIF
SET STOP LOSS hsl
graph hsl
graph dojiL
Sorry, cancel that last post. I had two doji indicators, one of which flags the doji and the other flags the next candle as an entry. I confused the two. Sorry!