Welcome Guest, please sign in to participate in a discussion. Search | Active Topics |

Cumulative RealCode Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
maljester
Posted : Friday, May 20, 2016 1:47:41 PM
Platinum Customer Platinum Customer

Joined: 1/30/2005
Posts: 135

I translated the following PCF to RealCode,  I hope there is more compact RealCode version.

PCF -

SGN( 
9 * ((C0 < AVGC10.0 AND AVGC20.0 < AVG(AVGC20.0,3)) - (C0 > AVGC10.0 AND AVGC20.0 > AVG(AVGC20.0,3))) + 
8 * ((C1 < AVGC10.1 AND AVGC20.1 < AVG(AVGC20.1,3)) - (C1 > AVGC10.1 AND AVGC20.1 > AVG(AVGC20.1,3))) + 
7 * ((C2 < AVGC10.2 AND AVGC20.2 < AVG(AVGC20.2,3)) - (C2 > AVGC10.2 AND AVGC20.2 > AVG(AVGC20.2,3))) + 
6 * ((C3 < AVGC10.3 AND AVGC20.3 < AVG(AVGC20.3,3)) - (C3 > AVGC10.3 AND AVGC20.3 > AVG(AVGC20.3,3))) + 
5 * ((C4 < AVGC10.4 AND AVGC20.4 < AVG(AVGC20.4,3)) - (C4 > AVGC10.4 AND AVGC20.4 > AVG(AVGC20.4,3))) + 
4 * ((C5 < AVGC10.5 AND AVGC20.5 < AVG(AVGC20.5,3)) - (C5 > AVGC10.5 AND AVGC20.5 > AVG(AVGC20.5,3))) + 
3 * ((C6 < AVGC10.6 AND AVGC20.6 < AVG(AVGC20.6,3)) - (C6 > AVGC10.6 AND AVGC20.6 > AVG(AVGC20.6,3))) + 
2 * ((C7 < AVGC10.7 AND AVGC20.7 < AVG(AVGC20.7,3)) - (C7 > AVGC10.7 AND AVGC20.7 > AVG(AVGC20.7,3))) + 
1 * ((C8 < AVGC10.8 AND AVGC20.8 < AVG(AVGC20.8,3)) - (C8 > AVGC10.8 AND AVGC20.8 > AVG(AVGC20.8,3)))) = 1
 
RealCode -
 
Dim cum1 As Single
Dim cum2 As Single
Dim cum3 As Single
cum1 = 0
cum2 = 0
If price.close < price.AVGC(10) And PRICE.AVGC(20, 0) < (price.AVGC(20) + price.AVGC(20, 1) + price.AVGC(20, 2)) / 3 Then 
cum1 = -1
Else
cum1 = 0
End If
If price.close > price.AVGC(10) And PRICE.AVGC(20, 0) > (price.AVGC(20) + price.AVGC(20, 1) + price.AVGC(20, 2)) / 3  Then 
cum2 = -1
Else
cum2 = 0
End If
cum3 = 9 * (cum1 - cum2)
 
If price.close(1) < price.AVGC(10, 1) And PRICE.AVGC(20, 1) < (price.AVGC(20, 1) + price.AVGC(20, 2) + price.AVGC(20, 3)) / 3  Then 
cum1 = -1
Else
cum1 = 0
End If
If price.close(1) > price.AVGC(10, 1) And PRICE.AVGC(20, 1) > (price.AVGC(20, 1) + price.AVGC(20, 2) + price.AVGC(20, 3)) / 3  Then 
cum2 = -1
Else
cum2 = 0
End If
cum3 = cum3 + (8 * (cum1 - cum2))
 
If price.close(2) < price.AVGC(10, 2) And PRICE.AVGC(20, 2) < (price.AVGC(20, 2) + price.AVGC(20, 3) + price.AVGC(20, 4)) / 3  Then 
cum1 = -1
Else
cum1 = 0
End If
If price.close(2) > price.AVGC(10, 2) And PRICE.AVGC(20, 1) > (price.AVGC(20, 2) + price.AVGC(20, 3) + price.AVGC(20, 4)) / 3  Then 
cum2 = -1
Else
cum2 = 0
End If
cum3 = cum3 + (7 * (cum1 - cum2))
 
If price.close(3) < price.AVGC(10, 3) And PRICE.AVGC(20, 3) < (price.AVGC(20, 3) + price.AVGC(20, 4) + price.AVGC(20, 5)) / 3  Then 
cum1 = -1
Else
cum1 = 0
End If
If price.close(3) > price.AVGC(10, 3) And PRICE.AVGC(20, 3) > (price.AVGC(20, 3) + price.AVGC(20, 4) + price.AVGC(20, 5)) / 3  Then 
cum2 = -1
Else
cum2 = 0
End If
cum3 = cum3 + (6 * (cum1 - cum2))
 
If price.close(4) < price.AVGC(10, 4) And PRICE.AVGC(20, 4) < (price.AVGC(20, 4) + price.AVGC(20, 5) + price.AVGC(20, 6)) / 3  Then 
cum1 = -1
Else
cum1 = 0
End If
If price.close(4) > price.AVGC(10, 4) And PRICE.AVGC(20, 4) > (price.AVGC(20, 4) + price.AVGC(20, 5) + price.AVGC(20, 6)) / 3  Then 
cum2 = -1
Else
cum2 = 0
End If
cum3 = cum3 + (5 * (cum1 - cum2))
 
If price.close(5) < price.AVGC(10, 5) And PRICE.AVGC(20, 5) < (price.AVGC(20, 5) + price.AVGC(20, 6) + price.AVGC(20, 7)) / 3  Then 
cum1 = -1
Else
cum1 = 0
End If
If price.close(5) > price.AVGC(10, 5) And PRICE.AVGC(20, 5) > (price.AVGC(20, 5) + price.AVGC(20, 6) + price.AVGC(20, 7)) / 3  Then 
cum2 = -1
Else
cum2 = 0
End If
cum3 = cum3 + (4 * (cum1 - cum2))
 
If price.close(6) < price.AVGC(10, 6) And PRICE.AVGC(20, 6) < (price.AVGC(20, 6) + price.AVGC(20, 7) + price.AVGC(20, 8)) / 3  Then 
cum1 = -1
Else
cum1 = 0
End If
If price.close(6) > price.AVGC(10, 6) And PRICE.AVGC(20, 6) > (price.AVGC(20, 6) + price.AVGC(20, 7) + price.AVGC(20, 8)) / 3  Then 
cum2 = -1
Else
cum2 = 0
End If
cum3 = cum3 + (3 * (cum1 - cum2))
 
If price.close(7) < price.AVGC(10, 7) And PRICE.AVGC(20, 7) < (price.AVGC(20, 7) + price.AVGC(20, 8) + price.AVGC(20, 9)) / 3  Then 
cum1 = -1
Else
cum1 = 0
End If
If price.close(7) > price.AVGC(10, 7) And PRICE.AVGC(20, 7) > (price.AVGC(20, 7) + price.AVGC(20, 8) + price.AVGC(20, 9)) / 3  Then 
cum2 = -1
Else
cum2 = 0
End If
cum3 = cum3 + (2 * (cum1 - cum2))
 
If price.close(8) < price.AVGC(10, 8) And PRICE.AVGC(20, 8) < (price.AVGC(20, 8) + price.AVGC(20, 9) + price.AVGC(20, 10)) / 3  Then 
cum1 = -1
Else
cum1 = 0
End If
If price.close(8) > price.AVGC(10, 8) And PRICE.AVGC(20, 8) > (price.AVGC(20, 8) + price.AVGC(20, 9) + price.AVGC(20, 10)) / 3  Then 
cum2 = -1
Else
cum2 = 0
End If
cum3 = cum3 + (1 * (cum1 - cum2))
If system.Math.Sign(cum3) = 1 Then
plot = 1
Else
plot = 0
End If

 

Bruce_L
Posted : Friday, May 20, 2016 3:08:41 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

You could do a literal translation of the Personal Criteria Formula into RealCode as follows.

If Math.Sign( _ 
	9 * ((Price.Last(0) < Price.AVG(10, 0) AndAlso Price.AVG(20, 0) < Price.MovingAverage(3).AVG(20, 0)) - (Price.Last(0) > Price.AVG(10, 0) AndAlso Price.AVG(20, 0) > Price.MovingAverage(3).AVG(20, 0))) + _
	8 * ((Price.Last(1) < Price.AVG(10, 1) AndAlso Price.AVG(20, 1) < Price.MovingAverage(3).AVG(20, 1)) - (Price.Last(1) > Price.AVG(10, 1) AndAlso Price.AVG(20, 1) > Price.MovingAverage(3).AVG(20, 1))) + _
	7 * ((Price.Last(2) < Price.AVG(10, 2) AndAlso Price.AVG(20, 2) < Price.MovingAverage(3).AVG(20, 2)) - (Price.Last(2) > Price.AVG(10, 2) AndAlso Price.AVG(20, 2) > Price.MovingAverage(3).AVG(20, 2))) + _
	6 * ((Price.Last(3) < Price.AVG(10, 3) AndAlso Price.AVG(20, 3) < Price.MovingAverage(3).AVG(20, 3)) - (Price.Last(3) > Price.AVG(10, 3) AndAlso Price.AVG(20, 3) > Price.MovingAverage(3).AVG(20, 3))) + _
	5 * ((Price.Last(4) < Price.AVG(10, 4) AndAlso Price.AVG(20, 4) < Price.MovingAverage(3).AVG(20, 4)) - (Price.Last(4) > Price.AVG(10, 4) AndAlso Price.AVG(20, 4) > Price.MovingAverage(3).AVG(20, 4))) + _
	4 * ((Price.Last(5) < Price.AVG(10, 5) AndAlso Price.AVG(20, 5) < Price.MovingAverage(3).AVG(20, 5)) - (Price.Last(5) > Price.AVG(10, 5) AndAlso Price.AVG(20, 5) > Price.MovingAverage(3).AVG(20, 5))) + _
	3 * ((Price.Last(6) < Price.AVG(10, 6) AndAlso Price.AVG(20, 6) < Price.MovingAverage(3).AVG(20, 6)) - (Price.Last(6) > Price.AVG(10, 6) AndAlso Price.AVG(20, 6) > Price.MovingAverage(3).AVG(20, 6))) + _
	2 * ((Price.Last(7) < Price.AVG(10, 7) AndAlso Price.AVG(20, 7) < Price.MovingAverage(3).AVG(20, 7)) - (Price.Last(7) > Price.AVG(10, 7) AndAlso Price.AVG(20, 7) > Price.MovingAverage(3).AVG(20, 7))) + _
	1 * ((Price.Last(8) < Price.AVG(10, 8) AndAlso Price.AVG(20, 8) < Price.MovingAverage(3).AVG(20, 8)) - (Price.Last(8) > Price.AVG(10, 8) AndAlso Price.AVG(20, 8) > Price.MovingAverage(3).AVG(20, 8)))) = 1 Then
	Plot = 1
End If


-Bruce
Personal Criteria Formulas
TC2000 Support Articles
maljester
Posted : Friday, May 20, 2016 8:08:51 PM
Platinum Customer Platinum Customer

Joined: 1/30/2005
Posts: 135

Thanks.  works great,  I could not get the syntax for converting AVG(AVGC20.0,3) when I tried.

Bruce_L
Posted : Saturday, May 21, 2016 10:51:48 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

You're welcome.



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
Users browsing this topic
Guest-1

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.