Perfect Trend Indicator with automatic trading
Forums › ProRealTime English forum › ProOrder support › Perfect Trend Indicator with automatic trading
- This topic has 17 replies, 2 voices, and was last updated 2 years ago by Mitchy14.
-
-
09/28/2022 at 12:31 PM #201560
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
09/30/2022 at 8:13 AM #201689Please 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.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivateddefparam flatbefore = 080000defparam flatafter = 170000// --- settingsSlowLength = 7 // Slow lengthSlowPipDisplace = 0 // Slow pip displaceFastLength = 3 // Fast lengthFastPipDisplace = 0 // Fast pip displaceMinDailyProfit = 1000 //Max daily loss allowed (in points)StopLoss = 50TakeProfit = 30// --- end of settingsthigh1 = Highest[SlowLength](high)+ SlowPipDisplace*pointsizetlow1 = Lowest[SlowLength](low)- SlowPipDisplace*pointsizethigh2 = Highest[FastLength](high)+ FastPipDisplace*pointsizetlow2 = Lowest[FastLength](low)- FastPipDisplace*pointsizeif barindex>2 thenif Close>line1[1] thenline1 = tlow1elseline1 = thigh1endifif Close>line2[1] thenline2 = tlow2elseline2 = thigh2endifendifif (Close[0]<line1[0] and Close[0]<line2[0]) thentrend = 1endifif (Close[0]>line1[0] and Close[0]>line2[0]) thentrend = -1endifif (line1[0]>line2[0] or trend[0] = 1) thentrena = 1endifif (line1[0]<line2[0] or trend[0] = -1) thentrena = -1endif//----// first time we launch the code, the trading is allowedonce TradeAllowed=1if intradaybarindex=0 thencount=0MyProfit=STRATEGYPROFITTradeAllowed=1endif// test if the strategyprofit of the day is currently above the daily profit allowedIf StrategyProfit>=MyProfit+(MinDailyProfit*POINTVALUE) thenTradeAllowed=0endifif TradeAllowed and trena<>trena[1] and trend=-1 and not longonmarket thenbuy 1 contract at marketendifif longonmarket and trend=1 thensell at marketendifif TradeAllowed and trena<>trena[1] and trend=1 and not shortonmarket thensellshort 1 contract at marketendifif shortonmarket and trend=-1 thenexitshort at marketendifSET STOP PLOSS stoplossSET TARGET PPROFIT takeprofit10/03/2022 at 12:04 PM #201834Hi 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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990// Definition of code parametersDEFPARAM CumulateOrders = True // Cumulating positions deactivated// --- settingsSlowLength = 20 // Slow lengthSlowPipDisplace = 0 // Slow pip displaceFastLength = 10 // Fast lengthFastPipDisplace = 0 // Fast pip displaceMinDailyProfit = 1000 //Max daily loss allowed (in points)StopLoss = 50TakeProfit = 300//trend detectionema = exponentialaverage[24](close)ema2 = exponentialaverage[12](close)//set trend using highs and lowsTrend1= highest[2](high)Trend2= highest[5](high)Trend3 = trend1-trend2///Trend4= lowest[2](low)Trend5= lowest[5](low)Trend6 = trend4-trend5// --- end of settingsthigh1 = Highest[SlowLength](high)+ SlowPipDisplace*pointsizetlow1 = Lowest[SlowLength](low)- SlowPipDisplace*pointsizethigh2 = Highest[FastLength](high)+ FastPipDisplace*pointsizetlow2 = Lowest[FastLength](low)- FastPipDisplace*pointsizeif barindex>2 thenif Close>line1[1] thenline1 = tlow1elseline1 = thigh1endifif Close>line2[1] thenline2 = tlow2elseline2 = thigh2endifendifif (Close[0]<line1[0] and Close[0]<line2[0]) thentrend = 1endifif (Close[0]>line1[0] and Close[0]>line2[0]) thentrend = -1endifif (line1[0]>line2[0] or trend[0] = 1) thentrena = 1endifif (line1[0]<line2[0] or trend[0] = -1) thentrena = -1endif//----// first time we launch the code, the trading is allowedonce TradeAllowed=1if intradaybarindex=0 thencount=0MyProfit=STRATEGYPROFITTradeAllowed=1endif// test if the strategyprofit of the day is currently above the daily profit allowedIf StrategyProfit>=MyProfit+(MinDailyProfit*POINTVALUE) thenTradeAllowed=0endifif TradeAllowed and trena<>trena[1] and trend=-1 and ema>ema2 and trend3 <0 and not longonmarket thenbuy 2 contract at marketendifif longonmarket and trend=1 thensell at marketendifif TradeAllowed and trena<>trena[1] and trend=1 and ema<ema2 and trend6 >-1 and not shortonmarket thensellshort 2 contract at marketendifif shortonmarket and trend=-1 thenexitshort at marketendifSET STOP PLOSS stoplossSET TARGET PPROFIT takeprofit -
AuthorPosts
Find exclusive trading pro-tools on