Strange buy level and Stop loss doesn't work

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #127675 quote
    teapot2002
    Participant
    Average

    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.

    Screenshot-2020-04-23-at-18.54.31.png Screenshot-2020-04-23-at-18.54.31.png
    #127681 quote
    robertogozzi
    Moderator
    Master

    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.

    it’s because you are using STOP, while you should use a LIMIT pending order, since your entry price (hahigh[1]) is lower than the current one

    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.

    because you did set such a huge SL, over 5000 pips/points; that’s because LOSS requires a difference in price (such as high – low[1]), while you used a price (haopen[1])

    I’d very much appreciate your help with this – it has been driving me mad all day.

    Many thanks.

    #127745 quote
    teapot2002
    Participant
    Average

    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
    
    Screenshot-2020-04-24-at-10.18.55.png Screenshot-2020-04-24-at-10.18.55.png
    #127848 quote
    teapot2002
    Participant
    Average

    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!

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

Strange buy level and Stop loss doesn't work


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
teapot2002 @teapot2002 Participant
Summary

This topic contains 3 replies,
has 2 voices, and was last updated by teapot2002
5 years, 10 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 04/23/2020
Status: Active
Attachments: 2 files
Logo Logo
Loading...