Bollinger Bandit
Forums › ProRealTime English forum › ProOrder support › Bollinger Bandit
- This topic has 10 replies, 4 voices, and was last updated 6 years ago by achel.
Tagged: Bollinger
-
-
11/04/2018 at 8:41 AM #84108
The Bollinger Bandit uses one standard deviation above the 50-day moving average as a potential long entry and one standard deviation below the 50-day moving average as a potential short entry.
The longer that we are in a trade, the easier it is to exit the market with a profit. We keep decrementing the number of days in our moving average calculation until we reach ten. From that point on, we do not decrement. There is one more element to our exit technique: the moving average must be below the upper band if we are long and above the lower band if we are short.
This element is to prevent the system from going back into the same trade that we just liquidated. If we hadn’t used this additional condition and we were long and the moving average was above the upper band, the long entry criteria would still be set up and a long trade would be initiated.
One more test must be passed before we initiate a position; the close of today must be greater than the close of 30 days ago for a long position and the close of today must be less than the close of 30 days ago for a short position. This additional requirement is a trend filter. We only want to go long in an uptrend and short in a downtrend.
This system is longer term in nature, so we will use 50 days in our calculations.
Could someone please translate into PRC code ? Thanks———————————-
Bollinger Bandit Pseudocode
LiqDay is initially set to 50
upBand = Average(Close,50) + StdDev(Close,50) *1.25 dnBand = Average(Close,50) – StdDev(Close,50) *1.25 rocCalc = Close of today – Close of thirty days agoSet liqLength to 50
If rocCalc is positive, a long position will be initiated when today’s market action >= upBand
If rocCalc is negative, a short position will be initiated when today’s market action <= dnBand
liqPoint = Average(Close, 50)
If liqPoint is above the upBand, we will liquidate a long position if today’s market action <= liqPoint If liqPoint is below the dnBand, we will liquidate a short position if today’s market action >= liqPoint
If we are not stopped out today, then liqLength = liqLength – 1 If we are stopped out today, then reset liqLength to fifty
—————————————-BELOW -TO TRANSLATE——————————————————–
Bollinger Bandit Program
{Uses Bollinger Bands and Rate of change to determine entry points. A trailing stop that is proportional with the amount of time a trade is on is used as the exit technique.}Inputs: bollingerLengths(50),liqLength(50),rocCalcLength(30); Vars: upBand(0),dnBand(0),liqDays(50),rocCalc(0);
upBand = BollingerBand(Close,bollingerLengths,1.25); dnBand = BollingerBand(Close,bollingerLengths,-1.25);rocCalc = Close – Close[rocCalcLength-1]; {remember to subtract 1} if(MarketPosition <> 1 and rocCalc > 0) then Buy(“BanditBuy”)tomorrow upBand
stop;
if(MarketPosition <>-1 and rocCalc < 0) then SellShort(“BanditSell”) tomorrow dnBand stop;if(MarketPosition = 0) then liqDays = liqLength; if(MarketPosition <> 0) then
begin
liqDays = liqDays – 1;
liqDays = MaxList(liqDays,10);end;
if(MarketPosition = 1 and Average(Close,liqDays) < upBand) then Sell(“Long Liq”) tomorrow Average(Close,liqDays) stop; if(MarketPosition = -1 and Average(Close,liqDays) > dnBand) then BuyToCover(“Short Liq”) tomorrow Average(Close,liqDays) stop;———————————-THANKS—————————————–
11/04/2018 at 9:06 AM #8410911/04/2018 at 11:34 AM #8411511/05/2018 at 8:36 AM #84147Here is the translated code for ProOrder:
1234567891011121314151617181920212223242526272829303132defparam cumulateorders=falsebollingerLengths=50liqLength=50rocCalcLength=30avg = average[bollingerLengths]upBand = avg+std[bollingerlengths]*1.25dnBand = avg-std[bollingerlengths]*1.25rocCalc = Close - Close[rocCalcLength-1]// {remember to subtract 1}if(not longonmarket and rocCalc > 0) and close<upBand thenBuy 1 contract at upBand stopendifif(not shortonmarket and rocCalc < 0) and close>dnBand thenSellShort 1 contract at dnBand stopendifif not onmarket thenliqDays = liqLengthelseliqDays = liqDays - 1liqDays = Max(liqDays,10)endifif(longonmarket = 1 and Average[liqDays] < upBand) thenSell at Average[liqDays] stopendifif(shortonmarket = -1 and Average[liqDays] > dnBand) thenexitshort at Average[liqDays] stopendifWhat timeframe and instrument suits the best the strategy? For what purpose it was designed for?
1 user thanked author for this post.
11/05/2018 at 12:34 PM #84166What timeframe and instrument suits the best the strategy?
Attached is DAX 1 hour over 100k bars with spread = 2
11/05/2018 at 12:39 PM #84171There was a mistake in the previous code, please use this one instead!
1234567891011121314151617181920212223242526272829303132defparam cumulateorders=falsebollingerLengths=50liqLength=50rocCalcLength=30avg = average[bollingerLengths]upBand = avg+std[bollingerlengths]*1.25dnBand = avg-std[bollingerlengths]*1.25rocCalc = Close - Close[rocCalcLength-1]// {remember to subtract 1}if(not longonmarket and rocCalc > 0) and close<upBand thenBuy 1 contract at upBand stopendifif(not shortonmarket and rocCalc < 0) and close>dnBand thenSellShort 1 contract at dnBand stopendifif not onmarket thenliqDays = liqLengthelseliqDays = liqDays - 1liqDays = Max(liqDays,10)endifif(longonmarket and Average[liqDays] < upBand) thenSell at Average[liqDays] stopendifif(shortonmarket and Average[liqDays] > dnBand) thenexitshort at Average[liqDays] stopendif11/06/2018 at 5:40 PM #84248The Bollinger Bandit program demonstrates how to:
- Invoke the Bollinger Band function. This function call is less than intuitive and must be passed three parameters: (1) price series, (2) number of elements in the sample used in the calculation for the standard deviation, and (3) number of deviations above/below moving average. You must use a negative sign in the last parameter to get the band to fall under the moving average.
- Invoke the MaxList function. This function returns the largest value in a list.
- Do a simple rate of change calculation.
- Create and manage a counter variable, liqLength.
- Could it be possible for you to backtest with above parameters one or more of the equities listed on attached table ?
- Could it be possible to create an indicator fo a manual trading process ?
- Thanks very much
- BR
11/07/2018 at 10:37 AM #84307Could it be possible for you to backtest with above parameters one or more of the equities listed on attached table ?
I think that you’ll be able to do it by yourself?
Could it be possible to create an indicator fo a manual trading process ?
Do you mean an indicator with buy/sell signals on the price chart and with the strategy described in your first post?
11/07/2018 at 11:27 AM #8431711/07/2018 at 2:24 PM #84328Let’s try this:
123456789101112131415161718192021222324252627282930313233343536373839bollingerLengths=50liqLength=50rocCalcLength=30avg = average[bollingerLengths]upBand = avg+std[bollingerlengths]*1.25dnBand = avg-std[bollingerlengths]*1.25atr = AverageTrueRange[14](close)rocCalc = Close - Close[rocCalcLength-1]// {remember to subtract 1}if(lastsignal<=0 and rocCalc > 0) and close<upBand thendrawarrowup(barindex,low-atr) coloured(0,255,0)lastsignal=1//lastbar=barindexendifif(lastsignal>=0 and rocCalc < 0) and close>dnBand thendrawarrowdown(barindex,high+atr) coloured(255,0,0)lastsignal=-1//lastbar=barindexendifif lastsignal=0 thenliqDays = liqLengthelseliqDays = liqDays - 1liqDays = Max(liqDays,10)endif//if(lastsignal=1 and Average[liqDays] < upBand) and barindex-lastbar>=1 then//drawtext("◄",barindex,upBand,dialog,bold,24) coloured(200,154,96)//lastsignal=0//endif//if(lastsignal=-1 and Average[liqDays] > dnBand) and barindex-lastbar>=1 then//drawtext("◄",barindex,upBand,dialog,bold,24) coloured(200,154,96)//lastsignal=0//endifreturn11/07/2018 at 4:48 PM #84344 -
AuthorPosts