How to create a breakout box between 2 hours, Code please?

Viewing 15 posts - 31 through 45 (of 57 total)
  • Author
    Posts
  • #76886 quote
    abacus23
    Participant
    Average

    Wow , thank you, 3 masters. 🙂

    Just backtesting now.

    Many thanks for all 3 contributions. 😉

    Have a good weekend.

    #76903 quote
    robertogozzi
    Moderator
    Master

    I think it should be (Barindex – TradeIndex) and not (TradeIndex – BarIndex) and it closes after 30 bars not 10.

    I’m guessing you are on your phone Robertogozzi as the code was not inserted correctly – I tidied it up for you 🙂

    I WAS on my phone (I also wrote TradeInex instead of TradeIndex, but on the phone I couldn’t see whether it was highlighted or not!) . Thank you Vonasi.

    #82554 quote
    abacus23
    Participant
    Average
    defparam flatafter = 210000
     
    if longonmarket then
    alreadybuy=1
    endif
    if shortonmarket then
    alreadysell=1
    endif
     
    if intradaybarindex=0 then
    alreadybuy=0
    alreadysell=0
    myprofit=strategyprofit
    endif
     
    if time = 061000 then
    yh = highest[86](high)
    yL=lowest[86](low)
    os = 2*pipsize
    endif
     
    timeEnterBefore1 = time >= 080000
    timeEnterAfter1  = time < 120000  
    timeEnterBefore2 = time >= 150000   
    timeEnterAfter2  = time < 200000
    
    if my condition AND ((timeEnterBefore1 AND timeEnterAfter1) or (timeEnterBefore2 AND timeEnterAfter2)) then
     
    if my condition and strategyprofit<=myprofit and yh>0 and yl>0 then
    if close<yh+os and not alreadybuy  then
    buy 1 contract at yh+os stop
    endif
    if close>yl+os and not alreadysell then
    sellshort 1 contract at yl-os stop
    endif
    endif
     
     
    set stop ploss 15
    set target pprofit 15

    I was trying to add 2 time conditions, but it doesn’t seem to be working.

    Could somebody advise where I have gone wrong please?

    #82574 quote
    robertogozzi
    Moderator
    Master

    There’s a missing ENDIF at line 37.

    Also, testing MY CONDITION at line 29 is useless (but this does not affect performance) since it’s been already evaluated at line 27.

    abacus23 thanked this post
    #82657 quote
    abacus23
    Participant
    Average

    Robertogozzi,

    Many thanks for your email reply. 😉

    I added an, ENDIF in line 37, but the code doesn’t work?

    I get a syntax error: the following variable is undefined : my condition.

    Many thanks for all your help.

    defparam flatafter = 210000
     
    if longonmarket then
    alreadybuy=1
    endif
    if shortonmarket then
    alreadysell=1
    endif
     
    if intradaybarindex=0 then
    alreadybuy=0
    alreadysell=0
    myprofit=strategyprofit
    endif
     
    if time = 061000 then
    yh = highest[86](high)
    yL=lowest[86](low)
    os = 2*pipsize
    endif
     
    timeEnterBefore1 = time >= 080000
    timeEnterAfter1  = time < 120000  
    timeEnterBefore2 = time >= 150000   
    timeEnterAfter2  = time < 200000
     
    if my condition AND ((timeEnterBefore1 AND timeEnterAfter1) or (timeEnterBefore2 AND timeEnterAfter2)) then
     
    if my condition and strategyprofit<=myprofit and yh>0 and yl>0 then
    if close<yh+os and not alreadybuy  then
    buy 1 contract at yh+os stop
    endif
    if close>yl+os and not alreadysell then
    sellshort 1 contract at yl-os stop
    endif
    endif
    endif 
     
    set stop ploss 15
    set target pprofit 15
    
    #82664 quote
    robertogozzi
    Moderator
    Master

    I thought MY CONDITION was a plain text to refer tou tour own undisclosed conditions.

    Variable names cannot have spaces, nor special signs, only aphanumeric characters.

    You will have to define what your conditions are and write them in palce of MY CONDITIONS, say

    Average[10,0](close) CROSSES OVER Average[50,0](close)  //or CROSSES UNDER for short trades

    or the like.

    #82667 quote
    abacus23
    Participant
    Average

    Roberto,

    Ok thank you, I will try.

    “my conditions” referred to the time, eg timenterbefore1 etc.

    i did write tcondition, but it still didn’t work.

    Thanks

    #82670 quote
    robertogozzi
    Moderator
    Master

    MYCONDITION, TCONDITION or whatever else you write MUST be defined before being used, if it refers to the time conditions already in place, just remove it.

    #82781 quote
    abacus23
    Participant
    Average

    robertogozzi

    Thank you, that made it work. 😉

    #83081 quote
    abacus23
    Participant
    Average
    defparam flatafter = 210000
    
    if longonmarket then
    alreadybuy=1
    endif
    if shortonmarket then
    alreadysell=1
    endif
     
    if intradaybarindex=0 then
    alreadybuy=0
    alreadysell=0
    myprofit=strategyprofit
    endif
     
    if time = 060500 then
    yh = highest[85](high)
    yL=lowest[85](low)
    os = 3*pipsize
    endif
    
    tcondition = time>074500 and time<205000
    
    if tcondition and strategyprofit<=myprofit and yh>0 and yl>0 then
    if close<yh+os and not alreadybuy then
    buy 1 contract at yh+os stop
    endif
    if close>yl+os and not alreadysell then
    sellshort 1 contract at yl-os stop
    endif
    endif
     
    set stop ploss 15
    set target pprofit 15
    

    Hi,

    Please could somebody clarify why my code works some days and not others.

    On 5/10/18 my code worked, how I wanted it to work, 0805 it went short, after the breakout of the conditions, yl / yh.

    On 8/10/18 my code didn’t work at 0755 short, when it should have, but activated at 1505n short? It’s the same code, the backtest proves it doesn’t work all the time.

    I have experienced it on other days as well, sometimes it works and sometimes not, not sure why?

    All I was after was a simple breakout strategy, but it seems I may have coded it incorrectly.

    Many thanks in advance. (The code should be attached)

    #83093 quote
    robertogozzi
    Moderator
    Master

    On which instrument and TF?

    #83094 quote
    abacus23
    Participant
    Average

    Sorry. 🙄

     

    Wall Street, 5 min chart.

    #83100 quote
    robertogozzi
    Moderator
    Master

    I think line 30 should read “close<yh-os“, but the cause for not entering on 8/10/18 at 0755 is because the previous bar, when the pending orders are placed, the short order was NOT place du to false conditions, because CLOSE (26435.1) < Y+OS(26435.6) and conditions at line 28 were not met.

    abacus23 thanked this post
    #83102 quote
    robertogozzi
    Moderator
    Master

    You can use GRAPH to display variables at runtime, with their values retained each bar.

    This debugging tool will help find out errors quickly (well… a bit quicker).

    abacus23 thanked this post
    x1-2.jpg x1-2.jpg
    #83105 quote
    abacus23
    Participant
    Average

    Many thanks again Roberto. 😉 I will have a look into the graph function.

    I have changed the code, as you instructed above, it works on the 8/10/18, but there are more trades it does not take, where as the old code did. I presume there is no way of re-wording my code, to simplify it, so when the price crosses the breakout points,  yh / yl , it buys/sells regardless?
Viewing 15 posts - 31 through 45 (of 57 total)
  • You must be logged in to reply to this topic.

How to create a breakout box between 2 hours, Code please?


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
abacus23 @abacus23 Participant
Summary

This topic contains 56 replies,
has 5 voices, and was last updated by robertogozzi
7 years, 4 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 05/21/2018
Status: Active
Attachments: 7 files
Logo Logo
Loading...