Whats wrong with this code, it only takes short positions and not long. I want to run it on EUR/USD 1 h
I can’t see whats wrong but I am learning….
DEFPARAM CumulateOrders = False
// Define start and closing time
DEFPARAM FlatBefore = 080000
DEFPARAM FlatAfter = 210000
// Conditions and indicators for the system
//MA = Average[30](close) // Simple moving average
X = 4 // Number of contracts
cond1 = ((High[0]-Low[0])/2) > Supertrend[3,10] // Conditions for long positions
cond2 = ((High[0]-Low[0])/2) < Supertrend[3,10] // Conditions for short positions
// Long positions
IF (cond1) THEN
BUY X CONTRACTS AT MARKET
ENDIF
IF LONGONMARKET AND (cond2) THEN
SELL AT MARKET
ENDIF
// Short positions
IF (cond2) THEN
SELLSHORT X CONTRACTS AT MARKET
ENDIF
IF SHORTONMARKET AND cond1 THEN
EXITSHORT AT MARKET
ENDIF
// Stops and targets
SET STOP pTrailing 4
cond1 is never going to be > ST
cond2 is always going to be < ST
I often hesitate to help with code (as I’m great either! 🙂 ) but substitute values in your cond 1 and 2 and you will see. E.g. high 11230 high – 11210 low / 2 = 10 so it is always going to be lower than ST and never higher … unless you get the biggest spike ever seen? 🙂
cond1 = ((High[0]-Low[0])/2) > Supertrend[3,10] // Conditions for long positions
cond2 = ((High[0]-Low[0])/2) < Supertrend[3,10] // Conditions for short positions
If you use Close > Supertrend etc then it will work.
I suggest to modify lines 10-11 as follows (though this won’t affect performance, it’s just makes code easier to read:
cond1 = (range/2) > Supertrend[3,10] // Conditions for long positions
cond2 = (range/2) < Supertrend[3,10] // Conditions for short positions
I think if you switch the order in which trades are opened, Short ones first, the results would be only short trades.
You are comparing half the range with ST, I can’t imagine what your goal is.
After line 32 add these lines, then check those values in the variable window of ProBackTest each candle:
graph Range
graph Range/2
graph Supertrend[3,10]
Tnx for the respons, Im am trying too learn the program and how I can program.
Im am trying too learn the program and how I can program.
No probs, keep on asking no matter how daft it seems … I will probably learn something also! 🙂
I am trying too program an easy program for the 1 h EUR/USD but i don’t really get it too work. But i am learning every day…