Bollinger System

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #14307 quote
    thomas123
    Participant
    New

    Hi,

    I just started working with PRT. I tried to create a system that works with the Bollinger Bands. Basically the idea is to sell if the price crosses the upper band and vice versa (in 1h timeframe).

    That´s the code I have so far:

    a = Average[20](close)
    
    IF barindex >= 20-1 THEN
    sumy2 = 0
    sumy = 0
    FOR i = 0 TO 20-1 do
    sumy2 = sumy2 + SQUARE(close[i])
    sumy = sumy + close[i]
    NEXT
    STDDEV =SQRT(sumy2 / 20 - SQUARE(sumy / 20))
    ELSE
    STDDEV = undefined
    ENDIF
    
    up = a+STDDEV*3
    down = a-STDDEV*3
    
    // Bedingungen zum Einstieg in Long-Positionen
    c1 = time>070000
    c2 = time<220000
    c3 = time=220000
    
    IF NOT SHORTONMARKET and c1 and c2 THEN
    Buy 1 SHARES AT down limit
    SET STOP PLOSS 5
    SET TARGET PPROFIT 15
    ENDIF
    
    // Bedingungen zum Ausstieg aus Long-Positionen
    
    
    IF c3  THEN
    Sell  AT Market
    ENDIF
    
    // Bedingungen zum Einstieg in Short-Positionen
    
    IF NOT LONGONMARKET and c1 and c2 THEN
    SELLSHORT 1 SHARES AT up limit
    SET STOP PLOSS 5
    SET TARGET PPROFIT 15
    ENDIF
    
    // Bedingungen zum Ausstieg aus Short-Positionen
    
    
    IF c3 THEN
    ExitShort  AT Market
    ENDIF
    

     

    The Problem now is that it buys/sells at the previous and not at the current bollinger value. Does someone have an idea how to solve this problem?

    Thank you!

     

    Regards Thomas

    #14310 quote
    Nicolas
    Keymaster
    Master

    I have modified your code a bit.

    You don’t have to calculate yourself the standard deviation as it is already a language instruction. Only one trade will be launch at the same time.

    defparam cumulateorders = false
    
    a = Average[20](close)
    
    up = a+STD[20](close)*3
    down = a-STD[20](close)*3
    
    // Bedingungen zum Einstieg in Long-Positionen
    c1 = time>070000
    c2 = time<220000
    c3 = time=220000
    
    IF NOT SHORTONMARKET and c1 and c2 THEN
    Buy 1 SHARES AT down limit
    SET STOP PLOSS 5
    SET TARGET PPROFIT 15
    ENDIF
    
    // Bedingungen zum Ausstieg aus Long-Positionen
    IF c3  THEN
    Sell AT Market
    ENDIF
    
    // Bedingungen zum Einstieg in Short-Positionen
    IF NOT LONGONMARKET and c1 and c2 THEN
    SELLSHORT 1 SHARES AT up limit
    SET STOP PLOSS 5
    SET TARGET PPROFIT 15
    ENDIF
    
    // Bedingungen zum Ausstieg aus Short-Positionen
    IF c3 THEN
    ExitShort AT Market
    ENDIF

    Results are great, but this is due to the “0 bar” behaviour of the tester.

    bollinger-trading-strategy-proorder.png bollinger-trading-strategy-proorder.png
    #14329 quote
    thomas123
    Participant
    New

    Hi Nicolas,

    thanks for your reply and your modifications.

    I still face the problem, that positions are openend even if the price doesn´t cross the Bollinger Bands. The reason is, that the system buys on the previous Bollinger value.

    As an example: Let´s say we are at the 3 o´clock candle, then the system buys/sells at the 2 o´clock bollinger value.

    Do you have any ideas how to solve that problem?

    And could you please explain what you mean by “0 bar” behaviour?

    Thanks

    #14339 quote
    Nicolas
    Keymaster
    Master

    You are putting LIMIT orders at market at the actual bollinger bands values. If price touch this value, the trade is open. You could have also try to use the cross of the close of candlesticks instead, with CROSSES OVER and CROSSES UNDER. What you think of a delay about the correct bollinger values may come from these conditional pending orders you are using in your strategy. Also, please have in mind that conditions are tested only 1 time at close of the candlestick and trades are executed at the next open.

    You’ll find a lot of topics and discussions here about the not look inside what happen in a bar, but it is now an old problem since version 10.3 now include a new tick by tick backtest engine.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

Bollinger System


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
thomas123 @thomas123 Participant
Summary

This topic contains 3 replies,
has 2 voices, and was last updated by Nicolas
9 years, 4 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 10/05/2016
Status: Active
Attachments: No files
Logo Logo
Loading...