Registered User Joined: 5/13/2015 Posts: 11
|
Hello,
I am very new to realCode - I am tring to write a binary indicator I usually use to define the trend.
The indicators should works like this:
If the low is higher then the 21 bars xaverage offsetted by 1 then the trend =1
if the high is lower then the 21 bars xaverage offsetted by 1 then the trend = -1
otherswise the trend is equal to the trend of the previous bar.
This is my attempt:
=========================================
Dim trend As Integer
If price.Low > price.XAVG(21, 1) Then
trend = 1
ElseIf price.high < price.XAVG(21, 1) Then
trend = -1
Else
trend = trend(1) '|*** <- Error here - I AM TRING To REFER THE VARIABLE VALUE ONE BAR AGO
End If
plot = trend
========================================
I looked and looked but I couldn't find a solution - any help appreciated
Thank you
|
Registered User Joined: 5/6/2014 Posts: 81
|
this should do itL
Static trend(2) As Integer
If isfirstbar Then
trend(0) = 0
trend(1) = 0
End If
If currentindex >= 22 Then
If price.Low > price.XAVG(21, 1) Then
trend(0) = 1
ElseIf price.high < price.XAVG(21, 1) Then
trend(0) = -1
Else
trend(0) = trend(1)
End If
plot = trend(0)
trend(1) = trend(0)
End If
|
Registered User Joined: 5/13/2015 Posts: 11
|
thank you so much Gr8Trades!
It works perfectly -
I could have never figure that out by myself -
thank you again
|