Bollinger Strategy

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #3446 quote
    KM
    Participant
    New

    Hi, can somebody help me with my strategy. I need some modification to optimize it. The change that I need is to make it open a position only if it crosses the middle bollinger line before hand. Example: If I have an open long position and it hits target profit then it only opens a new long position if it crosses the middle bollinger line again, if the price still above the middle bollinger then it should stay inactive.

    Sorry if my English is bad.

     

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    
    // Conditions to enter long positions
    indicator1 = ExponentialAverage[50](close)
    c1 = (close > indicator1)
    
    indicator2 = ExponentialAverage[50](close)+1.5*std[50](close)
    c2 = (high[7] >= indicator2)
    
    IF c1 AND c2 THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
    
    // Conditions to exit long positions
    indicator3 = ExponentialAverage[50](close)-1.5*std[50](close)
    c3 = (low <= indicator3)
    
    IF c3 THEN
    SELL  AT MARKET
    ENDIF
    
    // Conditions to enter short positions
    indicator4 = ExponentialAverage[50](close)
    c4 = (close < indicator4)
    
    indicator5 = ExponentialAverage[50](close)-1.5*std[50](close)
    c5 = (low[7] <= indicator5)
    
    IF c4 AND c5 THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    
    // Conditions to exit short positions
    indicator6 = ExponentialAverage[50](close)+1.5*std[50](close)
    c6 = (high >= indicator6)
    
    IF c6 THEN
    EXITSHORT  AT MARKET
    ENDIF
    
    // Stops and targets
    set target %profit 0.4
    
    #3451 quote
    Nicolas
    Keymaster
    Master

    Hello,  in your conditions variables ‘condition1’ and ‘condition4’ , you should test a crossover with the  EMA instead of only testing if close is above or under it. I’ll post codes if you don’t find how to get it.

    #3454 quote
    Nicolas
    Keymaster
    Master

    Here is the short tricks to made it works like you want it :

    For Long position :

    c1 = (close crosses over indicator1)

    For Short position :

    c4 = (close crosses under indicator4)

     

    bollinger strategy

    #3461 quote
    KM
    Participant
    New

    Thanks for the reply, but that isn’t what I’m looking for. If I make those changes, then it will trigger an Entry only if it crosses the middle bollinger line and the second conditions kicks in. I need it to cross beforehand. So it will be like this:

     

    Conditions:

    1. The price is over middle bollinger band
    2. Seven days before the high has to be over upper bollinger band

      Enter Long.

    3. If previous position hits target/stop then enter only if the prise moves under the middle bollinger band, then up and condition 1 and 2 kicks in then go long again.
    #3479 quote
    Nicolas
    Keymaster
    Master

    So your ‘c1’ condition need only to be tested once? At ProOrder strategy startup? If so, all you have to do is to “flag” your first trade with a variable and then make 2 different ‘c1’ conditions :

    • first ‘c1’ : tradedbefore=0 so test only if “Close>EMA50”
    • second ‘c1’ : tradedbefore=1 so test a crossover
    #3600 quote
    KM
    Participant
    New

    Thank you Nicolas,  I’ll try it out.

    #3601 quote
    KM
    Participant
    New

    Sorry Nicolas, I can’t  make it work. Can you please write the code for me?

    #3713 quote
    Nicolas
    Keymaster
    Master

    Here is the final code, I have flagged the first trade with the “tradedbefore” variable set to 1 if a first trade has occurred. If then, the next trade would be taken only if the price crosses above or below the middle bollinger band (a moving average 50 periods in this case).

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    DEFPARAM preloadbars = 0
    
    once tradedbefore=0
    GRAPH tradedbefore as "tradedbefore"
    
    // Conditions to enter long positions
    indicator1 = ExponentialAverage[50](close)
    if tradedbefore=0 then
    c1 = (close > indicator1)
    elsif tradedbefore=1 then
    c1 = close crosses over indicator1
    endif
    
    indicator2 = ExponentialAverage[50](close)+1.5*std[50](close)
    c2 = (high[7] >= indicator2)
    
    IF c1 AND c2 THEN
    BUY 1 CONTRACT AT MARKET
    tradedbefore = 1
    ENDIF
    
    // Conditions to exit long positions
    indicator3 = ExponentialAverage[50](close)-1.5*std[50](close)
    c3 = (low <= indicator3)
    
    IF c3 THEN
    SELL  AT MARKET
    ENDIF
    
    // Conditions to enter short positions
    indicator4 = ExponentialAverage[50](close)
    if tradedbefore=0 then
    c4 = (close < indicator4)
    elsif tradedbefore = 1 then
    c4 = close crosses under indicator4
    endif
    
    indicator5 = ExponentialAverage[50](close)-1.5*std[50](close)
    c5 = (low[7] <= indicator5)
    
    IF c4 AND c5 THEN
    SELLSHORT 1 CONTRACT AT MARKET
    tradedbefore = 1
    ENDIF
    
    // Conditions to exit short positions
    indicator6 = ExponentialAverage[50](close)+1.5*std[50](close)
    c6 = (high >= indicator6)
    
    IF c6 THEN
    EXITSHORT  AT MARKET
    ENDIF
    
    // Stops and targets
    set target %profit 0.4
    #3720 quote
    KM
    Participant
    New

    Thank you very much

    #3766 quote
    Nicolas
    Keymaster
    Master

    You are welcome, hope it will help you.

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

Bollinger Strategy


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
KM @bz_invest Participant
Summary

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

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