Bollinger Strategy problems with exit orders

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

    Hello everyone,

    I am having problems implementing a Bollinger Strategy.

    The following code should buy and sell with the shown condition. But we have trouble with the exits. They do not as they should

    defparam cumulateorders = false
    
    startTradingTime = 090500
    stopTradingTime = 210000
    
    positionSize = 1
    
    // TRADING HOURS
    timeCondition = 0
    IF(time >= startTradingTime) AND (time <= stopTradingTime) THEN
    timeCondition = 1
    ENDIF
    
    AmountOfSigmas = 2
    BollingerAmountOfPeriods = 20
    BollingerBandsMeanAtCurrentClose = average[BollingerAmountOfPeriods,0](close)
    standardDeviation = STD[BollingerAmountOfPeriods](close)
    upperBollingerBand = BollingerBandsMeanAtCurrentClose + (AmountOfSigmas * standardDeviation)
    lowerBollingerBand = BollingerBandsMeanAtCurrentClose - (AmountOfSigmas * standardDeviation)
    
    AmountOfSigmascloseMean = 0.1
    UpperBollingerCloseMean = BollingerBandsMeanAtCurrentClose + AmountOfSigmascloseMean*standardDeviation
    LowerBollingerCloseMean = BollingerBandsMeanAtCurrentClose - AmountOfSigmascloseMean*standardDeviation
    
    // Onboard Condition
    CurrentValueAboveUpperBollinger = close > upperBollingerBand // BollingerUp[BollingerAmountOfPeriods](close)//upperBollingerBand //BollingerUp[BollingerAmountOfPeriods](close)
    CurrentValueBelowLowerBollinger = close < lowerBollingerBand //BollingerDown[BollingerAmountOfPeriods](close)//lowerBollingerBand// BollingerDown[BollingerAmountOfPeriods](close) //
    
    BuyShortCondition = CurrentValueAboveUpperBollinger AND timeCondition
    BuyLongCondition = CurrentValueBelowLowerBollinger AND timeCondition 
    
    // EXIT CONDITION
    sellLongCondition = close >= LowerBollingerCloseMean
    sellShortCondition = close <= UpperBollingerCloseMean
    
    sellstoplong = 40
    sellstopshort = 40
    IF BuyLongCondition AND NOT LONGONMARKET THEN
     BUY positionSize PERPOINT AT MARKET
     //SET STOP PLOSS sellstoplong
     SET TARGET PROFIT (BollingerBandsMeanAtCurrentClose +AmountOfSigmascloseMean*standardDeviation)*pipsize // POINT WHERE IT SHOULD SELL
    ENDIF
    
    
    IF BuyShortCondition AND NOT SHORTONMARKET THEN
    
     SELLSHORT positionSize PERPOINT AT MARKET
     //SET STOP PLOSS sellstopshort
     SET TARGET PROFIT (BollingerBandsMeanAtCurrentClose-AmountOfSigmascloseMean*standardDeviation)*pipsize // POINT WHERE IT SHOULD SELL
    ENDIF
    
    
    #199008 quote
    JS
    Participant
    Senior

    I don’t see exit orders, I do see “Exit Condition” but these are not used in the code…

    You go Long with “Buy” but I don’t see “Sell” as “exit order”

    You go Short with “SellShort” but I don’t see “ExitShort” as “exit order”

    LONG: Buy vs Sell

    SHORT: SellShort vs ExitShort

    #199013 quote
    taklause
    Participant
    New
    IF sellLongCondition THEN
    sell at market
    ENDIF
    
    
    IF sellShortCondition THEN
    exitshort at market
    ENDIF
    Yes you are right, but how would I use a SET TARGET PROFIT with UpperBollingerCloseMean or LowerBollingerCloseMean as example?
    #199021 quote
    JS
    Participant
    Senior
    DefParam CumulateOrders = False
    
    Period = 20
    
    xMean = Average[Period](Close)
    xStd = Std[Period](Close)
    
    BBUp = xMean + 2 * xStd
    BBDown = xMean - 2 * xStd
    
    If Close Crosses Over BBUp then
    SellShort 1 contract at Market
    EndIf
    
    If Close Crosses Under BBDown then
    Buy 1 contract at Market
    EndIf
    
    xMeanUp = xMean + 0.1 * xStd
    xMeanDown = xMean - 0.1 * xStd
    
    If LongOnMarket then
    Sell at xMeanUp LIMIT
    EndIf
    
    If ShortOnMarket then
    ExitShort at xMeanDown LIMIT
    EndIf
    Hi @taklause You can use a LIMIT order to exit your positions…
    taklause thanked this post
    Schermafbeelding-2022-08-13-om-15.48.41.png Schermafbeelding-2022-08-13-om-15.48.41.png
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

Bollinger Strategy problems with exit orders


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
taklause @taklause Participant
Summary

This topic contains 3 replies,
has 2 voices, and was last updated by JS
3 years, 6 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 08/13/2022
Status: Active
Attachments: 1 files
Logo Logo
Loading...