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

Help - refer past bars in an indicator - realCode Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
icookwithwine
Posted : Friday, September 4, 2015 5:56:43 PM
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
 
 
Gr8Trades
Posted : Friday, September 4, 2015 9:35:56 PM
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
 
icookwithwine
Posted : Saturday, September 5, 2015 12:41:50 PM
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

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.