Hi All,
This concept really caught my eye – I actually downloaded this as an indicator a while ago. I think it has some real use. On using it for shorter periods, it has an acceptable success rate – which is exciting as usually, you have to tweak parameters etc.
I wondered why it doesn’t also include short opportunities. Was there a specific reason? What would need to be added if that was feasible?
It also doesn’t follow the indicator sometimes (even when I tweak operational hours, pips etc), posting trades on ‘grey zones’ (occasionally after a ‘downward zone’) – is that correct and part of the strategy?
Of course as reference, I am using this indicator https://www.prorealcode.com/prorealtime-indicators/perfect-trend-line/
Best, Tom
Please find below the strategy that trade both long and short orders. I added stoploss and takeprofit as parameters. There is no longer bars wait between 2 orders of the same time. You might want to adapt the flatbefore and flatafter time too.
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
defparam flatbefore = 080000
defparam flatafter = 170000
// --- settings
SlowLength = 7 // Slow length
SlowPipDisplace = 0 // Slow pip displace
FastLength = 3 // Fast length
FastPipDisplace = 0 // Fast pip displace
MinDailyProfit = 1000 //Max daily loss allowed (in points)
StopLoss = 50
TakeProfit = 30
// --- end of settings
thigh1 = Highest[SlowLength](high)+ SlowPipDisplace*pointsize
tlow1 = Lowest[SlowLength](low)- SlowPipDisplace*pointsize
thigh2 = Highest[FastLength](high)+ FastPipDisplace*pointsize
tlow2 = Lowest[FastLength](low)- FastPipDisplace*pointsize
if barindex>2 then
if Close>line1[1] then
line1 = tlow1
else
line1 = thigh1
endif
if Close>line2[1] then
line2 = tlow2
else
line2 = thigh2
endif
endif
if (Close[0]<line1[0] and Close[0]<line2[0]) then
trend = 1
endif
if (Close[0]>line1[0] and Close[0]>line2[0]) then
trend = -1
endif
if (line1[0]>line2[0] or trend[0] = 1) then
trena = 1
endif
if (line1[0]<line2[0] or trend[0] = -1) then
trena = -1
endif
//----
// first time we launch the code, the trading is allowed
once TradeAllowed=1
if intradaybarindex=0 then
count=0
MyProfit=STRATEGYPROFIT
TradeAllowed=1
endif
// test if the strategyprofit of the day is currently above the daily profit allowed
If StrategyProfit>=MyProfit+(MinDailyProfit*POINTVALUE) then
TradeAllowed=0
endif
if TradeAllowed and trena<>trena[1] and trend=-1 and not longonmarket then
buy 1 contract at market
endif
if longonmarket and trend=1 then
sell at market
endif
if TradeAllowed and trena<>trena[1] and trend=1 and not shortonmarket then
sellshort 1 contract at market
endif
if shortonmarket and trend=-1 then
exitshort at market
endif
SET STOP PLOSS stoploss
SET TARGET PPROFIT takeprofit
Hi Nicholas,
Thanks so much for your reply – especially with your busy schedule.
I have moved forward with the code (learning as I go). I also have upped the period for the MAs as I wanted to trade over a higher timeframe (Daily) and increased the take profit etc. This will only trade on the GBPUSD.
It made sense to add trend detection to the code to try and steer clear of any ranging markets and found a simple logic (that I believe you may have made yourself a long time ago).
It works well in theory, and will require further tweaking, but it seems to only trade short positions! I have tweaked the MAs as I thought it could be misaligned with the cross of the perfect trend, but it still doesn’t seem to work!
I’d love to get your take on it.
Best,
Tom
// Definition of code parameters
DEFPARAM CumulateOrders = True // Cumulating positions deactivated
// --- settings
SlowLength = 20 // Slow length
SlowPipDisplace = 0 // Slow pip displace
FastLength = 10 // Fast length
FastPipDisplace = 0 // Fast pip displace
MinDailyProfit = 1000 //Max daily loss allowed (in points)
StopLoss = 50
TakeProfit = 300
//trend detection
ema = exponentialaverage[24](close)
ema2 = exponentialaverage[12](close)
//set trend using highs and lows
Trend1= highest[2](high)
Trend2= highest[5](high)
Trend3 = trend1-trend2
///
Trend4= lowest[2](low)
Trend5= lowest[5](low)
Trend6 = trend4-trend5
// --- end of settings
thigh1 = Highest[SlowLength](high)+ SlowPipDisplace*pointsize
tlow1 = Lowest[SlowLength](low)- SlowPipDisplace*pointsize
thigh2 = Highest[FastLength](high)+ FastPipDisplace*pointsize
tlow2 = Lowest[FastLength](low)- FastPipDisplace*pointsize
if barindex>2 then
if Close>line1[1] then
line1 = tlow1
else
line1 = thigh1
endif
if Close>line2[1] then
line2 = tlow2
else
line2 = thigh2
endif
endif
if (Close[0]<line1[0] and Close[0]<line2[0]) then
trend = 1
endif
if (Close[0]>line1[0] and Close[0]>line2[0]) then
trend = -1
endif
if (line1[0]>line2[0] or trend[0] = 1) then
trena = 1
endif
if (line1[0]<line2[0] or trend[0] = -1) then
trena = -1
endif
//----
// first time we launch the code, the trading is allowed
once TradeAllowed=1
if intradaybarindex=0 then
count=0
MyProfit=STRATEGYPROFIT
TradeAllowed=1
endif
// test if the strategyprofit of the day is currently above the daily profit allowed
If StrategyProfit>=MyProfit+(MinDailyProfit*POINTVALUE) then
TradeAllowed=0
endif
if TradeAllowed and trena<>trena[1] and trend=-1 and ema>ema2 and trend3 <0 and not longonmarket then
buy 2 contract at market
endif
if longonmarket and trend=1 then
sell at market
endif
if TradeAllowed and trena<>trena[1] and trend=1 and ema<ema2 and trend6 >-1 and not shortonmarket then
sellshort 2 contract at market
endif
if shortonmarket and trend=-1 then
exitshort at market
endif
SET STOP PLOSS stoploss
SET TARGET PPROFIT takeprofit