MyLongConditions = close CROSSES OVER BollingerDOWN[20]
MyShortConditions = close CROSSES UNDER BollingerUP[20]
Based on the above codes, may i know how the crosses are physically presented on charts.
I have a strategy where some of the crosses are not being considered as crosses though they look very similar to the others that are added as being crosses.
The following screenshot support my observations.
MyLongConditions is: previous Close is under previous Bollinger Down and current Close is above Bollinger Down
MyShortConditions is: previous Close is above previous Bollinger Up and current Close is below current Bollinger Up
In your first example, there is already an opened order, you might have a condition to prevent new order if one is already present? Second example, I dont know what’s happening, better to analyze the whole code to get a real idea of whats going on on that particular case.
Hello Nicolas,
Thanks for the information, but I dont remember applying any condition to prevent new order if one is already present.
Please see below my strategy and advise accordingly:
//------------------------------------------
// BollingerBands Strategy
//----Backtest-------
MyLongConditions = close CROSSES OVER BollingerDOWN[20]
MyShortConditions = close CROSSES UNDER BollingerUP[20]
p = 20
upper = bollingerup[p]
lower = bollingerdown[p]
middle = average[p]
BandwidthAbs= upper-lower
BandwidthCentage= (BandwidthAbs/middle)*100
//Bandwidth% should be adjusted based on securities and timeframes
IF MyLongConditions THEN
IF BandwidthCentage > 0.00 THEN
BUY 1 CONTRACTS AT MARKET
ENDIF
ELSIF MyShortConditions THEN
IF BandwidthCentage > 4.00 THEN
SELL AT MARKET
ENDIF
ENDIF
Add Not OnMarket to your conditions:
IF MyLongConditions AND Not OnMarket THEN
ELSIF MyShortConditions AND Not OnMarket THEN
Hello Roberogozzi,
Am sorry , adding AND Not OnMarket to my conditions has rendered my strategy mute or ineffective, not even a single signal , no cross over or cross under for all timeframes and asset classes.
My fault, an order is likely to have been triggered but can’t exit.
Remove Not OnMarket from the ELSIF line.
You may want to use the “graph” command in probacktest to visualise data in a specific window for debugging and/or investigating unexpected behaviour, in order to find out if it’s a platform bug, or a user code bug, or not a bug but a misplaced expectation, etc… Here with adding as last line:
graph MyShortConditions
it shows the cross in 2nd circle is detected on July 9th.
In case you were expecting a short position to open there, then it wasn’t a cross detection issue, it was about “sell” vs “sellshort” commands. Sell (used in your above code) exits an existing long position. Sellshort (not used in your above code) initiates a short position.
SELL
SELLSHORT
(not entering into further details of when there is or isn’t an opposite position already open and being reversed rather than just exited, or when defparam cumulateorders = true or false settings is used)
JC_Bywan,
Thanks very much for the information.
But if you follow the thread from the beginning, Nicolas already asked whether i apply conditions to prevent new orders when one is already present and my reponse is NO. Now i have even provided my codes to you where you are able to confirm there is no such conditions so am confused you are making reference to that fact.
Or if what i have stated above do not represent the meaning of your information then can you please explain what you mean by : “Sell(used in your above code) exits an existing long position.”
Regards
Sell is the instruction used to close buy order, while Sellshort is the one to open a sell order.
not even a single signal , no cross over or cross under for all timeframes and asset classes
Try below and it may trigger orders using the values you show in your conditions.
BandwidthCentage= (BandwidthAbs/middle)*1000 (in place of 100)
Also, don’t you need SellShort (in place of Sell) at Market at Line 22?
Attached might encourage you?
Hello Nicolas,
Many thanks for providing more insight.
So if Sell is the instruction used to close buy order, does it then follow that for bollinger upperband cross to become a signal (Sell in this case), then there should have been already in existence a corresponding bollinger lowerband cross signal (Buy). It also follows that in a setup where there are 1 lowerband cross signal(Buy) followed by 3 successive upperband crosses, only one of these 3 crosses will become a Sell signal to close the earlier 1 Buy signal, the remaining 2 crosses will not qualify for signal . Am i right?
Yes … we can only Sell (Close a Long) if we have a Buy / Long trade open.
Am i right?
Yes … the remaing two crosses / Sell signals will do nothing if there are no open Longs to Sell / Close.
@Grahal, thanks very much for the education, appreciated.
Hello,
I also need help to explain the attached screenshot where there are 5 consecutive Buy signals followed by 2 consecutive upperband crosses.
Only one of the upperband crosses converted to Sell signal to close one of the 5 Buy signals, leaving the other upperband cross as just a cross. Does it mean the remaining 4 Buy signals have been cancelled.
Also may i know whether it was the 1st, 2nd, 3rd, 4th or the 5th Buy signal that was closed by the Buy signal.
Regards