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

Viewing 15 posts - 16 through 30 (of 57 total)
  • Author
    Posts
  • #75863 quote
    robertogozzi
    Moderator
    Master

    You shoud add

    AND Not daysForbiddenEntry

    in lines 26 and 29, just before THEN.

    Those days are FORBIDDEN, just remove the ones you want trading to be allowed.

    abacus23 thanked this post
    #75867 quote
    abacus23
    Participant
    Average

    robertogozzi,

    All inserted and working wonderfully.;)

    Many thanks for all your help.

    #76499 quote
    abacus23
    Participant
    Average

    I have been using the Auto Trading and it is working great, after all of the help from everybody 😉 but it only ever buys £1 per point, either way.

    I have been into Options>Trading Options > Auto trading, but there is nothing for position size? ( I have seen it on the simplified creation) and on the website link https://www.prorealcode.com/blog/learning/money-management-prorealtime-code/ from Nicholas, but I can’t seem to add it in.

    If I want £3 per point, example, how can I add this please?

    The link above does state how to amend it, but as my code has gotten longer and longer, I keep getting error messages when I try to insert the position size.

    #76501 quote
    Vonasi
    Moderator
    Master

    I keep getting error messages when I try to insert the position size.

    It would be easier for everyone if you posted the code on here as otherwise we are all just going to be guessing what you might have done wrong.

    #76502 quote
    abacus23
    Participant
    Average
    defparam flatafter = 210000
     
    daysForbiddenEntry = OpenDayOfWeek = 1 OR OpenDayOfWeek = 2 OR OpenDayOfWeek = 3 OR OpenDayOfWeek = 4 OR OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
     
    if longonmarket then
    alreadybuy=1
    endif
    if shortonmarket then
    alreadysell=1
    endif
     
    if intradaybarindex=0 then
    alreadybuy=0
    alreadysell=0
    endif
     
    if time = 061000 then
    yh = highest[86](high)
    yL=lowest[86](low)
    os = 2*pipsize
    endif
     
    tcondition = time>080000 and time<200000
     
    if tcondition then
    if close<yh+os and not alreadybuy then
    buy 1 contract at yh+os PositionSize 3 stop
    endif
    if close>yl+os and not alreadysell then
    sellshort 1 contract at yl-os PositionSize 3 stop
    endif
    endif
     
    set stop ploss 30
    ONCE TrailStart = 30 //30 Start trailing profits from this point
    ONCE ProfitPerCent = 0.666 //66.6% Profit to keep
    IF Not OnMarket THEN
    y1 = 0
    y2 = 0
    ELSIF LongOnMarket AND close > (TradePrice + (y1 * pipsize)) THEN //LONG
    x1 = (close – tradeprice) / pipsize //convert price to pips
    IF x1 >= TrailStart THEN //go ahead only if 30+ pips
    y1 = max(x1 * ProfitPerCent, y1) //y = % of max profit
    ENDIF
    IF y1 THEN //Place pending STOP order when y>0
    SELL AT Tradeprice + (y1 * pipsize) STOP //convert pips to price
    ENDIF
    ELSIF ShortOnMarket AND close < (TradePrice – (y2 * pipsize)) THEN //SHORT
    x2 = (tradeprice – close) / pipsize //convert price to pips
    IF x2 >= TrailStart THEN //go ahead only if 30+ pips
    y2 = max(x2 * ProfitPerCent, y2) //y = % of max profit
    ENDIF
    IF y2 THEN //Place pending STOP order when y>0
    EXITSHORT AT Tradeprice – (y2 * pipsize) STOP //convert pips to price
    ENDIF
    ENDIF
    

    Lastly, I have a slight issue with the breakout box settings,  if the time condition is 8-8, as below:

    tcondition = time>080000 and time<200000.

    Eg: Sell example: If the price has moved out of the breakout box at say 7:30, it seems to buy at 8 regardless, I would like the sell trade to be cancelled if the box has been broken before 8.  The buy remains active, but the same conditions as the above.

    Hopefully this makes sense.

    #76503 quote
    GraHal
    Participant
    Master

    Hopefully this makes sense.

    I don’t know what else might be wring as I am just about to run it, but surely Lines 25 to 32 need to read as below (without PositionSize 3) ??

    Also DaysForbiddenEntry in Line 3 is not used in the code??

    Attached is what I get on DJI at 10 min TF (what TF and Market is it supposed to run on?). Ignore the Win %, it is low due to the PRT Even Trades Glitch some of us are experiencing.

     

    if tcondition 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
    
    abacus23 thanked this post
    Abacus.jpg Abacus.jpg Abacus-2.jpg Abacus-2.jpg
    #76510 quote
    abacus23
    Participant
    Average

    GraHal,

    Many thanks, 5 min chart, I am on.

    defparam flatafter = 210000
    
    daysForbiddenEntry = OpenDayOfWeek = 2
    
    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 = 1*pipsize
    endif
     
    tcondition = time>080000 and time<200000
     
    if tcondition and strategyprofit<=myprofit and yh>0 and yl>0 then
    if close<yh+os and not alreadybuy AND Not daysForbiddenEntry then
    buy 1 contract at yh+os stop
    endif
    if close>yl+os and not alreadysell AND Not daysForbiddenEntry then
    sellshort 1 contract at yl-os stop
    endif
    endif
     
    set stop ploss 15
    ONCE TrailStart    =130       //30     Start trailing profits from this point
    ONCE ProfitPerCent = 0.8    //66.6%  Profit to keep
    IF Not OnMarket THEN
    y1 = 0
    y2 = 0
    ELSIF LongOnMarket AND close > (TradePrice + (y1 * pipsize)) THEN                         //LONG
    x1 = (close - tradeprice) / pipsize           //convert price to pips
    IF x1 >= TrailStart THEN                      //go ahead only if 30+ pips
    y1 = max(x1 * ProfitPerCent, y1)           //y = % of max profit
    ENDIF
    IF y1 THEN                                       //Place pending STOP order when y>0
    SELL AT Tradeprice + (y1 * pipsize) STOP      //convert pips to price
    ENDIF
    ELSIF ShortOnMarket AND close < (TradePrice - (y2 * pipsize)) THEN                        //SHORT
    x2 = (tradeprice - close) / pipsize           //convert price to pips
    IF x2 >= TrailStart THEN                      //go ahead only if 30+ pips
    y2 = max(x2 * ProfitPerCent, y2)           //y = % of max profit
    ENDIF
    IF y2 THEN                                       //Place pending STOP order when y>0
    EXITSHORT AT Tradeprice - (y2 * pipsize) STOP //convert pips to price
    ENDIF
    ENDIF
    I have added the forbidden code in.
    Removing the position size works on a back test, but how do I code in, the position size, (i.e £3 per point instead of the standard £1 per point)
    Also, eg DJI, 5 min chart,  2/7/18. Breakout box was broken at 6:05, the system bought at 08:50, not sure why?
    I would like to code in, if the price has broken out already before 8, the sell trade gets cancelled. (same conditions for the buy)
    #76513 quote
    abacus23
    Participant
    Average

    It’s ok, forget my ramblings, I have made it all work. 😉

    #76791 quote
    abacus23
    Participant
    Average

    Is it possible to add a non trade condition to the pro auto trading?

    I would like to add a condition, in that, if the breakout box is over 300 pips, the trades, buy and sell are not allowed to happen.

    I have tried to code it in, but for some reason it won’t work.

    Please could somebody have a look and see where I have gone wrong.

    defparam flatafter = 210000
     
    daysForbiddenEntry = OpenDayOfWeek = 2
     
    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 = 1*pipsize
    endif
    
    if yh-yL >=300*pipsize THEN
    result=0
    else
    result=1
    endif
    
    tcondition = time>080000 and time<200000
     
    if tcondition and strategyprofit<=myprofit and yh>0 and yl>0 then
    if close<yh+os and not alreadybuy AND Not daysForbiddenEntry then
    buy 1 contract at yh+os stop
    endif
    if close>yl+os and not alreadysell AND Not daysForbiddenEntry then
    sellshort 1 contract at yl-os stop
    endif
    endif
     
    set stop ploss 15
    ONCE TrailStart    =30       //30     Start trailing profits from this point
    ONCE ProfitPerCent = 0.6666    //66.6%  Profit to keep
    IF Not OnMarket THEN
    y1 = 0
    y2 = 0
    ELSIF LongOnMarket AND close > (TradePrice + (y1 * pipsize)) THEN                         //LONG
    x1 = (close - tradeprice) / pipsize           //convert price to pips
    IF x1 >= TrailStart THEN                      //go ahead only if 30+ pips
    y1 = max(x1 * ProfitPerCent, y1)           //y = % of max profit
    ENDIF
    IF y1 THEN                                       //Place pending STOP order when y>0
    SELL AT Tradeprice + (y1 * pipsize) STOP      //convert pips to price
    ENDIF
    ELSIF ShortOnMarket AND close < (TradePrice - (y2 * pipsize)) THEN                        //SHORT
    x2 = (tradeprice - close) / pipsize           //convert price to pips
    IF x2 >= TrailStart THEN                      //go ahead only if 30+ pips
    y2 = max(x2 * ProfitPerCent, y2)           //y = % of max profit
    ENDIF
    IF y2 THEN                                       //Place pending STOP order when y>0
    EXITSHORT AT Tradeprice - (y2 * pipsize) STOP //convert pips to price
    ENDIF
    ENDIF
    
    #76794 quote
    robertogozzi
    Moderator
    Master

    Add

    AND Result

    to lines 33 and 37.

    abacus23 thanked this post
    #76797 quote
    abacus23
    Participant
    Average

    Roberto, top man. 😉

    You guys are great.

    #76881 quote
    abacus23
    Participant
    Average

    I’m hoping this is the last question. 😉 Sorry Roberto.

    I have read lots about selling after n bars, but I would only like to sell after n bars, if the trade is losing.

    I have input the following code, but it sells regardless of profit / loss.

    if onmarket and BARINDEX-TRADEINDEX(1)>30 then
    SELL AT MARKET
    EXITSHORT AT MARKET
    endif
    

    Is it possible to remain in the trade after 30 bars if winning, but if after 30 bars I am losing, it sells the trade?

    Many thanks again in advance.

    #76882 quote
    GraHal
    Participant
    Master

    You need below or something similar… 🙂

    position perf is a %

    if onmarket and positonperf < - 0.0001 and BARINDEX-TRADEINDEX(1)>30 then
    SELL AT MARKET
    EXITSHORT AT MARKET
    endif

    OR

    if onmarket and abs(Close - tradeprice < 0) and BARINDEX-TRADEINDEX(1)>30 then
    SELL AT MARKET
    EXITSHORT AT MARKET
    endif

    syntax might be wrong, I have my grandkids here and they want to watch Horrid Henry! 🙂

    #76884 quote
    robertogozzi
    Moderator
    Master

    The code you found lets you close any open trade after N bars, regardless of performance, you ahould add a condition testing whether TRADEPRICE is higher or lower than the current CLOSE  and act accordingly.

    IF Close < TRADEPRICE AND (TradeInex - BarIndex) > 30 THEN
    SELL AT MARKET
    ENDIF

    this will close any long trade after 10 bars if the curent price is below entry price.

    #76885 quote
    Vonasi
    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 🙂

    robertogozzi thanked this post
Viewing 15 posts - 16 through 30 (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...