Registered User Joined: 10/31/2010 Posts: 106 
	 | 
	
		Hi, I've read the information in the Ref guide and on this forum concerning audible alerts and I've got the system to sound off but not according to my condition rules. Here's what I want: 
 
1-When my RSI line crosses up passed it's (5 period) moving average - sound alert. 
2-When my RSI line crosses down passed it's (5 period) moving average - sound alert. (The RSI line is based on it's symbol price) 
 
When I wrote the code I simply dropped the original 2 conditions I made that monitors the RSI crossing the MAinto the RC box and then added the alert text you guys provided in the ref guide. Like this:  
 
(this example is just the cross down, the cross up is a separate condition/RC) 
 
'# RC = condition.unlinked.RSICrossdown  
If isLastBar Then  
LokiStatic.PlaySound("Z:\Documents\StockFinder5\Surfrider67\Alarms\mshot.wav") 
End If  
 
When I add it to a watch list it simply repeats the my alert .wav over and over. 
Thanks in advance!
	 | 
	 | 
	
	
	
		Registered User Joined: 10/31/2010 Posts: 106 
	 | 
	
		For some reason nobody has wrote me back on this question, I am still trying to solve it and cannot. My latest attempt: '# RSI = chart.RSI'# MA = chart.MovingAverage.5'# If RSI > MA Then     PassIf isLastBar Then	LokiStatic.PlaySound("Z:\Documents\StockFinder5\Surfrider67\Alarms\mshot.wav")End If End IfElseSetIndexInvalidEnd If What I'm really looking for is the ability to drop any condition into a real code script for making an audio alert.  I found one on this site but can't get it to work for me. If this isn't possible can someone point me in the right direction for the answer to my original post?
	 | 
	 | 
	
	
	
		Registered User Joined: 12/31/2005 Posts: 2,499 
	 | 
	
		QUOTE (Surfrider67) Hi, I've read the information in the Ref guide and on this forum concerning audible alerts and I've got the system to sound off but not according to my condition rules. Here's what I want: 
 
1-When my RSI line crosses up passed it's (5 period) moving average - sound alert. 
2-When my RSI line crosses down passed it's (5 period) moving average - sound alert. (The RSI line is based on it's symbol price) 
 
When I wrote the code I simply dropped the original 2 conditions I made that monitors the RSI crossing the MAinto the RC box and then added the alert text you guys provided in the ref guide. Like this:  
 
(this example is just the cross down, the cross up is a separate condition/RC) 
 
'# RC = condition.unlinked.RSICrossdown  
If isLastBar Then  
LokiStatic.PlaySound("Z:\Documents\StockFinder5\Surfrider67\Alarms\mshot.wav") 
End If  
 
When I add it to a watch list it simply repeats the my alert .wav over and over. 
Thanks in advance!   
 
Your code above as written will play the sound on the last bar of every watchlist item 
 
Try 
'# RC = condition.unlinked.RSICrossdown  
' 
' only alert on the last bar when RC.value is true 
' 
If isLastBar Then  
   if RC.value then 
          LokiStatic.PlaySound("Z:\Documents\StockFinder5\Surfrider67\Alarms\mshot.wav") 
   end if 
End If  
 
 
	 | 
	 | 
	
	
	
		Registered User Joined: 10/31/2010 Posts: 106 
	 | 
	
		That was it thanks Jas.  It plays however until the condition turns false-how would I write it to play only once?
	 | 
	 | 
	
	
	
		Registered User Joined: 12/31/2005 Posts: 2,499 
	 | 
	
		QUOTE (Surfrider67) That was it thanks Jas.  It plays however until the condition turns false-how would I write it to play only once?   
 
That is complicated.  
 
You would need to record when the alert was issed and then check to see if the current alert situation was still in the same timeframe, whether it was by bar, or hour, or day.  
 
Using a Static NameValueCollection to record the symbol name and asOfTime of the alert,  and then later checking to see if there was an alert issued for the current symbol and if it was not within the timeframe would provide a method of skipping the alert. 
 
See http://vb.net-informations.com/collections/vb.net_namevaluecollection.htm for some example code for using NameValueCollection. 
 
The idea is to collect the list of alerts and keep it around. Normally, but not in this case, there is code like 
If isFirstBar then 
    ' clear the static value of the previous symbol 
end if 
 
However you need to keep the collection from symbl to symbol, so that when StockFinder revists a symbol the collection of alerts can be checked to see if the alert needs to be issues and the new timeframe store in the collection for that symbol by replacing the old entry if present or adding a new one if not. 
 
So the isFirstBar clear in NOT needed, 
 
This collection stays around as long as the instance of the indicator exists. I'm not sure when StockFinder creates a new instance. If it is based on the chart, then changing watchlist would still use the same collection, which is good.. 
 
 
Hope this helps. 
 
	 | 
	 | 
	
	
	
		Registered User Joined: 12/31/2005 Posts: 2,499 
	 | 
	
		see also: 
 
http://msdn.microsoft.com/en-us/library/system.collections.specialized.namevaluecollection_members(v=vs.85).aspx 
 
	 | 
	 | 
	
	
	
		Registered User Joined: 10/31/2010 Posts: 106 
	 | 
	
		I'll give it a shot, thank you, again!  
	 | 
	 | 
	
	
	
		  Registered User Joined: 6/15/2008 Posts: 1,356 
	 | 
	
		 
	Jas, Bruce, or anyone else; 
	I was wondering if you have used NameValueCollection() in realcode ? 
	I've been doing some experimenting, and ran into some strange problems: 
	first off; you need to add   " Imports system.Collections.Specialized " as the very 1st line in your Class code, for realcode to acknowledge NameValueCollection().  
	like so: 
	http://screencast.com/t/6ImQZ35m 
	Entering this line anywhere else, will generate errors. 
	Next; 
	Once I have an "error free" code, the condition runs, but after I edit the code again, and make changes, it will execute the code, as if it was before I edited and made the changes. So, no matter what I change in the code, it'll run as when it was edited the first time! 
	very weird. 
	so question is; is NameValueCollection() supported in realcode? or am I wasting time, trying to implement it? 
	  
	  
	  
	  
	  
	 | 
	 | 
	
	
	
		  Registered User Joined: 6/15/2008 Posts: 1,356 
	 | 
	
		 
	Here's some test code I'm experimenting with: 
	a simple indicator that finds the high and low over the past 500bars, and then triggers if price retraces over 23.6%. 
	
		Imports system.Collections.Specialized 
	
		<WBIGuid("d4af43f1-eb1c-476f-8dee-5f986504edd6"),FriendlyName("RealCodeCondition"),BlockTemplateEmptyMethodOnly()> _ 
	
		Public partial Class RealCodeCondition 
	
		                inherits RealCodeCondition_base 
	
		                Sub New 
	
		                                autoloop = False 
	
		                End Sub 
	
		                Public Overrides Sub CallUserCode() 
	
		                                '# Retrace = userinput.single = 23.6 
	
		                                '# BarsAgo = UserInput.Integer = 0 
	
		                                '# Period = UserInput.Integer = 500 
	
		                                Dim Range(1) As Integer 
	
		                                Range(1) = Price.Bar.Count - 1 - BarsAgo 
	
		                                Range(0) = Range(1) - Period + 1 
	
		                                Dim BarA As Integer = Range(0) 
	
		                                If Range(0) >= 0 Then 
	
		                                                For i As Integer = Range(0) To Range(1) 
	
		                                                                If Price.Bar.HighValue(i) >= Price.Bar.HighValue(BarA) Then 
	
		                                                                                BarA = i 
	
		                                                                End If 
	
		                                                Next 
	
		                                End If 
	
		                                If BarA < Range(1) - 1 Then 
	
		                                                Dim BarB As Integer = BarA 
	
		                                                Dim BarBqualified As Integer = BarA 
	
		                                   
	
		                                                For i As Integer = BarA + 1 To Range(1) - 1 
	
		                                                                If Price.Bar.LowValue(i) < Price.Bar.LowValue(BarB) Then 
	
		                                                                                BarB = i 
	
		                                                                                For j As Integer = i To Range(1) - 1 
	
		                                                                                                If Price.Bar.lowValue(j) < Price.Bar.lowValue(j - 1) AndAlso _ 
	
		                                                                                                                Price.Bar.lowValue(j) < Price.Bar.lowValue(j + 1) Then 
	
		                                                                                                                BarBqualified = BarB 
	
		                                                                                                end if 
	
		                                                                                                Exit For 
	
		                                                                                Next 
	
		                                                                end if 
	
		                                                next 
	
		                                                If BarBqualified > BarA Then 
	
		                                                                Static alert_dbase As New NameValueCollection() 
	
		                                                                Dim alert_time As Date 
	
		                                                                Dim alert_minute As Integer 
	
		                                                                Dim level As Single = price.bar.lowvalue(BarBqualified) + Retrace / 100 * _ 
	
		                                                                                (price.bar.highvalue(BarA) - price.bar.lowvalue(BarBqualified)) 
	
		                                                                Dim brklevel As Integer = 0 
	
		                                                                Static sym As String 
	
		                                                                For i As Integer = BarBqualified To Range(1) 
	
		                                                                                If price.Bar.lastvalue(i) > level AndAlso price.Bar.lastvalue(i - 1) < level Then 
	
		                                                                                                brklevel = i 
	
		                                                                                End If 
	
		                                                                Next 
	
		                                                                For j As Integer = 0 To price.Bar.count - 1 
	
		                                                                                If j = brklevel Then 
	
		                                                                                                MyBase.addtoOutput(price.bar.datevalue(j), True) 
	
		                                                                                                If brklevel = price.Bar.count - 1 AndAlso sym <> CurrentSymbol Then 
	
		                                                                                                                sym = CurrentSymbol 
	
		                                                                                                                alert_time = datetime.now 
	
		                                                                                                                alert_minute = alert_time.Minute 
	
		                                                                                                                Dim symtrue As Boolean = False 
	
		                                                                                                                Dim i As Integer 
	
		                                                                                                                For i = 0 To alert_dbase.count - 1 
	
		                                                                                                                                If alert_dbase.Get(i) = sym Then 
	
		                                                                                                                                                symtrue = True 
	
		                                                                                                                                                showmessage("already in dbase" & " " & Me.currentsymbol) 
	
		                                                                                                                                                Exit For 
	
		                                                                                                                                End If 
	
		                                                                                                                Next 
	
		                                                                                                                If symtrue = False Then 
	
		                                                                                                                                alert_dbase.Add(sym, alert_minute) 
	
		                                                                                                                                showmessage("adding" & " " & Me.currentsymbol & " " & alert_dbase.Count) 
	
		                                                                                                                                                                                
	
		                                                                                                                End If 
	
		                                                                                                                                                                                                                                                                                                                                
	
		                                                                                                                lokistatic.playsound("c:\notify.wav") 
	
		                                                                                                                                                
	
		                                                                                                End If    
	
		                                                                
	
		                                                                                Else 
	
		                                                                                                MyBase.addtoOutput(price.bar.datevalue(j), False) 
	
		                                                                                End If 
	
		                                                                Next 
	
		                                End If 
	
		                                End If 
	
		                                
	
		                                
	
		  
	
		end sub 
	
		End Class 
 
	  
	My first test is to add the symbol and date stamp into the NameValueCollection, it should popup a mesage whether it is being added, if it's not yet in the Collection, or popup a message if it's already in the Collection. 
	  
	well, it's not working. 
	anyone any ideas? 
	 | 
	 | 
	
	
	
		  Registered User Joined: 6/15/2008 Posts: 1,356 
	 | 
	
		 
	ok, moving on: 
	upgraded .NET framework from 4.0 to 4.5, and still not working. 
	Instead of NameValueCollection()   trying ArrayList() 
	which works!!!  without having to add the "import" statement as first line; 
	  
	<WBIGuid("d4af43f1-eb1c-476f-8dee-5f986504edd6"),FriendlyName("RealCodeCondition"),BlockTemplateEmptyMethodOnly()> _ 
	Public partial Class RealCodeCondition 
	            inherits RealCodeCondition_base 
	            Sub New 
	                        autoloop = False 
	            End Sub 
	            Public Overrides Sub CallUserCode() 
	                        '# Retrace = userinput.single = 23.6 
	                        '# BarsAgo = UserInput.Integer = 0 
	                        '# Period = UserInput.Integer = 500 
	                        Dim Range(1) As Integer 
	                        Range(1) = Price.Bar.Count - 1 - BarsAgo 
	                        Range(0) = Range(1) - Period + 1 
	                        Dim BarA As Integer = Range(0) 
	                        If Range(0) >= 0 Then 
	                                    For i As Integer = Range(0) To Range(1) 
	                                                If Price.Bar.HighValue(i) >= Price.Bar.HighValue(BarA) Then 
	                                                            BarA = i 
	                                                End If 
	                                    Next 
	                        End If 
	                        If BarA < Range(1) - 1 Then 
	                                    Dim BarB As Integer = BarA 
	                                    Dim BarBqualified As Integer = BarA 
	                           
	                                    For i As Integer = BarA + 1 To Range(1) - 1 
	                                                If Price.Bar.LowValue(i) < Price.Bar.LowValue(BarB) Then 
	                                                            BarB = i 
	                                                            For j As Integer = i To Range(1) - 1 
	                                                                        If Price.Bar.lowValue(j) < Price.Bar.lowValue(j - 1) AndAlso _ 
	                                                                                    Price.Bar.lowValue(j) < Price.Bar.lowValue(j + 1) Then 
	                                                                                    BarBqualified = BarB 
	                                                                        end if 
	                                                                        Exit For 
	                                                            Next 
	                                                end if 
	                                    next 
	                                    If BarBqualified > BarA Then 
	                                                Static alert_dbase As New Arraylist() 
	                                                Dim alert_time As Date 
	                                                Dim alert_minute As Integer 
	                                                Dim level As Single = price.bar.lowvalue(BarBqualified) + Retrace / 100 * _ 
	                                                            (price.bar.highvalue(BarA) - price.bar.lowvalue(BarBqualified)) 
	                                                Dim brklevel As Integer = 0 
	                                                Static sym As String 
	                                                For i As Integer = BarBqualified To Range(1) 
	                                                            If price.Bar.lastvalue(i) > level AndAlso price.Bar.lastvalue(i - 1) < level Then 
	                                                                        brklevel = i 
	                                                            End If 
	                                                Next 
	                                                For j As Integer = 0 To price.Bar.count - 1 
	                                                            If j = brklevel Then 
	                                                                        MyBase.addtoOutput(price.bar.datevalue(j), True) 
	                                                                        If brklevel = price.Bar.count - 1 AndAlso sym <> CurrentSymbol Then 
	                                                                                    sym = CurrentSymbol 
	                                                                                    alert_time = datetime.now 
	                                                                                    alert_minute = alert_time.Minute 
	                                                                                    Dim symtrue As Boolean = False 
	                                                                                    
	                                                                                    If alert_dbase.Contains(sym) Then 
	                                                                                                            symtrue = True 
	                                                                                                showmessage("already in dbase" & " " & Me.currentsymbol & " " & alert_dbase.Count) 
	                                                                                                
	                                                                                                End If 
	                                                                        
	                                                                                    If symtrue = False Then 
	                                                                                                alert_dbase.Add(sym) 
	                                                                                                showmessage("adding" & " " & Me.currentsymbol & " " & alert_dbase.Count) 
	                                                                                                                                    
	                                                                                    End If 
	                                                                                                                                                                                                                                                
	                                                                                    lokistatic.playsound("c:\notify.wav") 
	                                                                                                            
	                                                                        End If 
	                                                
	                                                            Else 
	                                                                        MyBase.addtoOutput(price.bar.datevalue(j), False) 
	                                                            End If 
	                                                Next 
	                                    End If 
	                        End If 
	            
	            End Sub 
	End Class 
	  
	  
	problem now: I can't store both ticker and timestamp in the arraylist, and as far as I know, ArrayList() does not support multidimensional arrays. 
	Next problem is that once you change timeframe the ArrayList() keeps its values, so need to come up with a routine to clear the ArrayList when the timeframe is being changed. 
	  
	So Bruce, question : which types of lists, dictionaries, and Collection classes are supported in realcode? There are a whole bunch, listed on the http://msdn.microsoft.com/en-us/library/System.Collections.aspx  website. 
	  
	I'd rather not having to try them all out one by one. 
	  
	  
	  
	  
	 | 
	 | 
	
	
	
		 
   Worden Trainer
  Joined: 10/7/2004 Posts: 65,138 
	 | 
	
		 
	According to development, any .NET collection is supported. 
  -Bruce Personal Criteria Formulas TC2000 Support Articles
	 | 
	 | 
	
	
	
		 
   Administration
  Joined: 9/18/2004 Posts: 3,522 
	 | 
	
		 
	Glancing over your code, I think you want to use a Generic Dictionary.  
	FYI, you can always declare your variable like so, without having to use the imports statement: 
	  
	 Static alert_dbase As New system.Collections.Specialized.NameValueCollection() 
	  
	  
  Ken Gilb (Kuf) Chief Software Engineer - Worden Brothers Inc.  Try/Catch - My RealCode Blog
	 | 
	 | 
	
	
	
		  Registered User Joined: 6/15/2008 Posts: 1,356 
	 | 
	
		 
	Thanks Kuf/Bruce, appreciate it. 
	 | 
	 | 
	
	
	
		  Registered User Joined: 6/15/2008 Posts: 1,356 
	 | 
	
		 
	Ha,  fantastic!  works perfectly with generic dictionary. 
	  
	modified the "test" code, for who-ever is interested : 
	  
	<WBIGuid("d4af43f1-eb1c-476f-8dee-5f986504edd6"),FriendlyName("RealCodeCondition"),BlockTemplateEmptyMethodOnly()> _ 
	Public partial Class RealCodeCondition 
	            inherits RealCodeCondition_base 
	            Sub New 
	                        autoloop = False 
	            End Sub 
	            Public Overrides Sub CallUserCode() 
	                        '# Retrace = userinput.single = 23.6 
	                        '# BarsAgo = UserInput.Integer = 0 
	                        '# Period = UserInput.Integer = 500 
	                        Dim Range(1) As Integer 
	                        Range(1) = Price.Bar.Count - 1 - BarsAgo 
	                        Range(0) = Range(1) - Period + 1 
	                        Dim BarA As Integer = Range(0) 
	                        If Range(0) >= 0 Then 
	                                    For i As Integer = Range(0) To Range(1) 
	                                                If Price.Bar.HighValue(i) >= Price.Bar.HighValue(BarA) Then 
	                                                            BarA = i 
	                                                End If 
	                                    Next 
	                        End If 
	                        If BarA < Range(1) - 1 Then 
	                                    Dim BarB As Integer = BarA 
	                                    Dim BarBqualified As Integer = BarA 
	                           
	                                    For i As Integer = BarA + 1 To Range(1) - 1 
	                                                If Price.Bar.LowValue(i) < Price.Bar.LowValue(BarB) Then 
	                                                            BarB = i 
	                                                            For j As Integer = i To Range(1) - 1 
	                                                                        If Price.Bar.lowValue(j) < Price.Bar.lowValue(j - 1) AndAlso _ 
	                                                                                    Price.Bar.lowValue(j) < Price.Bar.lowValue(j + 1) Then 
	                                                                                    BarBqualified = BarB 
	                                                                        end if 
	                                                                        Exit For 
	                                                            Next 
	                                                end if 
	                                    Next 
	                                    If BarBqualified > BarA Then 
	                                                
	                                                            Static alert_dbase As New dictionary(Of String, Date) 
	                                                Dim alert_time As Date 
	                                                Dim alert_minute As Integer 
	                                                Dim level As Single = price.bar.lowvalue(BarBqualified) + Retrace / 100 * _ 
	                                                            (price.bar.highvalue(BarA) - price.bar.lowvalue(BarBqualified)) 
	                                                Dim brklevel As Integer = 0 
	                                                Static sym As String 
	                                                For i As Integer = BarBqualified To Range(1) 
	                                                            If price.Bar.lastvalue(i) > level AndAlso price.Bar.lastvalue(i - 1) < level Then 
	                                                                        brklevel = i 
	                                                            End If 
	                                                Next 
	                                                For j As Integer = 0 To price.Bar.count - 1 
	                                                            If j = brklevel Then 
	                                                                        MyBase.addtoOutput(price.bar.datevalue(j), True) 
	                                                                        If brklevel = price.Bar.count - 1 AndAlso sym <> CurrentSymbol Then 
	                                                                                    sym = CurrentSymbol 
	                                                                                    alert_time = datetime.now 
	                                                                                    alert_minute = alert_time.Minute 
	                                                                                    Dim symtrue As Boolean = False 
	                                                                                    
	                                                                                    If alert_dbase.ContainsKey(sym) Then 
	                                                                                                symtrue = True 
	                                                                                                Dim keydate As Date = alert_dbase.Item(sym) 
	                                                                                                showmessage("already in dbase" & " " & sym & " date of entry: " & keydate & " total entries in dbase: " & alert_dbase.Count) 
	                                                                                                
	                                                                                    End If 
	                                                                        
	                                                                                    If symtrue = False Then 
	                                                                                                alert_dbase.Add(sym, datetime.now) 
	                                                                                                showmessage("adding" & " " & Me.currentsymbol & " " & alert_dbase.Count) 
	                                                                                                                                    
	                                                                                    End If 
	                                                                                                                                                                                                                                                
	                                                                                    lokistatic.playsound("c:\notify.wav") 
	                                                                                                            
	                                                                        End If 
	                                                
	                                                            Else 
	                                                                        MyBase.addtoOutput(price.bar.datevalue(j), False) 
	                                                            End If 
	                                                Next 
	                                    End If 
	                        End If 
	            
	            End Sub 
	End Class 
	  
	a good link for description and examples: 
	http://www.dotnetperls.com/dictionary-vbnet 
	I used the dictionary with "string" as the key, which will hold the tickersymbol, and "date" for the time stamp. 
	the above test code, detects if the symbol is in the dictionary already, if not, then it will add the symbol with the date at the time the condition passed. 
	  
	next step is to manipulate the entries in the dictionary based on current bar and timestamp 
	 | 
	 | 
	
	
	
		  Registered User Joined: 6/15/2008 Posts: 1,356 
	 | 
	
		 
	got something working 
	
		Public partial Class RealCodeCondition 
	
		  inherits RealCodeCondition_base 
	
		  Sub New 
	
		    autoloop = False 
	
		  End Sub 
	
		  Public Overrides Sub CallUserCode() 
	
		    '# Retrace = userinput.single = 23.6 
	
		    '# BarsAgo = UserInput.Integer = 0 
	
		    '# Period = UserInput.Integer = 500 
	
		  
	
		    Dim Range(1) As Integer 
	
		    Range(1) = Price.Bar.Count - 1 - BarsAgo 
	
		    Range(0) = Range(1) - Period + 1 
	
		    Dim BarA As Integer = Range(0) 
	
		    Static alert_dbase As New dictionary(Of String, Date) 
	
		    Static CurrentTimeFrame As String 
	
		    Dim CheckTimeFrame As String 
	
		    Dim LastBar As Integer 
	
		    Static LastBarDate As Date 
	
		    LastBar = price.Bar.count - 1 
	
		    If Price.Bar.Datevalue(LastBar) <> LastBarDate Then 
	
		      LastBarDate = Price.Bar.Datevalue(LastBar) 
	
		      alert_dbase.clear 
	
		      ' showmessage("new bar, clear Dbase ; " & alert_dbase.count) 
	
		    End If 
	
		    CheckTimeFrame = WhatTimeFrame() 
	
		    If CheckTimeFrame <> CurrentTimeFrame Or Price.Bar.Datevalue(LastBar) <> LastBarDate Then 
	
		      alert_dbase.clear 
	
		      CurrentTimeFrame = CheckTimeFrame 
	
		      ' showmessage("new TimeFrame, clear Dbase ; " & alert_dbase.count) 
	
		    End If 
	
		    If Range(0) >= 0 Then 
	
		      For i As Integer = Range(0) To Range(1) 
	
		      If Price.Bar.HighValue(i) >= Price.Bar.HighValue(BarA) Then 
	
		        BarA = i 
	
		      End If 
	
		      Next 
	
		    End If 
	
		    If BarA < Range(1) - 1 Then 
	
		      Dim BarB As Integer = BarA 
	
		      Dim BarBqualified As Integer = BarA 
	
		   
	
		      For i As Integer = BarA + 1 To Range(1) - 1 
	
		        If Price.Bar.LowValue(i) < Price.Bar.LowValue(BarB) Then 
	
		          BarB = i 
	
		          For j As Integer = i To Range(1) - 1 
	
		            If Price.Bar.lowValue(j) < Price.Bar.lowValue(j - 1) AndAlso _ 
	
		              Price.Bar.lowValue(j) < Price.Bar.lowValue(j + 1) Then 
	
		              BarBqualified = BarB 
	
		            end if 
	
		          Exit For 
	
		          Next 
	
		        end if 
	
		      next 
	
		      If BarBqualified > BarA Then 
	
		  
	
		        Dim alert_time As Date 
	
		        Dim alert_minute As Integer 
	
		        Dim level As Single = price.bar.lowvalue(BarBqualified) + Retrace / 100 * _ 
	
		(price.bar.highvalue(BarA) - price.bar.lowvalue(BarBqualified)) 
	
		        Dim brklevel As Integer = 0 
	
		        Static sym As String 
	
		        For i As Integer = BarBqualified To Range(1) 
	
		          If price.Bar.lastvalue(i) > level AndAlso price.Bar.lastvalue(i - 1) < level Then 
	
		            brklevel = i 
	
		          End If 
	
		        Next 
	
		        For j As Integer = 0 To price.Bar.count - 1 
	
		          If j = brklevel Then 
	
		            MyBase.addtoOutput(price.bar.datevalue(j), True) 
	
		            If brklevel = price.Bar.count - 1 AndAlso sym <> CurrentSymbol Then 
	
		              sym = CurrentSymbol 
	
		              alert_time = datetime.now 
	
		              alert_minute = alert_time.Minute 
	
		              Dim symtrue As Boolean = False 
	
		              If alert_dbase.ContainsKey(sym) Then 
	
		                symtrue = True 
	
		                'Dim keydate As Date = alert_dbase.Item(sym) 
	
		                'showmessage("already in dbase" & " " & sym & " date of entry: " & keydate & " total entries in dbase: " & alert_dbase.Count) 
	
		              End If 
	
		  
	
		              If symtrue = False Then 
	
		                lokistatic.playsound("c:\notify.wav") 
	
		                alert_dbase.Add(sym, datetime.now) 
	
		                showmessage("adding" & " " & Me.currentsymbol & " " & alert_dbase.Count & " at: " & datetime.now) 
	
		                Me.log.info("entryCondition UP, on " & WhatTimeFrame() & " " & Me.currentsymbol & " at: " & datetime.now) 
	
		              End If 
	
		            End If  
	
		  
	
		          Else 
	
		            MyBase.addtoOutput(price.bar.datevalue(j), False) 
	
		          End If 
	
		        Next 
	
		    End If 
	
		End If 
	
		  
	
		end sub 
	
		  Private Function WhatTimeFrame() As String 
	
		  Dim tframe As String 
	
		  If Me.BarInterval.Days > 0 Then 
	
		    tframe = Me.BarInterval.Days & " Days " 
	
		  Else 
	
		    tframe = Me.BarInterval.TotalMinutes & " Minutes" 
	
		  End If 
	
		    Return tframe 
	
		  End Function 
	
		End Class 
	
		  
 
	The yellow highlighted code initialises the "database" , with one string column, and one date column. 
	It checks whether the timeframe has changed, if so, it clears the database, and it clears the database on a new bar. 
	so for example; if the condition runs on a 60min chart, it will clear the database at every hour, when the current bar closes. 
	The red highlighted code checks if the symbol is already in the database in case a symbol breaks the "brklevel" every subsequent time during the same bar, if so, it won't add that symbol, and it won't popup a message. 
	You can enable the showmessage, to confirm proper operation of the code. 
	 I only posted this code for finding a way to get the alert to trigger only once for a symbol during one bar. It would be to lenghty to post it with the indicator I actually use. 
	I have tested it a bit today, and it seems to work properly. 
	Any improvements/suggestions are welcome. 
	thanks. 
	P. 
	 | 
	 | 
	
	
	
		  Registered User Joined: 6/15/2008 Posts: 1,356 
	 | 
	
		 
	for some reason the "highlighting" didn't work. 
	the yellow highlight is supposed to be from " 
	Static alert_dbase As New dictionary(Of String, Date) 
	to: 
	   ' showmessage("new TimeFrame, clear Dbase ; " & alert_dbase.count) 
	  
	    End If 
	  
	and the "red" highlight: 
	  
	
		 If alert_dbase.ContainsKey(sym) Then 
	
		                symtrue = True 
	
		                'Dim keydate As Date = alert_dbase.Item(sym) 
	
		                'showmessage("already in dbase" & " " & sym & " date of entry: " & keydate & " total entries in dbase: " & alert_dbase.Count) 
	
		              End If 
	
		  
	
		              If symtrue = False Then 
	
		                lokistatic.playsound("c:\notify.wav") 
	
		                alert_dbase.Add(sym, datetime.now) 
	
		                showmessage("adding" & " " & Me.currentsymbol & " " & alert_dbase.Count & " at: " & datetime.now) 
	
		                Me.log.info("entryCondition UP, on " & WhatTimeFrame() & " " & Me.currentsymbol & " at: " & datetime.now) 
	
		              End If 
 
	  
	 | 
	 | 
	
	
	
		  Registered User Joined: 6/15/2008 Posts: 1,356 
	 | 
	
		 
	 If CheckTimeFrame <> CurrentTimeFrame Or Price.Bar.Datevalue(LastBar) <> LastBarDate Then 
	should be: 
	 If CheckTimeFrame <> CurrentTimeFrame Then 
	 | 
	 | 
	
	
	
		  Registered User Joined: 6/15/2008 Posts: 1,356 
	 | 
	
		 
	Bruce; 
	As you can see from the code, I'd like to write certain events to a file. 
	Unfortunately, as I understand, we only have the option to write to the log file. 
	Apparently something in my code creates an error, even though the condition works fine. 
	Log file filling up with the following continuous error: 
	http://screencast.com/t/RN30TbjQ 
	Sincerely hope Worden one day picks up SF development again. 
	  
	  
	 | 
	 | 
	
	
	
		 
   Worden Trainer
  Joined: 10/7/2004 Posts: 65,138 
	 | 
	
		 
	It is also my understanding that the only way you can write to disk directly from RealCode is to write to the log file. 
	You can get the values of a RealCode Indicator to disk by manually doing an export, but that is not the same thing as having the RealCode itself write to disk. That said, it might be possible to encode information into the values and dates of data in an indicator and then use a manual export to get the desired information into an external file. 
	I have looked at and played with your RealCode and do not know why it is generating the error in the log file. 
  -Bruce Personal Criteria Formulas TC2000 Support Articles
	 | 
	 | 
	
	
	
		  Registered User Joined: 6/15/2008 Posts: 1,356 
	 | 
	
		 
	Yea "manual" isn't going to work for me. I use short timeframes mostly. 
	  
	I gave it a quick try however, just to see what would happen" 
	  
	enter: 
	Imports System.IO 
	as first line 
	then: 
	Using outfile As New StreamWriter("c:\testFile.txt") 
	outfile.Write("test") 
	End Using  
	  
	at the point where the symbol gets added to the alert_dbase. 
	  
	although it compiles with no errors, it's not writing the file. 
	  
	  
	  
	 | 
	 | 
	
	
	
		  Registered User Joined: 6/15/2008 Posts: 1,356 
	 | 
	
		 
	removed the "imports System.IO" 
	and wrote it as Kuf suggested in earlier post: 
	  
	and.... it's working!!  well sort of. 
	it worked only once: 
	  
	Now when I edit the realcode I do get an error: 
	  
	  
	aaaah. so close! 
	  
	Kuf/Bruce; 
	Come on guys... allow IO ,  or do you know a way to make this work? 
	  
	 | 
	 | 
	
	
	
		  Registered User Joined: 6/15/2008 Posts: 1,356 
	 | 
	
		 
	A little more progress: 
	the : 
	Using outfile As system.io.StreamWriter("c:\test\testFile.txt") 
	       outfile.Write("test") 
	End Using 
	from the previous example works, but it overwrites the same line in the text file, everytime the condition triggers. 
	  
	No matter what I do, realcode accepts the code the first time you edit it into the condition, editing it afterwards will generate the "IO operations are not allowed" error. 
	here's the next example. It ADDS lines to a text file, everytime the condition triggers: 
	make sure you have a C:\test\ folder for the testFile.txt file. 
	  
	  
	  
	 | 
	 | 
	
	
	
		  Registered User Joined: 6/15/2008 Posts: 1,356 
	 | 
	
		 
	the experimenting has lead to a final code I'm using now. 
	  
	Even though we are now able to minimize the amount of popup alerts with the "showmessage" command to just one alert per bar, I personally don't like the fact that you have to click the "ok" button on the popup message. The code pauses, and thus, the current scan stops, until you click the ok button. 
	On longer timeframes it's not an issue in my opinion, but on short timeframes it gets annoying. specially since sometimes the popup message is minimized to the task bar on your windows screen. so you could easily oversee a popup message, and subsequently miss alerts on other stocks in your watchlist. 
	therefore on short timeframes I use audible alerts only. And I found a way, by using text2speech to hear which ticker triggered. 
	I used this program TexttoWav  http://download.cnet.com/TextToWav/3000-2169_4-10773719.html 
	to create a small soundfile for each ticker in my watchlist, and copied them in a folder I created c:\StockfinderV5data\wavs 
	for example for Amazon, I typed "amazon, up"  in the texttowav program and saved it as amzn-up.wav  
	Now everytime my condition passes for amazon, it'll say "amazon up" . and eneters a log entry in a file c:\StockfinderV5data\logs\entry-up.txt    (make sure you create the folders). 
	here is the final code. If you do want the popup message, just enable the showmessage line in the code by removing the ' 
	any comments/suggestions/improvements welcome. 
	  
	the output of the text file : 
	  
	 | 
	 | 
	
	
	
		Registered User Joined: 4/13/2014 Posts: 11 
	 | 
	
		 
	I am pretty bad with coding pthegreat so I apologize ahead of time. 
	How could I use your above coding to add my basic coding example? 
	I am running only daily carts and would want theAlert to trigger only once a day and have that info added to the stockFinderApp.log 
	  
	If isLastBar Then 
	  If (Price.close(0) - Price.Close(1)) / Price.Close(1) > .02 Then 
	    'showmessage("test") 
	    LokiStatic.PlaySound("c:\windows\media\notify.wav") 
	    Me.log.info("Alert passed on " & Me.currentsymbol & " with a price of" & price.close) 
	    pass 
	  End If 
	End If 
	 | 
	 | 
	
	
	
		Registered User Joined: 5/6/2014 Posts: 81 
	 | 
	
		 
  QUOTE (cortner) 
 I am pretty bad with coding pthegreat so I apologize ahead of time. 
 How could I use your above coding to add my basic coding example? 
    
 1st : don't have to apologize :-)   I learned to program from scratch myself (and still learning). Learned a lot from worden's forum. At first it seems overwhelming, and at times impossible. But trust me, if you put in some effort and time; read books etc. you'll start to understand and get bettter and better at it. 
 2nd: I don't use SF actively anymore, although I do like the platform very much. 
 having said that, I don't mind trying to code this for you as an example. However i don't have a lot of time. I might be able to have a look at it this coming weekend, unless Bruce or someone else takes a crack at it before then. 
 Thanks and have a gr8 day 
	 | 
	 | 
	
	
	
		Registered User Joined: 4/13/2014 Posts: 11 
	 | 
	
		 
	Any help would be much appreciated !  
	Thanks 
	  
	 | 
	 | 
	
	
	
		Registered User Joined: 5/6/2014 Posts: 81 
	 | 
	
		 
	Cortner, In my spare time I'm working on setting up a website. on which I'm planning to post some SF indicators/conditions and such. 
	The alert system is a valuable part in creating a trading system, imo. As soon as I can I'll post it on the website, with an example to use it as an alert to any condition. 
	I'm working on it, but hope to get it all working by the weekend. 
	http://www.gr8wklytrades.com 
	 | 
	 | 
| 
Guest-1 |