Download software Tutorial videos
Subscription & data-feed pricing Class schedule


New account application Trading resources
Margin rates Stock & option commissions

Attention: Discussion forums are read-only for extended maintenance until further notice.
Welcome Guest, please sign in to participate in a discussion. Search | Active Topics |

Storing a value in a variable for future bars to reference Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
sageofhalo
Posted : Tuesday, October 2, 2018 4:13:48 PM
Platinum Customer Platinum Customer

Joined: 2/24/2013
Posts: 16

Hello,

I have another issue I'm trying to fix and searching hasn't turned up a solution.  I am telling a variable to be defined as price.Close(X) where X is user defined.  But really what I want is for that variable to store the value of price.Close(X) for future bars to compare against until the variable is redefined as a new value.  Is there a way to do this?

Thresh and Hold are the variables that are not sticking to the value for the bar in which they are defined.  Clearly I'm doing it wrong and need the proper coding to do what I'm after.  As an aside the code might have some redundant elements like Exit Function and Plots as I've been troubleshooting but this is where it's at right now. Also Starting Trend as "Down" is sort of a workaround at the moment.

Thank you in advance,

Connor

Here is the code:

'# Smoothing = UserInput.Integer = 5
 
Dim Ind As Single
Dim Check As Boolean = False
Dim Thresh As Single
Dim Hold As Single
Dim Trend As String = "Down"
 
 
 
Select Case Trend
Case = "Up"
Select Case price.Close
Case > price.Close(1) And Check = False
Thresh = price.Close(Smoothing)
Ind = price.Close
Plot = Ind
Exit Function
Case > price.Close(1) And Check = True And price.Close <= Hold
Ind = Hold
Plot = Ind
Exit Function
Case > price.Close(1) And Check = True And price.Close > Hold
Check = False
Thresh = price.Close(Smoothing)
Ind = price.Close
Plot = Ind
Exit Function
Case <= price.Close(1) And Check = False And price.Close > price.Close(Smoothing)
Hold = price.Close(1)
Thresh = price.Close(Smoothing)
Check = True
Ind = price.Close(1)
Plot = Ind
Exit Function
Case <= price.Close(1) And Check = True And price.Close > Thresh
Ind = Hold
Plot = Ind
Exit Function
Case <= Thresh
Trend = "Down"
Check = False
Thresh = price.Close(Smoothing)
Ind = price.Close
Plot = Ind
Exit Function
End Select
Case = "Down"
Select Case price.Close
Case < price.Close(1) And Check = False
Thresh = price.Close(Smoothing)
Ind = price.Close
Plot = Ind
Exit Function
Case < price.Close(1) And Check = True And price.Close >= Hold
Ind = Hold
Plot = Ind
Exit Function
Case < price.Close(1) And Check = True And price.Close < Hold
Check = False
Thresh = price.Close(Smoothing)
Ind = price.Close
Plot = Ind
Exit Function
Case >= price.Close(1) And Check = False And price.Close < price.Close(Smoothing)
Hold = price.Close(1)
Thresh = price.Close(Smoothing)
Check = True
Ind = price.Close(1)
Plot = Ind
Exit Function
Case >= price.Close(1) And Check = True And price.Close < Thresh
Ind = Hold
Plot = Ind
Exit Function
Case >= Thresh
Trend = "Up"
Check = False
Thresh = price.Close(Smoothing)
Ind = price.Close
Plot = Ind
Exit Function
End Select
End Select

 

Bruce_L
Posted : Tuesday, October 2, 2018 4:26:04 PM


Worden Trainer

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

Use Static instead of Dim.



-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.