PP Month, problem getting it
Forums › ProRealTime English forum › ProOrder support › PP Month, problem getting it
- This topic has 13 replies, 3 voices, and was last updated 3 years ago by robertogozzi.
-
-
10/23/2020 at 7:12 PM #148276
Hello everyone!
I hope you are well.
I am coding a very simple code that sells or buys on the first cross of the Monthly PP. However I am not able to get it right. In the following code I can’t mange to get the correct Monthly PP…
Can someone help…? 🙂
Thanks!
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115//-------------------------------------------------------------------------// Code principal : PPM avec trailing stop//-------------------------------------------------------------------------//-------------------------------------------------------------------------// Code principal : MonSystème//-------------------------------------------------------------------------//-------------------------------------------------------------------------// Code principal : PPM avec trailing stop//-------------------------------------------------------------------------//-------------------------------------------------------------------------// Code principal : PPM avec trailing stop//-------------------------------------------------------------------------DEFPARAM Preloadbars = 10000// Cumul des positions désactivéDEFPARAM CumulateOrders = False//************************************************************************//Horaires de trading// Annule tous les ordres en attente et ferme toutes les positions à 0:00, puis empêche toute création d'ordre avant l'heure "FLATBEFORE".DEFPARAM FLATBEFORE = 080000// Annule tous les ordres en attente et ferme toutes les positions à l'heure "FLATAFTER"DEFPARAM FLATAFTER = 170000// Empêche le système de placer des ordres pour entrer sur le marché ou augmenter la taille d'une position avant l'heure spécifiéenoEntryBeforeTime = 080000timeEnterBefore = time >= noEntryBeforeTime// Empêche le système de placer des ordres pour entrer sur le marché ou augmenter la taille d'une position après l'heure spécifiéenoEntryAfterTime = 170000timeEnterAfter = time < noEntryAfterTime// Empêche le système de placer de nouveaux ordres sur les jours de la semaine spécifiésdaysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0//************************************************************************If Month<>Month[1] thenmonthlyHigh = Highest[max(1,BarIndex - lastMonthBarIndex)](High)[1]monthlyLow = Lowest[max(1,BarIndex - lastMonthBarIndex)](Low)[1]lastMonthBarIndex = BarIndexpp = (monthlyHigh + monthlyLow + Close[1]) / 3endifgraph ppIf Month<>Month[1] thenPremierpassage=0Endif//************************************************************************// Conditions pour ouvrir une position acheteusec1 = (close CROSSES UNDER pp)IF c1 AND timeEnterBefore AND timeEnterAfter AND Premierpassage=0 AND not daysForbiddenEntry THENBUY 1 CONTRACT AT MARKETPremierpassage=1SET STOP pLOSS 55ENDIF// Conditions pour ouvrir une position en vente à découvertc2 = (close CROSSES OVER pp)IF c2 AND timeEnterBefore AND timeEnterAfter AND Premierpassage=0 AND not daysForbiddenEntry THENSELLSHORT 1 CONTRACT AT MARKETPremierpassage=1SET STOP pLOSS 55ENDIFIf Premierpassage=0 and c1 or c2 thenPremierpassage=1endif//************************************************************************//trailing stop functiontrailingstart = 15 //trailing will start @trailinstart points profittrailingstep = 5 //trailing step to move the "stoploss"//reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN//first move (breakeven)IF newSL=0 AND close-tradeprice(1)>=trailingstart THENnewSL = tradeprice(1)+trailingstepENDIF//next movesIF newSL>0 AND close-newSL>=trailingstep THENnewSL = newSL+trailingstepENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL=0 AND tradeprice(1)-close>=trailingstart THENnewSL = tradeprice(1)-trailingstepENDIF//next movesIF newSL>0 AND newSL-close>=trailingstep THENnewSL = newSL-trailingstepENDIFENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIF10/23/2020 at 7:16 PM #148280As English is the language you chose to use, this topic is moved from french proorder forum to english proorder forum, please see rules in yellow box below created in order to make sure the forums remain tidy for everybody’s ease of use, thank you
10/23/2020 at 7:29 PM #14828710/23/2020 at 11:50 PM #148296Make sure line 2 of the indicator reads:
1Once mode = 0since you are using MODE 0.
10/26/2020 at 10:15 AM #148485Thanks @Robertogozzi. However I can’tfigure out what you mean… If I add it to line 2 it gets me an error…
10/26/2020 at 11:25 AM #148497How do you know the values differ?
I think because the indicator (by Nicolas) from which you copied the formula plots a different value, doesn’t it? Well… the predefined mode in that indicator is 1, while your code uses mode 0, change mode in your code or the initial default setting in the indicator.
10/26/2020 at 12:52 PM #148501For instance, when I write “graph pp”, in August, the Monthly PP was 12624.33 and the instruction above that I use in the code give me a different value, whatever the mode of calculation… I can’t find the real Monthly PP…
Do you have suggestions?
10/26/2020 at 12:53 PM #148503Here is another version of the code that I tried but no evolution. Still wrong calculation of the monthly PP
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123//-------------------------------------------------------------------------// Code principal : PPM avec trailing stop//-------------------------------------------------------------------------//-------------------------------------------------------------------------// Code principal : MonSystème//-------------------------------------------------------------------------//-------------------------------------------------------------------------// Code principal : PPM avec trailing stop//-------------------------------------------------------------------------//-------------------------------------------------------------------------// Code principal : PPM avec trailing stop//-------------------------------------------------------------------------DEFPARAM Preloadbars = 10000// Cumul des positions désactivéDEFPARAM CumulateOrders = False//************************************************************************//Horaires de trading// Annule tous les ordres en attente et ferme toutes les positions à 0:00, puis empêche toute création d'ordre avant l'heure "FLATBEFORE".DEFPARAM FLATBEFORE = 080000// Annule tous les ordres en attente et ferme toutes les positions à l'heure "FLATAFTER"DEFPARAM FLATAFTER = 170000// Empêche le système de placer des ordres pour entrer sur le marché ou augmenter la taille d'une position avant l'heure spécifiéenoEntryBeforeTime = 080000timeEnterBefore = time >= noEntryBeforeTime// Empêche le système de placer des ordres pour entrer sur le marché ou augmenter la taille d'une position après l'heure spécifiéenoEntryAfterTime = 170000timeEnterAfter = time < noEntryAfterTime// Empêche le système de placer de nouveaux ordres sur les jours de la semaine spécifiésdaysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0//************************************************************************timeframe(5 minutes,updateonclose)mode = 1If Month<>Month[1] thenmonthlyHigh = Highest[BarIndex - lastMonthBarIndex](High)[1]monthlyLow = Lowest[BarIndex - lastMonthBarIndex](Low)[1]lastMonthBarIndex = BarIndexIf mode = 0 thenpp = (monthlyHigh + monthlyLow + Close[1]) / 3Elsif mode = 1 thenpp = (Open + monthlyHigh + monthlyLow + Close[1]) / 4Elsif mode = 2 thenpp = (monthlyHigh + monthlyLow + Close[1]*2) / 4Elsepp = (Open*2 + monthlyHigh + monthlyLow) / 4EndifEndiftimeframe(default)Graph ppIf Month<>Month[1] thenPremierpassage=0Endif//************************************************************************// Conditions pour ouvrir une position acheteusec1 = (close CROSSES UNDER pp)IF c1 AND timeEnterBefore AND timeEnterAfter AND Premierpassage=0 AND not daysForbiddenEntry THENBUY 1 CONTRACT AT MARKETPremierpassage=1SET STOP pLOSS 55ENDIF// Conditions pour ouvrir une position en vente à découvertc2 = (close CROSSES OVER pp)IF c2 AND timeEnterBefore AND timeEnterAfter AND Premierpassage=0 AND not daysForbiddenEntry THENSELLSHORT 1 CONTRACT AT MARKETPremierpassage=1SET STOP pLOSS 55ENDIF//************************************************************************//trailing stop functiontrailingstart = 15 //trailing will start @trailinstart points profittrailingstep = 5 //trailing step to move the "stoploss"//reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN//first move (breakeven)IF newSL=0 AND close-tradeprice(1)>=trailingstart THENnewSL = tradeprice(1)+trailingstepENDIF//next movesIF newSL>0 AND close-newSL>=trailingstep THENnewSL = newSL+trailingstepENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL=0 AND tradeprice(1)-close>=trailingstart THENnewSL = tradeprice(1)-trailingstepENDIF//next movesIF newSL>0 AND newSL-close>=trailingstep THENnewSL = newSL-trailingstepENDIFENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIF10/26/2020 at 1:40 PM #148507As asked you before, why do you say it is incorrect?
What is the correct value (and how is it calculated)?
10/26/2020 at 1:46 PM #14850810/26/2020 at 2:15 PM #14851310/26/2020 at 3:30 PM #148519OpenMonth (not Month) should be used, replace line 40 with:
1OpenMonth<>OpenMonth[1]10/26/2020 at 4:35 PM #148534Thanks @Robertogozzi, it helps a bit I think but didn’t solve the problem…
Do you have a Monthly PP code that works for you in 1 minute timeframe ?
Here is a picture of what it gives me and what’s real in PRT…
10/26/2020 at 4:46 PM #148537Your code above works fine, but uou’ll have to OpenMonth throughout your code, not just line 40. And you have to use enough bars (I used 100K 1-minute units).
-
AuthorPosts
Find exclusive trading pro-tools on