Hello,
I need help to find error in the strategy bellow, the code do not enter position.
here is strategy’s rules :
- Wait for 5 bar down in a row
- Confirm with RSI<10
- Wait for doji
- Take Profit in funtion of the entry price (50% of the downward move represented by the 5 precedents bars)
Hourly or Daily Datas.
//////////inputs
minbarsdown = 5
RSIthreshold = 10
dojispan = 0.10
proftarget = 0.50
exitbars=5
exitRSI=50
count = 0
n = 1
///////vars
mom = RSI[14](close)
doji = abs(open - close)/(high - low)
if close > close[1] then
count = count + 1
elsif close < close[1] then
count = 0
endif
//ENTRY
if count >= minbarsdown and mom <= RSIthreshold and doji < dojispan then
buy n shares at market
SET TARGET PROFIT (TRADEPRICE(1) + proftarget*(close[count] - close))
endif
//exit
if longonmarket and (mom > exitRSI or (BARINDEX-TRADEINDEX(1)) >= exitbars) then
sell n shares at market
ENDIF
Your code could be:
//////////inputs
minbarsdown = 5
RSIthreshold = 10
dojispan = 0.10
proftarget = 0.50
exitbars=5
exitRSI=50
n = 1
///////vars
mom = RSI[14](close)
doji = abs(open - close)/(high - low)
//ENTRY
if summation[5](close > close[1]) = minbarsdown and mom <= RSIthreshold and doji < dojispan then
buy n shares at market
SET TARGET PROFIT (TRADEPRICE(1) + proftarget*(close[count] - close))
endif
//exit
if longonmarket and (mom > exitRSI or (BARINDEX-TRADEINDEX(1)) >= exitbars) then
sell n shares at market
ENDIF
using SUMMATION is simpler and faster.
You wrote BARS DOWN, but actually your code (and mine) is counting BARS UP.
If you want to scan bearish bars, you just need to replace “>” with “<” at line 15 with SUMMATION.
Thanks Roberto,
But still doesn’t resolve the problem
Parameters are too strict, when DOJI is < 0.10 MOM is never below 10 (in my test). Try to test it with a higher value for RSIthreshold.
In my code you will be reported COUNT as not exixting. I don’t know what you are exactly using it for, but this is your original code with the addition of my solution:
//////////inputs
minbarsdown = 5
RSIthreshold = 10
dojispan = 0.10
proftarget = 0.50
exitbars=5
exitRSI=50
count = 0
n = 1
///////vars
mom = RSI[14](close)
doji = abs(open - close)/(high - low)
if close > close[1] then
count = count + 1
elsif close < close[1] then
count = 0
endif
//ENTRY
if summation[5](close > close[1]) = minbarsdown and mom <= RSIthreshold and doji < dojispan then
buy n shares at market
SET TARGET PROFIT (TRADEPRICE(1) + proftarget*(close[count] - close))
endif
//exit
if longonmarket and (mom > exitRSI or (BARINDEX-TRADEINDEX(1)) >= exitbars) then
sell n shares at market
ENDIF
moreover, your stop loss will never be reached because it’s a price, not a difference between prices which is what LOSS requires, on DAX it would be ove 13000 pips!, you should compute a difference, such as abs(HIGH – TradePrice(1)) or the like.
Perfect, i spotted the problem,
Thanks for your great help.
Gonna work on it and post results if they give something of interest.