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 |

Simple Code Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
mholman
Posted : Thursday, May 27, 2010 4:51:49 PM
Registered User
Joined: 8/3/2006
Posts: 79
I'm trying to learn to write some simple code.  First for price to close above a XAvg and second to close below a XAvg.

First to close above 
'# PC = indicator.unlinked.PriceClose
'# MA = indicator.unlinked.MovingAvg(30)
'# Period = userinput.integer = 30
If price.Close > price.xavg(period) Then pass

Second to close below
'# PC = indicator.unlinked.PriceClose
'# MA = indicator.unlinked.MovingAvg(30)
'# Period = userinput.integer = 30
If price.Close < price.xavg(period) Then pass
The second one appears to work but the first one doesn't.  Any suggestions?
Kuf
Posted : Friday, May 28, 2010 9:58:19 AM


Administration

Joined: 9/18/2004
Posts: 3,522
You're doing it the hard way. You don't need the PC and MA variables, just use this code:

'# Period = userinput.integer = 30

If price.Close > price.xavg(period) Then pass

if price.close < price.xavg(period) then pass

Ken Gilb (Kuf)
Chief Software Engineer - Worden Brothers Inc.
Try/Catch - My RealCode Blog
mholman
Posted : Friday, May 28, 2010 10:28:01 AM
Registered User
Joined: 8/3/2006
Posts: 79

Thanks,  I was trying to experiment with draggign indicators into the code box.  But couldn't get them to work.  Could you explain why I keep getting " Operator '>' is not defined for type 'WBI.CommonBlocks.CommonBlocks.ScriptingLine' "  and also when I use "Then Pass" I get "pass" is not declared.?? 

I really appreciate the great job you all have done with SF5.
Mac

 

StockGuy
Posted : Friday, May 28, 2010 10:31:13 AM

Administration

Joined: 9/30/2004
Posts: 9,187
If you're getting "pass" not declared, you're trying to code a RealCode condition inside of the indicator editor. 
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.