Magic Trend strategy
Forums › ProRealTime English forum › ProOrder support › Magic Trend strategy
- This topic has 4 replies, 5 voices, and was last updated 2 years ago by robertogozzi.
-
-
09/16/2021 at 10:49 AM #177707
Help Coding strategy
Magic trend Strategy1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071//==========================================================================================================DEFPARAM CUMULATEORDERS = falseDEFPARAM PRELOADBARS = 10000cciP = 20atrP = 14atrM = 1smaP = 5cciP = max(1,min(999,cciP))atrP = max(1,min(999,atrP))atrM = max(0.0000001,min(999,atrM))smaP = max(1,min(999,smaP))//IF BarIndex > max(cciP,atrP) THENlastCCI = thisCCIthisCCI = CCI[cciP](typicalPrice)myATR = AverageTrueRange[atrP](close)//temp1 = myATR * atrMupT = low - temp1downT = high + temp1//temp2 = Average[smaP,0](myATR) * atrMbuffDN = high + temp2buffUP = low - temp2//IF (thisCCI >= 0) AND (lastCCI < 0) THENbuffUP = buffDN[1]ENDIFIF (thisCCI <= 0) AND (lastCCI > 0) THENbuffDN = buffUP[1]ENDIFIF (thisCCI >= 0) THENIF (buffUP < buffUP[1]) THENbuffUP = buffUP[1]ENDIFELSIF (thisCCI <= 0) THENIF (buffDN > buffDN[1]) THENbuffDN = buffDN[1]ENDIFENDIFIF thisCCI >= 0 THENMagicTrend = buffUPELSIF thisCCI <= 0 THENMagicTrend = buffDNENDIFELSEthisCCI = 0lastCCI = 0myATR = 0buffUP = 0buffDN = 0buffDN = 0buffUP = 0MagicTrend = 0ENDIF// Conditions to enter long positionsIF buffUP=1 THENBUY 1 CONTRACTS AT MARKETSET STOP %LOSS 1 //sl=1set target %profit 2 //TP=2ENDIF// Conditions to exit long positionsIf buffDN=1 THENSELL AT MARKETSET STOP %LOSS 1 //sl=1set target %profit 2 //TP=2ENDIFWhats Wrong with this code?
09/16/2021 at 11:18 AM #177711Try below in place of your Lines 59 to 71 above …
12345678910111213141516Lng = Close crosses over buffUpSht = Close crosses under buffDn// Conditions to enter long positionsIF Lng THENBUY 1 CONTRACTS AT MARKETSET STOP %LOSS 1 //sl=1set target %profit 2 //TP=2ENDIF// Conditions to exit long positionsIf Sht THENSELLShort AT MARKETSET STOP %LOSS 1 //sl=1set target %profit 2 //TP=2ENDIF1 user thanked author for this post.
01/05/2023 at 8:32 PM #206854Hi,
i wont buy or sell by a crossover, only if the trend is change.
If the trend goes down the i want have a sell signal, if the trend goes up i want have a buy signal.
If the color from the trend switch from green to red sell, from red to green buy.
I have no idea how to code this.
thx for help.
01/06/2023 at 4:25 PM #206903Hello Killerplautze is just a simple code maybe it will help 😉
123456789101112131415161718192021222324252627282930313233// Festlegen der Code-ParameterDEFPARAM CumulateOrders = False // Kumulieren von Positionen deaktiviertmyMagicTrend = CALL "Magic Trend custom"[20, 9, 2, 5]Gruen = myMagicTrend > myMagicTrend[1]Rot = myMagicTrend < myMagicTrend[1]// Verhindert das Trading an bestimmten WochentagendaysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0// Bedingungen zum Einstieg in Long-PositionenIF Gruen AND not daysForbiddenEntry THENBUY 1 CONTRACT AT MARKETENDIF// Bedingungen zum Ausstieg von Long-PositionenIF Rot THENSELL AT MARKETENDIF// Bedingungen zum Einstieg in Short-PositionenIF Rot AND not daysForbiddenEntry THENSELLSHORT 1 CONTRACT AT MARKETENDIF// Bedingungen zum Ausstieg aus Short-PositionenIF gruen THENEXITSHORT AT MARKETENDIF1 user thanked author for this post.
01/10/2023 at 6:11 PM #207193i wont buy or sell by a crossover, only if the trend is change. If the trend goes down the i want have a sell signal, if the trend goes up i want have a buy signal. If the color from the trend switch from green to red sell, from red to green buy
This IS exactly what a crossover does, as @GraHal coded.
The code posted by @Razz , only checks when the Magic Trend rises or falls, not when a crossover occurs.1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on