Simple BB Strategy that needs help

Viewing 15 posts - 1 through 15 (of 19 total)
  • Author
    Posts
  • #238559 quote
    Trader Sab
    Participant
    New

    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 quote
    Trader Sab
    Participant
    New
    #238575 quote
    Iván González
    Moderator
    Master

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

    2024-10-07_11-44.png 2024-10-07_11-44.png
    #238594 quote
    JS
    Participant
    Senior
    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…

    Iván González and Trader Sab thanked this post
    #238632 quote
    Trader Sab
    Participant
    New
    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 quote
    Iván González
    Moderator
    Master
    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
    defparam cumulateorders=true
    // Strategy 1 Mean Revision Trade
    BUpper = BollingerUp[20](Close)
    BLower = BollingerDown[20](Close)
    
    //Conditions to enter a long trade
    IF 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 High > BUpper THEN
    SELLshort 1 CONTRACTS AT MARKET
    ENDIF
    
    //Conditions to close a short trade
    IF ShortOnMarket AND Low > BLower THEN
    EXITSHORT AT MARKET
    ENDIF
    
    SET STOP TRAILING 16
    Trader Sab thanked this post
    #238703 quote
    Trader Sab
    Participant
    New
    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 quote
    Iván González
    Moderator
    Master
    The system works as you designed… It opens new positions in the next bar open when conditions are met. Look at the screenshot.
    Trader Sab thanked this post
    2024-10-08_17-59.png 2024-10-08_17-59.png
    #238800 quote
    Trader Sab
    Participant
    New
    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.
    Screenshot-2024-10-10-103013.png Screenshot-2024-10-10-103013.png
    #238838 quote
    druby
    Participant
    New
    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.
    Iván González and Trader Sab thanked this post
    #238943 quote
    Trader Sab
    Participant
    New
    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 quote
    Trader Sab
    Participant
    New
    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
    System-1-Short-only-open-trade-at-5pm.png System-1-Short-only-open-trade-at-5pm.png System-1-Short-only-open-trade-at-5pm-1.png System-1-Short-only-open-trade-at-5pm-1.png System-1-Short-only-open-trade-at-5pm-2.png System-1-Short-only-open-trade-at-5pm-2.png
    #239005 quote
    Niklas87
    Participant
    New
    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.
    Trader Sab thanked this post
    #239007 quote
    Trader Sab
    Participant
    New
    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
    System-1-Short-only-BB-3-STDV.png System-1-Short-only-BB-3-STDV.png
    #239009 quote
    Trader Sab
    Participant
    New
    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!
    Only-2nd-candle-after-condition-open-trade.png Only-2nd-candle-after-condition-open-trade.png
Viewing 15 posts - 1 through 15 (of 19 total)
  • You must be logged in to reply to this topic.

Simple BB Strategy that needs help


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Trader Sab @trader-sab Participant
Summary

This topic contains 18 replies,
has 5 voices, and was last updated by druby
1 year, 4 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 10/07/2024
Status: Active
Attachments: 11 files
Logo Logo
Loading...