Simple BB Strategy that needs help

Forums ProRealTime English forum ProOrder support Simple BB Strategy that needs help

Viewing 15 posts - 1 through 15 (of 19 total)
  • #238559

    Good morning

    I like to program my mean revision set up on 15 min TF buying outside the Bollinger Bands. However in the current Back Test system bought only on the first candle outside the BBs and not on the subsequent ones.

    Most appreciate your insights.

     

    #238560

    Here the missing file

    #238575

    Hi!
    Could you share your code to copy/paste?
    Just press the buttom “Insert PRT code”.

    #238594
    JS

    Hi,

    When I look at the code you go “Long” when the “Close<Blower” and “Short” when the “Close>BUpper”…

    If you want to go “short” you must use “SellShort” in your code…

    So, line 20 of the code should be: “SellShort 1 Lot at Market”

    Furthermore, if you want to use “cumulative orders” then the following line in your code must be used: “DefParam CumulateOrders=True”

    With this, any “Close” that goes outside the BB will generate an order…

    2 users thanked author for this post.
    #238632

    Thank you for your answer. Here the code

    // Strategy 1 Mean Revision Trade

    BUpper = BollingerUp[20](Close)
    BLower = BollingerDown[20](Close)

    //Conditions to enter a long trade

    IF NOT LongOnMarket AND Low [1]< BLower THEN
    BUY 1 CONTRACTS AT MARKET
    ENDIF

    //Conditions to close a long trade

    If LongOnMarket AND High > BUpper THEN
    SELL AT MARKET
    ENDIF

    //Conditions to enter a short trade

    IF NOT ShortOnMarket AND High > BUpper THEN
    SELL 1 LOT AT MARKET
    ENDIF

    //Conditions to close a short trade
    IF ShortOnMarket AND Low > BLower THEN
    EXITSHORT AT MARKET
    ENDIF

    SET STOP TRAILING 16

     

    #238649

    Hi, As JS indicates in his answer, in order to enter more orders you have to put the instruction defparam cumulateorders=true on the first line. On the other hand, the entry condition must be changed so that it can accumulate positions. You have to remove if not longonmarket . This makes the purchase only occur if it is not bought. Also the instruction to go short is sellshort

    1 user thanked author for this post.
    #238703

    Many thanks!

    Now if I look at the trade log of the back testing with ‘defparam cumulateorders=true’

    The systems doesn’t open trades where the conditions are fullfilled. Do I have to specify anything more than ‘IF Low [1]< BLower THEN’

    Or is this just a bug with the backtesting on this software?

    I truly appreciate your insights.

    Best Regards

    Sab

    #238738

    The system works as you designed… It opens new positions in the next bar open when conditions are met.
    Look at the screenshot.

    1 user thanked author for this post.
    #238800

    I tested the system as you did on EURUSD 1 hr, but I get some really strange back testing results, which I can not understand. I have been going through line by line what positions the system

    opened and when it closed them, as I like to understand the equity curve it projects. However I am turning in circles, hence I

     

    Just looking at Oct 2nd, the systems opens correctly a

    11.00  – Sell order @ 1.10723, the candle has a total lenght of (open 1.0723, Low 1.0613) over 10 points, with a trailing stop of 16, this positions should not have created

    a Loss of $762. My question is why is that possible with a trailing stop of 16? Max loss should be  $160

    13.00 – Sell order @ 1.10671, the candle opened however @ 1.10757, why is the system opening a position only 8 pips later? The trade was closed correctly

    15.00 – System generates a buy order but doesn’t close it until October 4th

    Are these problems of the backtesting with ProRealTime or do I need to write the code differently?

    Thank you so much for your assistance.

     

     

    #238838

    As a guess, from your image, the code only allows 1 buy and 1 sell at a time, due to IF  NotxxxxOnMarket.

    It appears that…

    On 30 sept 19:00 Buy entry @ 1.11485 is exited by  2 oct  11:00 Sell entry 1.10723 and the difference is 0.00762  ( $ 762 )

    Then 2 oct 11:00 Sell exit @ 1.10723 and is exited by 2 oct 12:00 Buy exit 1.10717 and the difference is 0.00006    ( $ 6 )

    However , I may have got the entry and exit transposed, but the numbers seem to correlate.

    I’m still guessing, I think its a combination having buy and sell in same strategy, with the buy exit condition and sell entry condition the same along with the 1 entry of each.

     

    So, when the buy exit is triggered, then the sell entry could also  be triggered in the same bar, does one take precedence over the other!, also the entry for long and short are slightly different  low[1] , high[0] .

    If code line are executed in sequence this can’t happen the other way round,  short exit _ long entry, it would have to wait for the next bar.

    This sequence of events may be happening on other trades and maybe that’s what tripping up the trailing stop, thinking its in a buy but its in a sell or something.

    To test, I would have two strategy’s one long, one short, see if correct trades are taken, and compared to current strategy results, this may show the difference.

    2 users thanked author for this post.
    #238943

    Thank you so much for your reply.

    Is it generally better to separate the short and long set ups in two different codes?

    Best Regards

     

    #238998

    Good morning

    I did separate the short and long trades into two codes, but still have the same problem that the system opens a short trade @ 5 pm althought the condition was met @ 3.45 when it opened correctly a short trade.

    If I can eliminate this error, than the system should be working fine. I appreciate your input and assistance.

    Best Regards

     

     

    #239005

    When defparam cumulateorders=true your code will trade even when a postion is open. If you change this to false or add “if not onmarket” to your buy conditions (if you whant to acumulate positons) this will be controlled.

    1 user thanked author for this post.
    #239007

    I have modified the code to use a 3 Standard Deviation for the short only to reduce trades when market is trending strongly. However here I have the same issue, the system doesn’t open a trade in the right location, but only 3 bars later after the condition as met.

    //Strategy 1 Mean Revision Short only

    DefParam CumulateOrders = True
    DefParam FLATBEFORE = 080000
    DefParam FLATAFTER = 220000

    BB = 20 //20 periods
    BBdev = 3 //3 standard deviation
    BBavg = average[BB,0](close) //BB mean (middle line)
    UPboll = BBavg + ((std[BB](close)) * BBdev) //BB Upper Band
    LOboll = BBavg – ((std[BB](close)) * BBdev) //BB Lower Band

    //Conditions to enter a short trade

    IF High [1]> UPboll THEN
    SELLSHORT 1 LOT AT MARKET
    ENDIF

    //Conditions to close a short trade
    IF ShortOnMarket AND Close < BBavg THEN
    EXITSHORT AT MARKET
    ENDIF

    SET STOP TRAILING 25

    #239009

    I adjust this, however I ran into the same problem again, the system opens the trade too late, only after 2 candles. However it closes the trade correctly.

    I can’t figure out what I am missing in my code.

    Thanks for your assistance!

Viewing 15 posts - 1 through 15 (of 19 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login