how to code multiple consecutive conditions with MACD?
Forums › ProRealTime English forum › ProBuilder support › how to code multiple consecutive conditions with MACD?
- This topic has 17 replies, 3 voices, and was last updated 2 years ago by robertogozzi.
-
-
02/28/2022 at 5:13 PM #189073
hi everyone,
I’m trying to turn this image into code, could you help me or is there something similar that is already coded?
how to detect :
– X bar red
– X bars green
– finaly X bars redor in the same idea how to detect :
– MACD > S-Line on X bars
– MACD < S-Line on X bars
– finaly MACD > S-Line on X bars02/28/2022 at 6:29 PM #189088#1
#1123456789101112131415p1 = 3p2 = 2p3 = 2MyHisto = MACD[12,26,9](close) //Histogram//MySignal = ExponentialAverage[9](MACDline[12,26,9](close)) //Signal//MyMACD = MACDline[12,26,9](close) //Macd//RedHisto = MyHisto < 0GreenHisto = MyHisto > 0Red1 = summation[p1](RedHisto[p2 + p3]) = p1Green1 = summation[p2](GreenHisto[p3]) = p2Red2 = summation[p3](RedHisto) = p3//Cond = Red1 AND Green1 AND Red2RETURN Cond#2
#2123456789101112131415p1 = 3p2 = 2p3 = 2//MyHisto = MACD[12,26,9](close) //HistogramMySignal = ExponentialAverage[9](MACDline[12,26,9](close)) //SignalMyMACD = MACDline[12,26,9](close) //Macd//RedPattern = MyMACD < MySignalGreenPattern = MyMACD > MySignalGreen1 = summation[p1](GreenPattern[p2 + p3]) = p1Red1 = summation[p2](RedPattern[p3]) = p2Green2 = summation[p3](GreenPattern) = p3//Cond = Green1 AND Red1 AND Green2RETURN Cond1 user thanked author for this post.
02/28/2022 at 6:35 PM #189091tks you so much, in addition I just bought Nicolas’ training ;-), and tks agin 🙂
1 user thanked author for this post.
02/28/2022 at 6:45 PM #189092I tryed the both code and get all the time 0, it’s mean the condition is never reached, but it’s will help me for my home work,
what is mean using the summation here ? and why Px :
123p1 = 3p2 = 2p3 = 2not easy for me to understand
02/28/2022 at 9:43 PM #189096p1 is the first periods, p2 is the second period and p3 is the last period (the latest bars).
I was returned many items on shares.
You can test it as a screener replacing the last line with
1Screener[Cond]1 user thanked author for this post.
03/05/2022 at 7:14 PM #189419Big tks to your answere, I do to much time to understand the logic, I’m to old :-), how to detect the lowest Red2 and Red1 persiode pls ?
123456789101112131415161718192021p1 = 3p2 = 6p3 = 2MyHisto = MACD[12,26,9](close) //Histogram//MySignal = ExponentialAverage[9](MACDline[12,26,9](close)) //Signal//MyMACD = MACDline[12,26,9](close) //Macd//RedHisto = MyHisto < 0GreenHisto = MyHisto > 0Red1 = summation[p1](RedHisto[p2 + p3]) = p1Green1 = summation[p2](GreenHisto[p3]) = p2Red2 = summation[p3](RedHisto) = p3LowestRed2 = lowest[P3]LowestRed1 = lowest[P2+P3]Div = LowestRed2 < LowestRed1Cond = Red1 AND Green1 AND Red2 AND DivScreener[Cond]tks in advance
03/06/2022 at 11:36 AM #189437I am attaching a diagram, both as a Pic and eXcel file.
I hope it’s clear.
1 user thanked author for this post.
03/06/2022 at 8:00 PM #189455Hi Roberto,
Your explanations are not clear but Very Clear, so that is the code and the photo of Excel files :
123456789101112131415161718192021p1 = 3p2 = 6p3 = 2MyHisto = MACD[12,26,9](close) //Histogram//MySignal = ExponentialAverage[9](MACDline[12,26,9](close)) //Signal//MyMACD = MACDline[12,26,9](close) //Macd//RedHisto = MyHisto < 0GreenHisto = MyHisto > 0Red1 = summation[p1](RedHisto[p2 + p3]) = p1Green1 = summation[p2](GreenHisto[p3]) = p2Red2 = summation[p3](RedHisto) = p3LowestRed2 = lowest[P3](Low)LowestRed1 = lowest[P1](Low[P2+P3])Div = LowestRed2 < LowestRed1Cond = Red1 AND Green1 AND Red2 AND DivScreener[Cond]now the question is how to use Px as a variable, I mean for exemple the P2 it’s was maybe 3 or 6 or 10 ?, you can also give me just a link if you have and I will work on it, and tks again for your help
03/07/2022 at 10:13 AM #189471I modified the title of the topic, please try to
- 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’.
1 user thanked author for this post.
03/07/2022 at 11:53 AM #189498You can simply use several constants, p1, p2 and p3, like I did in the code above, or you can use arrays to store as many values you need:
12345$p[1] = 3$p[2] = 6$p[3] = 3..1 user thanked author for this post.
03/07/2022 at 12:28 PM #189502ok tks you, I don’t understand what is mean the $p ?, about array I don’t know because I never learn about it but I can imagine the idea you want to tell me,
so I hope this is my last question for this thread, do you think it will be beter to make this screener with a FOR boucle condition to detect what I need in like this exemple :
12345678910111213141516171819202122232425//Somethink like thisFOR Y = 0 To 10 DOIF ConditionRed THENEndRed2 = YRED2 = 1BreakELSERED2 = 0ENDIFNEXTIF RED2 THENFOR X = EndRed2 To EndRed2+10IF ConditionGreen THENEndGreen1 = XGreen1 = 1BreakELSEGreen1 = 0ENDIFNEXTENDIF...Best Reguards
03/07/2022 at 12:49 PM #189505$p[] is an array. You can find info at https://www.prorealcode.com/topic/array-variables-availability-in-prorealtime/.
No, your example is not correct.
If you can explain your idea with more details I may try to help you. If you mean to apply arrays to the code above, then my answer is no, you can’t, because of the logic behind that code.
1 user thanked author for this post.
03/07/2022 at 1:50 PM #189515tks again for your answers, I will get time and make somethink as an indicator or as a screener and try if my idea and what I have in my head can work or not and put the result here, maybe 2 or 3 days I hope no more, tks again roberto for all your help
03/07/2022 at 7:37 PM #189572hi all
I think I found what I want as an indicator, I will try to change it as a screener, I have a problem to code directly a screener because I can’t draw on it, or maybe they have solution, so I made this () code can detect what I want, like you to in your exemple
P3 = Red2 (from bar IDs 0 to 10)
P2 = Green1 (from bar IDs X3 to X3+10)
P1 = Red1 (from bar IDs X2 to X2+50)and I think we can change the first 10 to a variable and the 50 to a variable too, that is the code :
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667Defparam drawonlastbaronly = true// Attribu :MyMACD = MACDline[12,26,9](close)MySLine = MACDSignal[12,26,9](close)MyHis = MACD[12,26,9](close)// (。♥‿♥。) Block Start// Block End (。♥‿♥。)IF MyMACD < 0 AND MySLine < 0 THEN// (。♥‿♥。) Block Start P3//BACKGROUNDCOLOR (0, 155, 10, 25)FOR X3 = 0 To 10 Do//IF MyMACD[Y] Crosses Under MySLine[Y] AND MyMACD[Y] < 0 AND MySLine[Y] < 0 THENIF MyMACD[X3] Crosses Under MySLine[X3] THENAbscisseP3 = X3BarP3 = Barindex[X3]CP3 = 1Drawtext("#X3#", Barindex[X3], Low[X3]-1)DRAWELLIPSE(BarP3-1,LOW[X3]-10,BarP3+1,HIGH[X3]+10)coloured(255,10,10)BreakELSECP3 = 0ENDIFNext// Block End (。♥‿♥。)P3// (。♥‿♥。) Block Start P2IF CP3 THENFOR X2 = X3 To X3+10 Do//IF MyMACD[Y] Crosses Under MySLine[Y] AND MyMACD[Y] < 0 AND MySLine[Y] < 0 THENIF MyMACD[X2] Crosses Over MySLine[X2] THENAbscisseP2 = X2BarP2 = Barindex[X2]CP2 = 1Drawtext("#X2#", Barindex[X2], Low[X2]-1)DRAWELLIPSE(BarP2-1,LOW[X2]-10,BarP2+1,HIGH[X2]+10)coloured(255,10,10)BreakELSECP2 = 0ENDIFNextENDIF// Block End (。♥‿♥。)P2// (。♥‿♥。) Block Start P1IF CP2 THENFOR X1 = X2 To X2+50 Do//IF MyMACD[Y] Crosses Under MySLine[Y] AND MyMACD[Y] < 0 AND MySLine[Y] < 0 THENIF MyMACD[X1] Crosses Under MySLine[X1] THENAbscisseP1 = X1BarP1 = Barindex[X1]CP1 = 1Drawtext("#X1#", Barindex[X1], Low[X1]-1)DRAWELLIPSE(BarP1-1,LOW[X1]-10,BarP1+1,HIGH[X1]+10)coloured(255,10,10)BreakELSECP1 = 0ENDIFNextENDIF// Block End (。♥‿♥。)P1ENDIF// tks to the Nisola's Cours ;-)Returnand I also add a photo for the understanding
d
03/11/2022 at 1:19 PM #189802This is the code that I modified to:
- use PipSize, otherwise it will plot correctly only on instruments with a pip ratio of 1
- replace the offset of graphic objects with a variable named OFFSET
- replace 10 and 50 periods, with variables P1 and P2:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869Defparam drawonlastbaronly = true// Attribu :MyMACD = MACDline[12,26,9](close)MySLine = MACDSignal[12,26,9](close)MyHis = MACD[12,26,9](close)Offset = 10 * pipsizep1 = 10p2 = 50// (。♥‿♥。) Block Start// Block End (。♥‿♥。)IF MyMACD < 0 AND MySLine < 0 THEN// (。♥‿♥。) Block Start P3//BACKGROUNDCOLOR (0, 155, 10, 25)FOR X3 = 0 To p1 Do//IF MyMACD[Y] Crosses Under MySLine[Y] AND MyMACD[Y] < 0 AND MySLine[Y] < 0 THENIF MyMACD[X3] Crosses Under MySLine[X3] THENAbscisseP3 = X3BarP3 = Barindex[X3]CP3 = 1Drawtext("#X3#", Barindex[X3], Low[X3]-1)DRAWELLIPSE(BarP3-1,LOW[X3]-Offset,BarP3+1,HIGH[X3]+Offset)coloured(255,10,10)BreakELSECP3 = 0ENDIFNext// Block End (。♥‿♥。)P3// (。♥‿♥。) Block Start P2IF CP3 THENFOR X2 = X3 To X3+p1 Do//IF MyMACD[Y] Crosses Under MySLine[Y] AND MyMACD[Y] < 0 AND MySLine[Y] < 0 THENIF MyMACD[X2] Crosses Over MySLine[X2] THENAbscisseP2 = X2BarP2 = Barindex[X2]CP2 = 1Drawtext("#X2#", Barindex[X2], Low[X2]-1)DRAWELLIPSE(BarP2-1,LOW[X2]-Offset,BarP2+1,HIGH[X2]+Offset)coloured(255,10,10)BreakELSECP2 = 0ENDIFNextENDIF// Block End (。♥‿♥。)P2// (。♥‿♥。) Block Start P1IF CP2 THENFOR X1 = X2 To X2+p2 Do//IF MyMACD[Y] Crosses Under MySLine[Y] AND MyMACD[Y] < 0 AND MySLine[Y] < 0 THENIF MyMACD[X1] Crosses Under MySLine[X1] THENAbscisseP1 = X1BarP1 = Barindex[X1]CP1 = 1Drawtext("#X1#", Barindex[X1], Low[X1]-1)DRAWELLIPSE(BarP1-1,LOW[X1]-Offset,BarP1+1,HIGH[X1]+Offset)coloured(255,10,10)BreakELSECP1 = 0ENDIFNextENDIF// Block End (。♥‿♥。)P1ENDIF// tks to the Nisola's Cours ;-)Returnand this is the screener:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869//Defparam drawonlastbaronly = trueMyMACD = MACDline[12,26,9](close)MySLine = MACDSignal[12,26,9](close)//MyHis = MACD[12,26,9](close)//Offset = 10 * pipsizep1 = 10p2 = 50// (。♥‿♥。) Block Start// Block End (。♥‿♥。)IF MyMACD < 0 AND MySLine < 0 THEN// (。♥‿♥。) Block Start P3//BACKGROUNDCOLOR (0, 155, 10, 25)FOR X3 = 0 To p1 Do//IF MyMACD[Y] Crosses Under MySLine[Y] AND MyMACD[Y] < 0 AND MySLine[Y] < 0 THENIF MyMACD[X3] Crosses Under MySLine[X3] THEN//AbscisseP3 = X3//BarP3 = Barindex[X3]CP3 = 1//Drawtext("#X3#", Barindex[X3], Low[X3]-1)//DRAWELLIPSE(BarP3-1,LOW[X3]-Offset,BarP3+1,HIGH[X3]+Offset)coloured(255,10,10)BreakELSECP3 = 0ENDIFNext// Block End (。♥‿♥。)P3// (。♥‿♥。) Block Start P2IF CP3 THENFOR X2 = X3 To X3+p1 Do//IF MyMACD[Y] Crosses Under MySLine[Y] AND MyMACD[Y] < 0 AND MySLine[Y] < 0 THENIF MyMACD[X2] Crosses Over MySLine[X2] THEN//AbscisseP2 = X2//BarP2 = Barindex[X2]CP2 = 1//Drawtext("#X2#", Barindex[X2], Low[X2]-1)//DRAWELLIPSE(BarP2-1,LOW[X2]-Offset,BarP2+1,HIGH[X2]+Offset)coloured(255,10,10)BreakELSECP2 = 0ENDIFNextENDIF// Block End (。♥‿♥。)P2// (。♥‿♥。) Block Start P1IF CP2 THENFOR X1 = X2 To X2+p2 Do//IF MyMACD[Y] Crosses Under MySLine[Y] AND MyMACD[Y] < 0 AND MySLine[Y] < 0 THENIF MyMACD[X1] Crosses Under MySLine[X1] THEN//AbscisseP1 = X1//BarP1 = Barindex[X1]CP1 = 1//Drawtext("#X1#", Barindex[X1], Low[X1]-1)//DRAWELLIPSE(BarP1-1,LOW[X1]-Offset,BarP1+1,HIGH[X1]+Offset)coloured(255,10,10)BreakELSECP1 = 0ENDIFNextENDIF// Block End (。♥‿♥。)P1ENDIF// tks to the Nisola's Cours ;-)Cond = CP1 AND CP2 AND CP3SCREENER[Cond]1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on