Check of previous candles

Viewing 2 posts - 31 through 32 (of 32 total)
  • Author
    Posts
  • #77080 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Lines 15 and 23 reference MONTHLY HA candlesticks as defined in lines 3-6. Since you are in the Weekly and Daily TF, you should define HA candlesticks also for those TF’s.

    First you’ll have to remove lines 5-6, since when you later want to refernce the high and low of a HA candlestick you should, I guess, reference the xHighD and xLowD from the DAILY definitions.

    For the WEEKLY TF you should add, after line 14 (before line 15):

    xCloseW = (open+high+low+close)/4
    xOpenW  = (xOpenW[1]+xCloseW[1])/2
    
    For the DAILY TF you’ll have to add 4 lines, after line 22 (before line 23):
    xCloseD = (open+high+low+close)/4
    xOpenD  = (xOpenD[1]+xCloseD[1])/2
    xHighD  = Max(max(high, xOpenD), xCloseD)
    xLowD   = Min(min(Low, xOpenD), xClosed)

    then you’ll have to change references in lines 15 and 23 and in lines 33,36,49,52,65,68,81,84,97 and 100.

    But I think also lines with reference to MyDay, MyDay[1] and so on… must be incorrect, but I cannot tell what because the code is too long, and difficult to read and debug.

    As I suggested at the beginning, before making a single change you should be confident with the current code. When you’ll be confident with your first change you may add one more (not trwo or three, just one at a time).

    Use GRAPH to debug.

    #77639 quote
    MarcMarc
    Participant
    Average

    Hi together,

    this is now my amended code:

    DEFPARAM CUMULATEORDERS = false
    
    TIMEFRAME (Monthly, updateonclose)
    MClose = (open+high+low+close)/4
    MOpen  = (MOpen[1]+MClose[1])/2
    MHigh  = Max(max(high, MOpen), MClose)
    MLow   = Min(min(Low, MOpen), MClose)
    
    IF (MOpen+MHigh+MLow+MClose)/4 > (MOpen[1]+MClose[1])/2 THEN
    MyMonth = 1 //BULLish
    ELSE
    MyMonth = -1 //BEARish
    ENDIF
    
    TIMEFRAME (Weekly, updateonclose)
    WClose = (open+high+low+close)/4
    WOpen  = (WOpen[1]+WClose[1])/2
    WHigh  = Max(max(high, WOpen), WClose)
    WLow   = Min(min(Low, WOpen), WClose)
    
    IF (WOpen+WHigh+WLow+WClose)/4 > (WOpen[1]+WClose[1])/2 THEN
    MyWeek = 1 //BULLish
    ELSE
    MyWeek = -1 //BEARish
    ENDIF
    
    TIMEFRAME (Daily, updateonclose)
    XClose = (open+high+low+close)/4
    XOpen  = (XOpen[1]+XClose[1])/2
    XHigh  = Max(max(high, XOpen), XClose)
    XLow   = Min(min(Low, XOpen), XClose)
    
    ONCE AlreadyTraded = 0
    IF (XOpen+XHigh+XLow+XClose)/4 > (XOpen[1]+XClose[1])/2 THEN
    MyDay = 1 //BULLish
    ELSE
    MyDay = -1 //BEARish
    ENDIF
    ThisDay = OpenDayofWeek
    IF ThisDay = 1 AND Not OnMarket AND AlReadyTraded = 0 THEN //Monday
    GoLong = MyMonth = 1 AND MyWeek = 1 AND MyDay = -1
    GoShort = MyMonth = -1 AND MyWeek = -1 AND MyDay = 1
    IF GoLong THEN
    EntryPrice = XHigh
    BUY 1 CONTRACT AT EntryPrice LIMIT
    ELSIF GoShort THEN
    EntryPrice = XLow
    SELLSHORT 1 CONTRACT AT EntryPrice LIMIT
    ENDIF
    Sl = AverageTrueRange[2](close)
    Tp = Sl
    SET Stop Loss Sl
    SET Target Profit Tp
    ENDIF
    
    IF ThisDay = 2 AND Not OnMarket AND AlReadyTraded = 0 THEN //Tuesday
    GoLong = MyMonth = 1 AND MyWeek = 1 AND MyDay[1] = -1 AND MyDay[2] = -1
    GoShort = MyMonth = -1 AND MyWeek = -1 AND MyDay[1] = 1 AND MyDay[2] = 1
    IF GoLong THEN
    EntryPrice = XHigh
    BUY 1 CONTRACT AT EntryPrice LIMIT
    ELSIF GoShort THEN
    EntryPrice = XLow
    SELLSHORT 1 CONTRACT AT EntryPrice LIMIT
    ENDIF
    Sl = AverageTrueRange[2](close)
    Tp = Sl
    SET Stop Loss Sl
    SET Target Profit Tp
    ENDIF
    
    IF ThisDay = 3 AND Not OnMarket AND AlReadyTraded = 0 THEN //Wednesday
    GoLong = MyMonth = 1 AND MyWeek = 1 AND MyDay[1] = -1 AND MyDay[2] = -1 AND MyDay[3] = -1
    GoShort = MyMonth = -1 AND MyWeek = -1 AND MyDay[1] = 1 AND MyDay[2] = 1 AND MyDay[3] = 1
    IF GoLong THEN
    EntryPrice = XHigh
    BUY 1 CONTRACT AT EntryPrice LIMIT
    ELSIF GoShort THEN
    EntryPrice = XLow
    SELLSHORT 1 CONTRACT AT EntryPrice LIMIT
    ENDIF
    Sl = AverageTrueRange[2](close)
    Tp = Sl
    SET Stop Loss Sl
    SET Target Profit Tp
    ENDIF
    
    IF ThisDay = 4 AND Not OnMarket AND AlReadyTraded = 0 THEN //Thursday
    GoLong = MyMonth = 1 AND MyWeek = 1 AND MyDay[1] = -1 AND MyDay[2] = -1 AND MyDay[3] = -1 AND MyDay[4] = -1
    GoShort = MyMonth = -1 AND MyWeek = -1 AND MyDay[1] = 1 AND MyDay[2] = 1 AND MyDay[3] = 1 AND MyDay[4] = 1
    IF GoLong THEN
    EntryPrice = XHigh
    BUY 1 CONTRACT AT EntryPrice LIMIT
    ELSIF GoShort THEN
    EntryPrice = XLow
    SELLSHORT 1 CONTRACT AT EntryPrice LIMIT
    ENDIF
    Sl = AverageTrueRange[2](close)
    Tp = Sl
    SET Stop Loss Sl
    SET Target Profit Tp
    ENDIF
    
    IF ThisDay = 5 AND Not OnMarket AND AlReadyTraded = 0 THEN //Friday
    GoLong = MyMonth = 1 AND MyWeek = 1 AND MyDay[1] = -1 AND MyDay[2] = -1 AND MyDay[3] = -1 AND MyDay[4] = -1 AND MyDay[5] = -1
    GoShort = MyMonth = -1 AND MyWeek = -1 AND MyDay[1] = 1 AND MyDay[2] = 1 AND MyDay[3] = 1 AND MyDay[4] = 1 AND MyDay[5] = 1
    IF GoLong THEN
    EntryPrice = XHigh
    BUY 1 CONTRACT AT EntryPrice LIMIT
    ELSIF GoShort THEN
    EntryPrice = XLow
    SELLSHORT 1 CONTRACT AT EntryPrice LIMIT
    ENDIF
    Sl = AverageTrueRange[2](close)
    Tp = Sl
    SET Stop Loss Sl
    SET Target Profit Tp
    ENDIF
    
    IF ThisDay = 1 AND Not OnMarket THEN
    AlreadyTraded = 0
    ENDIF
    IF OnMarket THEN
    AlreadyTraded = 1
    ENDIF
    

    When Backtesting it the result looks very bad…

    Backtest.jpg Backtest.jpg
Viewing 2 posts - 31 through 32 (of 32 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Check of previous candles


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Marc @mast83 Participant
Summary

This topic contains 31 replies,
has 3 voices, and was last updated by MarcMarc
8 years, 3 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 07/13/2018
Status: Active
Attachments: 4 files
ProRealCode ProRealCode
Loading...