Hi, I’ve a problem with a strategy. It’s a simple strategy that buy when the value of the indicator leaves -100 and sell when the value of the indicator leaves 100.
But I don’t know why strategy has wrong signals. I’ve tried with other markets, but I’ve the same problem. It’s probably an oversight of mine but I can’t find it. Thank you to those who want to help me.
Give your topic a meaningful title.Describe your question or your subject in your title. Do not use meaningless titles such as ‘Coding Help Needed’.
Thank you 🙂
If your code is not hundreds of lines, post it please.
Sorry for my title Roberto.
Here the indicator:
HighMom = DHigh(0) - DHigh(2)
LowMom = DLow(0) - DLow(2 )
Cond1 = (DHigh(0) >= Dlow(5) OR DHigh(0) >= DLow(6) )
Cond2 = ( DHigh(2) >= DClose(7) OR DHigh(2) >= DClose (8) )
Cond3 = ( DLow(0) <= DHigh (5) OR DLow(0) <= DHigh(6) )
Cond4 = (DLow(2) <= DClose(7) OR DLow(2) <= DClose(8) )
Cond = ( Cond1 OR Cond2 ) AND ( Cond3 OR Cond4 )
IF Cond then
Num = HighMom + LowMom
Else
Num = 0
ENDIF
Den = ABS( HighMom ) + ABS( LowMom )
TDREI = 100 * Summation [5](Num) / Summation [5] (Den)
SignBuy=0
SignSell=0
if TDREI[1]=100 and TDREI<100 then
SignSell=1
endif
if TDREI[1]=-100 and TDREI>-100 then
SignBuy=1
endif
return TDREI,SignSell as "Sell",SignBuy as "Buy"
And here the strategy
shorta = 0
compra = 0
copri = 0
vendi = 0
signal,SignSell,SignBuy=Call "TD REI"
//if signal[1]>99 and signal<99 then
if SignSell=1 then
Shorta=1
Vendi=1
endif
//if signal[1]<-99 and signal>-99 then
if SignBuy=1 then
Compra=1
copri = 1
endif
REM - * - * -* - Comincio le azioni - * - * - * -
NumContrattiMax=2
IF LongOnMarket and (vendi or shorta) THEN
SELL AT MARKET
ENDIF
IF ShortOnMarket and (copri or compra) THEN
EXITSHORT AT MARKET
ENDIF
IF shorta and COUNTOFSHORTSHARES<NumContrattiMax THEN
SELLSHORT 1 contracts at market
SET STOP %LOSS SLLong*0.1
SET TARGET %PROFIT TPLong*0.1
ENDIF
IF compra and COUNTOFLONGSHARES<NumContrattiMax THEN
buy 1 contracts at market
SET STOP %LOSS SLLong*0.1
SET TARGET %PROFIT TPLong*0.1
ENDIF
Thanks
Firstly, your indicator returns 1 for both sell and buy signal making them difficult to see on the chart, I suggest that you replace lines 21 and 24 of your indicator with:
SignSell = -50 //line21
SignBuy = 50 //line 24
you don’t have to change the code in your strategy because they are TRUE being <> 0, but can easily be spotted on the chart.
Secondly, you have added a variable named NumContrattiMax, but it can only be 1 unless you set line 1 to TRUE.
Thirdly, you have added two variables, TPLong and SLLong as if you wanted to make those values for Long trades different from the Short ones, but you are using the same variables for both Long and Short trades.
The trade you are talking about seems to have been opened on Dec. 7th at 01:00 (you did not specify any daye & time, which you should always do, instead) accorduing to the SHORT signal from the prior candle as you can see from my pic (-50).
Everything seems fine to me.
Thank you Roberto.
- I’ve changed to -50 and 50 so I can see better on the chart.
- Yes, that’s right, this is a generic strategy that I use to test my ideas. So it’s not all fine. I need to see how the indicator works. But you’re right, it’s useless if the first line is set to “False” value.
- Yes, that’s right, as point 2, I’ve use this code to see how the indicator works.
The different between me and you is the TD value. In that trade I’ve the indicator at 100 not less than 100. You can also see that I’ve not -5 sell signals on the bottom of the chart. I’ve dont’t understand why.
Same problem on 1 hour DAX chart.
3 strange position that I’ve circled
Prova ad usare questa versione dell’indicatore:
Try using this version:
HighMom = DHigh(0) - DHigh(2)
LowMom = DLow(0) - DLow(2 )
Cond1 = (DHigh(0) >= Dlow(5) OR DHigh(0) >= DLow(6) )
Cond2 = ( DHigh(2) >= DClose(7) OR DHigh(2) >= DClose (8) )
Cond3 = ( DLow(0) <= DHigh (5) OR DLow(0) <= DHigh(6) )
Cond4 = (DLow(2) <= DClose(7) OR DLow(2) <= DClose(8) )
Cond = ( Cond1 OR Cond2 ) AND ( Cond3 OR Cond4 )
IF Cond then
Num = HighMom + LowMom
Else
Num = 0
ENDIF
Den = ABS( HighMom ) + ABS( LowMom )
TDREI = 100 * Summation [5](Num) / Summation [5] (Den)
SignBuy=0
SignSell=0
if TDREI[1]=100 and TDREI<100 then
SignSell=-50
endif
if TDREI[1]=-100 and TDREI>-100 then
SignBuy=50
endif
return TDREI AS "Td Rei",SignSell as "Sell",SignBuy as "Buy"
Same result Roberto.
It’s not so important, this indicator doesn’t do what I’m expected, and I think that I don’t use in the future. Anyway it’s very strange, I’ve write many strategies in the past and this is the first time that happen this strange behavior