Hi everyone,
I need your help to program this pattern,
I have tried several different codes and I find more or less results, but it is not great, A code to detect zones 1, 2 and 3
Z3 = MACD < S-Line
Z2 = S-Line > MACD
Z1 = MACD < S-Line
Z1, Z2 and Z3 < 0
and there is a sample of code and picture to explain
// _ _ _ _ _ _
// /_\| |_| |_ _ _(_) |__ _ _| |_ ___
// / _ \ _| _| '_| | '_ \ || | _(_-<
// /_/ \_\__|\__|_| |_|_.__/\_,_|\__/__/
MyMACD = MACDline[12,26,9](close)
MySLine = MACDSignal[12,26,9](close)
PointA = MyMACD Crosses Over MySLine AND MyMACD < 0 AND MySLine < 0
IF PointA Then
FOR X3 = 1 To 100 Do
IF MyMACD[X3] Crosses Under MySLine[X3] AND MyMACD[X3] < 0 AND MySLine[X3] < 0 Then
AbscisseX3 = X3
BarIndX3 = Barindex[X3]
CondP3 = 1
Break
ELSE
CondP3 = 0
ENDIF
Next
IF CondP3 Then
FOR X2 = X3+1 To 100 Do
IF MyMACD[X2] Crosses Over MySLine[X2] AND MyMACD[X2] < 0 AND MySLine[X2] < 0 Then
AbscisseX2 = X2
BarIndX2 = Barindex[X2]
CondP2 = 1
Break
ELSE
CondP2 = 0
ENDIF
Next
ENDIF
IF CondP2 Then // AND Not CondP3[1]
FOR X1 = X2+1 To 100 Do
IF MyMACD[X1] Crosses Under MySLine[X1] AND MyMACD[X1] < 0 AND MySLine[X1] < 0 Then
AbscisseX1 = X1
BarIndX1 = Barindex[X1]
CondP1 = 1
Break
ELSE
CondP1 = 0
ENDIF
Next
ENDIF
ELSE
CondP3 = 0
CondP2 = 0
CondP1 = 0
ENDIF
AllCondition = CondP3 AND CondP2 AND CondP1
// ########################################################################
// _ _ ___ _ _ _ _
// _| | |_ | \ ___| |__ _ _ __ _(_)_ _ __ _ _| | |_
// |_ . _| | |) / -_) '_ \ || / _| | ' \/ _ | |_ . _|
// |_ _| |___/\___|_.__/\_,_\__, |_|_||_\__, | |_ _|
// |_|_| |___/ |___/ |_|_|
Debuging = 0
If Debuging Then
DRAWTEXT("#CondP3#", barindex, pipsize)
DRAWTEXT("#CondP2#", barindex, - pipsize)
DRAWTEXT("#CondP1#", barindex,- 3 * pipsize)
DRAWTEXT("#AllCondition#", barindex, - 5 * pipsize)
ENDIF
IF AllCondition AND Not AllCondition[1] Then
BACKGROUNDCOLOR(0,255,0,42)
DrawRectangle(BarIndX1, 2*pipsize , BarIndX3, -2*pipsize)
DRAWTEXT("◄", barindex, pipsize)
DRAWTEXT("►", BarIndX1, pipsize)
ENDIF
RETURN
Best Reguards
JSParticipant
Senior
Hi @ZeroCafeine
Try this…
The pattern is red-green-red-green…
MyMACD = MACDline[12,26,9](close)
MySLine = MACDSignal[12,26,9](close)
For i=0 to 100
If MyMACD[i] Crosses Over MySLine[i] and MyMACD[i]<0 and MySLine[i]<0 then
PointA = BarIndex[i]
DrawVLine(PointA) Coloured(255,0,0)
Break
EndIf
If MyMACD[i] Crosses Under MySLine[i] and MyMACD[i]<0 and MySLine[i]<0 then
X3 = BarIndex[i]
DrawVLine(X3) Coloured(0,255,0)
Break
EndIf
Next
Return MyMACD as "MyMACD" coloured(0,0,255), MySLine as "MySLine" coloured(255,0,0)
JSParticipant
Senior
It’s not necessary to use a For-loop here…
MyMACD = MACDline[12,26,9](close)
MySLine = MACDSignal[12,26,9](close)
If MyMACD Crosses Over MySLine and MyMACD<0 and MySLine<0 then
PointA = BarIndex
DrawVLine(PointA) Coloured(255,0,0)
EndIf
If MyMACD Crosses Under MySLine and MyMACD<0 and MySLine<0 then
X3 = BarIndex
DrawVLine(X3) Coloured(0,255,0)
EndIf
Return MyMACD as "MyMACD" coloured(0,0,255), MySLine as "MySLine" coloured(255,0,0)