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 |

Using Indicator values as part of Condition code Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
Onereason
Posted : Tuesday, April 9, 2013 10:57:22 AM
Registered User
Joined: 10/7/2004
Posts: 56

Hi Bruce,

In an effort to reduce my computer load (it's bogging down big time) with all the conditions/indicators I have, I thought of using the indicator value in replacement of some of the codition real code I was using (same code basically)

I am finding that in my watchlist that the conditions no longer light up the watchlist, although the indicators appear correctly on the charts.

 

 
'# diff = chart.William2MinIndicator
 
If price.Last > (diff.value * .9935) - .08 Then
' If price.high > diff Then
 
pass
End If
 
is there anything I should do differently?
 
Thanks
 
Robert
Bruce_L
Posted : Tuesday, April 9, 2013 11:12:56 AM


Worden Trainer

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

I don't see anything obvious I would do different. If you want to share you Layout (and maybe add the full RealCode Condition for comparison), I could take a look.



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
Onereason
Posted : Tuesday, April 9, 2013 12:04:49 PM
Registered User
Joined: 10/7/2004
Posts: 56

Hi Bruce,

 

Thanks for your fast reply.

That is the whole condition code and the indictator puts a "dot" where it should be on the chart. The chart is the same for the indicator and the condition as well.

 

Respectfully,

 

Robert

Bruce_L
Posted : Tuesday, April 9, 2013 12:07:27 PM


Worden Trainer

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

Try adding the following line to your RealCode Condition:

'# Cumulative

My understanding from your original post was that this RealCode Condition was a replacement for an older RealCode Condition which contained the entire code of the RealCode Indicator in it as well. That older Condition is what I meant by the "full RealCode Condition for comparison".



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
Onereason
Posted : Tuesday, April 9, 2013 12:18:53 PM
Registered User
Joined: 10/7/2004
Posts: 56

Hi Bruce,

Ok, I added the line to the first line of code in the Condition. I didn't see a change.

 

Here is my indicator code

 

' William 2Min V1.04 updated 4-3-13
Dim OffsetPct As Single
Dim Offset As Single
Dim Barsearched As Single
Dim offset1 As Single
Dim trigger As Single
Dim B4EarlyWarn As Single
Dim Length As Single
Dim volumeLength As Single
Dim VolumeAvediff As Single
Dim VolumeNowAve As Single
Dim VolumeShortAve As Single
Dim VolumeLongAve As Single
Dim diff As Single
Dim totaldiff As Single
Dim diffneg As Single
Dim diffneg1 As Single
Dim diffpercent As Single
Dim diffpercentneg As Single
Dim diffpercentneg1 As Single
Dim VolumeMult As Single
Dim volumeadjust As Single
Dim volumeDiffadjust As Single
Dim varVolumeMin As Single
Dim diffbar1 As Single
Dim MaxHigh15_6 As Single
Dim MaxHigh20_6 As Single
Dim MaxHigh20_10 As Single
Dim MaxHigh20_15 As Single
Dim MaxHigh20_16 As Single
Dim MaxHigh20_17 As Single
Dim MaxHigh20_18 As Single
Dim MaxHigh20_20 As Single
Dim MaxHigh20_21 As Single
Dim MA300_200 As Single
Static Open As New List(Of Single)
Static Close As New List(Of Single)
OffsetPct = 1.0252
Offset = 23
Barsearched = 0
Offset1 = 12
Trigger = .32
B4EarlyWarn = 1
Length = 300
VolumeLength = 1500
VolumeAvediff = 0
volumeadjust = 0
diffbar1 = 0
volumeMult = .1
varVolumeMin = 5000
MaxHigh20_6 = price.maxhigh(20, offset - 6)
 
' adjust for MA500_200 higher than diff
MA300_200 = Price.AVGH(300, 200)
 
 
' If price.high > MaxHigh20_6 Then
 
MaxHigh15_6 = price.maxhigh(15, offset + 6)
 
MaxHigh20_10 = price.maxhigh(20, offset - 10)
MaxHigh20_15 = price.maxhigh(20, offset - 15)
MaxHigh20_16 = price.maxhigh(20, offset - 16)
MaxHigh20_17 = price.maxhigh(20, offset - 17)
MaxHigh20_18 = price.maxhigh(20, offset - 18)
MaxHigh20_20 = price.maxhigh(20, offset - 20)
MaxHigh20_21 = price.maxhigh(20, offset - 21)
 
VolumeNowAve = volume.AVG(3, 1)
VolumeShortAve = volume.AVG(20, 2)
VolumeLongAve = volume.AVG(100, 1)
 
Static OpeningOpen As Single
Static YesterdayClose As Single
Static YesterdayHigh As Single
 
If Price.DateValue.DayOfYear <> Price.DateValue(1).DayOfYear Then
OpeningOpen = Price.Open
YesterdayClose = Price.Close(1)
YesterdayHigh = Price.high(1)
End If
 
diffpercent = OpeningOpen * 1.01
diff = OpeningOpen + Trigger 
If diff < price.maxhigh(Length, offset) * OffsetPct Then
diff = price.maxhigh(Length, offset) * OffsetPct
End If   
If diff < price.maxhigh(Length, offset) + trigger Then
diff = price.maxhigh(Length, offset) + trigger 
End If  
 
 
If Single.IsNaN(OpeningOpen) Then
SetIndexInvalid
End If
   
If diff < diffpercent Then
diff = diffpercent
End If   
 
If diff < YesterdayClose * 1.01 Then
diff = YesterdayClose * 1.01
End If
 
 
 
If diff < MaxHigh20_6 Then
diff = MaxHigh20_6
End If
If diff < MaxHigh20_6 Then
diff = MaxHigh20_6
End If
 
If diff < price.AVGH(15, offset + 80) + .1
diff = price.AVGH(15, offset + 80) + .1
End If
If diff < price.AVGH(15, offset + 80) * 1.01 Then
diff = price.AVGH(15, offset + 80) * 1.01
End If
 
 
If diff < MaxHigh20_6 + .19 Then
diff = MaxHigh20_6 + .19
End If
If diff < MaxHigh20_6 * 1.0123 Then
diff = MaxHigh20_6 * 1.0123
End If
If diff < MaxHigh20_10 + .13 Then
diff = MaxHigh20_10 + .13
End If
If diff < MaxHigh20_10 * 1.0123 Then
diff = MaxHigh20_10 * 1.0123
End If
 
 
If diff < MaxHigh20_15 * 1.001 Then
diff = MaxHigh20_15 * 1.001
End If
 
If diff < MaxHigh20_16 + .08 Then
diff = MaxHigh20_16 + .08
End If
If diff < MaxHigh20_16 * 1.0058 Then
diff = MaxHigh20_16 * 1.0058
End If
                   
If diff < MaxHigh20_17 + .06 Then
diff = MaxHigh20_17 + .06
End If
If diff < MaxHigh20_17 * 1.005 Then
diff = MaxHigh20_17 * 1.005
End If
 
If diff < MaxHigh20_18 + .05 Then
diff = MaxHigh20_18 + .05
End If
If diff < MaxHigh20_18 * 1.0001 Then
diff = MaxHigh20_18 * 1.0001
End If
 
If diff < MaxHigh20_20 + .01 Then
diff = MaxHigh20_20 + .01
End If
If diff < MaxHigh20_20 * 1.0007 Then
diff = MaxHigh20_20 * 1.0007
End If
 
If diff < MaxHigh20_21 + .01 Then
diff = MaxHigh20_21 + .01
End If
 
If diff < MaxHigh20_21 * 1.0001 Then
diff = MaxHigh20_21 * 1.0001
End If
                                                               
If diff < price.High(5) * 1.001 Then
diff = price.High(5) * 1.001
End If
If diff < MaxHigh15_6 + .1 Then
If price.High(offset - 15) < MaxHigh15_6 + .1 Then
diff = MaxHigh15_6 + .1
End If
End If
If diff < MaxHigh15_6 * 1.0014 Then
If price.High(offset - 15) < MaxHigh15_6 * 1.0014 Then
diff = MaxHigh15_6 * 1.0012
End If
End If
 
' If diff < price.low * 1.0028 Then
' diff = price.low * 1.0028
' End If
 
' adjust for MA500_200 higher than diffEntry
If diff < MA300_200 Then
diff = diff + (.055 * (MA300_200 - diff))
End If
 
 
If VolumeLongAve < varVolumeMin Then
volumeadjust = (1 - VolumeLongAve / varVolumeMin) * volumeMult
diff = (diff * 1.0005) + .02 + (volumeadjust * 1.0)
End If
 
 
 
 
If VolumeNowAve > volume.AVG(50, 10) * 2.15 Then
volumeDiffadjust = VolumeNowAve / ((volume.AVG(50, 10)) * 2.15)
volumeDiffadjust = System.Math.Sqrt(volumeDiffadjust)
volumeDiffadjust = volumeDiffadjust * .001
diff = diff * (1 + volumeDiffadjust)
End If
 
If VolumeNowAve > VolumeLongAve * 6.15 Then
volumeDiffadjust = VolumeNowAve / (VolumeLongAve * 6.15)
volumeDiffadjust = volumeDiffadjust * .85
volumeDiffadjust = System.Math.Sqrt(volumeDiffadjust)
volumeDiffadjust = volumeDiffadjust * .001
diff = diff * (1 + volumeDiffadjust)
End If
 
If Me.CurrentDate.hour = 10 Then
If Me.currentdate.minute < 20 Then
diff = diff * 1.001
End If
 
If Me.CurrentDate.hour < 10 Then
If Me.CurrentDate.hour <= 9 Then
If Me.currentdate.minute < 51 Then
diff = (diff * 1.001) + .01
End If
End If 
diff = diff * 1.004 + .01
End If
 
If Me.CurrentDate.hour <= 10 Then
If Me.currentdate.minute < 10 Then
diff = diff * 1.001 + .01
End If
End If
 
 
End If
 
 
If Me.CurrentDate.hour >= 14 Then
If Me.currentdate.minute > 30 Then
diff = (diff * 1.002) 
End If
 
If Me.CurrentDate.hour > 15 Then
diff = (diff * 1.01)
If Me.currentdate.minute > 15 Then
diff = (diff * 1.001) + .01
End If
End If
End If
 
 
plot = diff
Onereason
Posted : Tuesday, April 9, 2013 12:20:13 PM
Registered User
Joined: 10/7/2004
Posts: 56

Instead of having the code in both an indicator and a condition on the same chart, I thought it may safe computer resources to only have the calculations done in the indicator, and use that for the condition??

Bruce_L
Posted : Tuesday, April 9, 2013 12:28:56 PM


Worden Trainer

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

Adding the '# Cumulative line to the RealCode Condition definitely cause the Condition Lights to appear for me.



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
Onereason
Posted : Tuesday, April 9, 2013 1:10:14 PM
Registered User
Joined: 10/7/2004
Posts: 56

Hi Bruce, Ok, I will reboot the system (sometimes that helps).

 

Where should the '#Cumulative line go (very begining or where?)

Bruce_L
Posted : Tuesday, April 9, 2013 1:17:43 PM


Worden Trainer

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

I always put it at the top of the code, but I don't think it actually matters.



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
Onereason
Posted : Tuesday, April 9, 2013 1:24:44 PM
Registered User
Joined: 10/7/2004
Posts: 56

Ok, thanks.

What if the stock is not on a chart? is the indicator updating? Because the problem I have is that a watchlist of about 50 stocks is not lighting up? so I am thinking maybe it's because the other 49 tickers don't have a chart up?

Does that make sense? In other words, my watchlist scans now depend on indicators that are not on an active chart with the symbol.

Bruce_L
Posted : Tuesday, April 9, 2013 1:30:03 PM


Worden Trainer

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

You don't need to have the chart up. I only get four true results currently in the Standard & Poors 100 Component Stocks WatchList. Are you sure there are symbols in your WatchList which are currently true?



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
Onereason
Posted : Wednesday, April 10, 2013 10:01:37 AM
Registered User
Joined: 10/7/2004
Posts: 56

Hi Bruce,

I wanted to say thanks for the great service and your always prompt help.

I mentioned StockFinder in an article i wrote today. http://www.thestreet.com/story/11891776/1/solars-short-squeeze-days-are-numbered.html

Thanks again

 

Robert

BobMc
Posted : Sunday, April 14, 2013 12:12:57 PM
Registered User
Joined: 10/7/2004
Posts: 816

Quote from Robert's article-

Stockfinder reports the odds of the next day moving higher is only 43%, compared to a 57% chance the next day will result in a lower closing price.

 

Really?!   How?

 

Regards

Bob Mc

 

jas0501
Posted : Monday, April 15, 2013 7:08:35 PM
Registered User
Joined: 12/31/2005
Posts: 2,499

In looking at your posted code I notices a couple things:

Three is a missing "then"

 

If diff < Price.AVGH(15, Offset + 80) + 0.1 Then
    diff = Price.AVGH(15, Offset + 80) + 0.1
End If
 
------------------------------
 
You have a nested if-then that is illogical. The hour < 10 can't be inside hour = 10
 

If Me.currentdate.Hour = 10 Then

    If Me.currentdate.Minute < 20 Then
        diff = diff * 1.001
    End If
 
    If Me.currentdate.Hour < 10 Then
        If Me.currentdate.Hour <= 9 Then
            If Me.currentdate.Minute < 51 Then
                diff = (diff * 1.001) + 0.01
            End If
        End If
        diff = diff * 1.004 + 0.01
    End If
 
    If Me.currentdate.Hour <= 10 Then
        If Me.currentdate.Minute < 10 Then
            diff = diff * 1.001 + 0.01
        End If
    End If

End If

=============================================
If performance is an issue you might try restructuring your evaluations. I think
 
If diff < price.AVGH(15, offset + 80) + .1  Then
    diff = price.AVGH(15, offset + 80) + .1
End If
If diff < price.AVGH(15, offset + 80) * 1.01 Then
    diff = price.AVGH(15, offset + 80) * 1.01
End If
 
might run faster written as 
 
val = price.AVGH(15, offset + 80)
valp1 = val + .1
valx101 = val * 1.01
if valp1 < valx101 then
    if diff < valp1 then
        diff = valp1
   endif
elseif diff < valx101 then
    diff = valx101
endif
 
It might not be any faster. I don't know how good the optimization is in the  compiled code. In the modified code there is only 1 multiply and 1 add and the assignment to diff will never be applied twice.

 

jas0501
Posted : Monday, April 15, 2013 7:32:20 PM
Registered User
Joined: 12/31/2005
Posts: 2,499

 

similarly
 
If diff < MaxHigh20_6 + 0.19 Then
    diff = MaxHigh20_6 + 0.19
End If
If diff < MaxHigh20_6 * 1.0123 Then
    diff = MaxHigh20_6 * 1.0123
End If
 
becomes
 
v1 = MaxHigh20_6 + 0.19
v2 = MaxHigh20_6 * 1.0123
if v1 < v2 then
    if diff < v1 then
        diff = v1
    endif
elseif diff < v2 then
   diff = v2
endif
 
and so on for each the similarly structured code piece
================
 
If you make the effort to restructure the code retain the original indicator and plot both.. This will help detect any coding errors.
 
I'm not sure it will be faster, but I expect it might be, mostly because the diff assignment never done twice. If the compiler/interpreter optimization is not good then the reduction in the multiply and the add will also improve performance. 
 
=============================
 
If you create the modifications I would be curious to know if it runs any faster.
 
 
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.