DEFPARAM CumulateOrders = false
//
HA = 1 //1=usa HA, 0=usa candele giapponesi
//
once xOpen = open
xClose = (open + close + high + low) / 4
if barindex > 0 then
xOpen = (xOpen + xClose[1]) / 2
endif
xLow = min(low,min(xClose,xOpen))
xHigh = max(high,max(xClose,xOpen))
IF HA = 0 THEN
xClose = close
xOpen = open
xHigh = high
xLow = low
ENDIF
//
//ONCE p1 = 1
//Bull1 = average[5*p1,1](((3*xClose)-(2*lowest[p1](xLow))-xOpen[p1])/xClose*100)
//Bear1 = average[5*p1,1]((xOpen[p1]+(2*highest[p1](xHigh))-(3*xClose))/xClose*100)
//Repuls1 = Bull1 - Bear1
//
ONCE p2 = 5
Bull2 = average[5*p2,1](((3*xClose)-(2*lowest[p2](xLow))-xOpen[p2])/xClose*100)
Bear2 = average[5*p2,1]((xOpen[p2]+(2*highest[p2](xHigh))-(3*xClose))/xClose*100)
Repuls2 = Bull2 - Bear2
//
ONCE p3 = 15
Bull3 = average[5*p3,1](((3*xClose)-(2*lowest[p3](xLow))-xOpen[p3])/xClose*100)
Bear3 = average[5*p3,1]((xOpen[p3]+(2*highest[p3](xHigh))-(3*xClose))/xClose*100)
Repuls3 = Bull3 - Bear3
//
MyAdx = ADX[14]
Diverg = CALL MyRepulseDivergences[p2, HA]
//
// --- LONG
L1 = Repuls2 CROSSES OVER Repuls3
L2 = Diverg = 1
L3 = MyAdx > 25
IF (L1 OR L2) AND L3 AND Not Onmarket THEN
BUY 1 Contract AT Market
ENDIF
//
// --- SHORT
S1 = Repuls2 CROSSES UNDER Repuls3
S2 = Diverg = -1
S3 = L3
IF (S1 OR S2) AND S3 AND Not Onmarket THEN
SELLSHORT 1 Contract AT Market
ENDIF
//
SET TARGET pPROFIT 100
SET STOP pLOSS 50