Simple BB Strategy that needs help
Forums › ProRealTime English forum › ProOrder support › Simple BB Strategy that needs help
- This topic has 18 replies, 5 voices, and was last updated 2 months ago by druby.
-
-
10/07/2024 at 9:35 AM #238559
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.
10/07/2024 at 9:36 AM #23856010/07/2024 at 10:44 AM #23857510/07/2024 at 1:49 PM #238594Hi,
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…
2 users thanked author for this post.
10/07/2024 at 9:13 PM #238632Thank 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
ENDIFSET STOP TRAILING 16
10/08/2024 at 8:38 AM #238649Hi, 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 removeif not longonmarket
. This makes the purchase only occur if it is not bought. Also the instruction to go short issellshort
1234567891011121314151617181920212223242526defparam cumulateorders=true// Strategy 1 Mean Revision TradeBUpper = BollingerUp[20](Close)BLower = BollingerDown[20](Close)//Conditions to enter a long tradeIF Low [1]< BLower THENBUY 1 CONTRACTS AT MARKETENDIF//Conditions to close a long tradeIf LongOnMarket AND High > BUpper THENSELL AT MARKETENDIF//Conditions to enter a short tradeIF High > BUpper THENSELLshort 1 CONTRACTS AT MARKETENDIF//Conditions to close a short tradeIF ShortOnMarket AND Low > BLower THENEXITSHORT AT MARKETENDIFSET STOP TRAILING 161 user thanked author for this post.
10/08/2024 at 11:51 AM #238703Many 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
10/08/2024 at 5:01 PM #238738The system works as you designed… It opens new positions in the next bar open when conditions are met.
Look at the screenshot.1 user thanked author for this post.
10/10/2024 at 9:52 AM #238800I 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.
10/10/2024 at 11:34 PM #238838As 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.
2 users thanked author for this post.
10/14/2024 at 8:47 AM #238943Thank you so much for your reply.
Is it generally better to separate the short and long set ups in two different codes?
Best Regards
10/15/2024 at 10:22 AM #238998Good 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
10/15/2024 at 10:43 AM #239005When 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.
1 user thanked author for this post.
10/15/2024 at 10:54 AM #239007I 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 = 220000BB = 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
ENDIFSET STOP TRAILING 25
10/15/2024 at 11:09 AM #239009I 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!
-
AuthorPosts
Find exclusive trading pro-tools on