Buy and sell script for MomentumPct ?
Author: DIY
Creation Date: 9/10/2011 10:26 PM
profile picture

DIY

#1
I notice that some Indicators in WealthLab.NET do not have the Buy and Sell script eg MomentumPct which I am trying to get up and running. Why not make it easier for us illiterate non-script writers and include the Buy and Sell script? Is there a generic script for Buy and Sell which can give us a base? Is there somehow I can make some sense out of it as it is double Dutch at present (PS I have 4 degrees)? I have studied the manuals and tried examples but no further advanced in understanding why. The correction Codes are of little help and often make it worse when you try to fix them.

I do not want to bother you people with so called 'simple things' like this each time. I am sure you have better things to do!
profile picture

Eugene

#2
The MomentumPct strategy example follows its own task, documented as "Duplicate the MomentumPctSeries calculation". I'm not sure what's a "generic Buy and Sell script" (Strategy to be precise), and why should it exist when there are hundreds of indicators with different parameters?

Hundreds of examples can be found on the Forums, in the Wiki, in the Strategies section, and in the QuickRef with buy and sell rules defined. Take ROC or TRIX for example and replace just one line (e.g. TRIX with MomentumPct), execute.

Or quickly make an example yourself by plugging MomentumPct in a Rule-based Strategy and converting the code to a code-based Strategy. Voila!
profile picture

DIY

#3
I found few examples in the manuals etc with less on 'how' and 'why' - maybe I am using my old science brain instead of lateral thinking!

Re [replace just one line (e.g. TRIX with MomentumPct)simply does not make sense to me. Do you mean using the TRIX strategy then replacing each trix word with MomentumPct?

Re [plugging MomentumPct in a Rule-based Strategy], I must be missing something as it does not paste in.

Please don't despair but below is my effort using the MomPct strategy plus the Buy & Sell from ROC with some modifications eg buy >100 and sell <100.

PS Should Buy be before Sell or vice versa in the script?

CODE:
Please log in to see this code.
profile picture

Cone

#4
When you paste code, click the CODE button first and paste between the tags. (I just did this for you in the post above.)

CODE:
Please log in to see this code.
Note: Whenever you make changes to a script, click the "Compile" button or "Run the Strategy" button in the Editor toolbar. (The latter compiles and runs.)

QUOTE:
Should Buy be before Sell or vice versa in the script?
In most cases, like this script that uses mutually-exclusive logic for entry and exits, it makes no difference. In other words, by the script design it will execute only exits OR entries on a given bar, so the order in which the logic appears does not matter.
profile picture

DIY

#5
Thanks Cone, the strategy is as recommended above. However the Buys and Sells arrows seem out of sync with the aim in the screen shot attached.



It seems the easiest way to use Indicators without a Buy/Sell strategy is to find another complete Indicator which is similar and cut and paste the Buy/Sell and modify it as there does not seem to be any rules for writing Buy/Sells.

profile picture

DIY

#6
PS I changed the int Period from 20 days to 10 days.
profile picture

Eugene

#7
Nothing is out of sync.

1. The exit is made after crossing ABOVE 100. It's obvious that it works fine.
2. The entry timing may not be as obvious as the exit because it goes w/ an extra condition attached.

Look it up in the QuickRef and you'll understand why it naturally delays (or invalidates) entries:
CODE:
Please log in to see this code.
profile picture

DIY

#8
Eugene, what I am looking for is to buy when the MomPct crosses >100 and sell when it crosses <100 (plus 2 bars after crossing). On the left it is buying after 5 bars and on the right hand side it is selling instead of buying, and not selling half way along.
profile picture

Eugene

#9
Hope this helps.
CODE:
Please log in to see this code.
profile picture

Eugene

#10
QUOTE:
On the left it is buying after 5 bars

I already explained the reason to you. It's in my previous reply. Have you already looked up TurnUp in the QuickRef?
QUOTE:
and on the right hand side it is selling instead of buying, and not selling half way along.

Because your rules (voiced today) are completely different from the code (posted yesterday). And Wealth-Lab did exactly what you coded, after correcting the "<" mistake of course.
profile picture

DIY

#11
Thanks Eugene, it works beautifully. Yes, I did look up TurnUp in QuickRef.

My rules have always been the same (see 4.34 pm 9.11.11). But apparently the code written by me and adjusted by Cone at 4.46 pm was not correct. No hard feeling Cone!
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).