Price passes a peak, achieving new high
Author: romaioi
Creation Date: 5/25/2015 11:18 AM
profile picture

romaioi

#1
Back attempting to code after a second multi-year break - well the last attempt didn't last more than the week spent around the last thread I started. I've attempted to code up a translated script in version 6/C# based language. Below is where I came to. It still has some compile errors - I've made comments on the line where those sticking points arose. Is anyone able to provide me with some guidance on cleaning it up to make it work?

This one is around getting the peak functions to work. The aim was to identify when price passes a peak, effectively achieving a fresh high.

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

Eugene

#2
Gianluca,

Let's put WSTL out of the equation and focus at what rules/conditions you're trying to accomplish. Price exceeding the previous peak aiming at a new high:

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

romaioi

#3
Thanks for the suggestion Eugene. Much appreciated. It looks simpler. I'll play around with combining that with a number of other rules to see if I can arrive at equivalent scripts to some of my older ones and generate the same results.
profile picture

romaioi

#4
Hi Eugene,

Hope you don't mind a follow up query. I added the following lines just above "BuyAtMarket(bar+1)" to introduce a rule to buy after price passes the peak. (Also used lower peak thresholds to be able to see more events.)

CODE:
Please log in to see this code.

My read of the result is that all previous peaks are used a reference points for the price cross (rather than the last peak).....as multiple entry markers that are below the most recent peak (relative to the entry markers) are observed. Is this correct? Is there a smart way to ensure the last peak is considered (I was thinking a 10 bar lookback would work but its too arbitrary)? Or is there something I need to understand about how the code works in consideration to the example you provided?

Apologies for this being rather basic, but it will help me rebuild much more than what I am asking about.

Sincerely,

Gianluca
profile picture

Eugene

#5
Gianluca,

A new peak can be discovered when the price has declined a defined percentage. This is just what my example code above showed. In plain English, what are your buy/sell rules - precisely? Is it buy all time high or something else? Please clarify what you want to achieve.
profile picture

romaioi

#6
Hi Eugene,

Precise rules wrt to the query are in Italics. In the script attempted above, there was only one key rule: if price (intraday high in this case) crosses above than the most recent peak, then by at market.

Once that's working, the intention is to apply the following:
If price surpasses the previous peak within 12 days of the Close crossing above the 20 day moving average, then buy at market. Peak thresholds used are between 4 & 10%.

I managed to get this working in version 4, but am just trying to recode and expand in the v6 language. Getting the "price surpassing the most recent peak" test working was the key aspect I had trouble with back in v4 and now here.

I used the SellAtClose rule just to help with testing. But otherwise will use an initial stop just below the most recent trough followed by an ATR based trailing stop.

Sincerely, Gianluca
profile picture

Eugene

#7
Here you go:

CODE:
Please log in to see this code.


Keep in mind that a peak is detected once the price has already declined.
profile picture

WEALTHPRO25

#8
i wanted price pass a peak after new low and i modified the code, it works fine, however when i screen i do not get alert notification even though in the trades i can see all the trades and dates, i would like to get the alerts showing the trades when i screen, please help, thanks

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

Eugene

#9
It doesn't work fine - it badly peaks into the future. Same with alerts. That's what you get for breaking working code from post #2 and not reading the WealthScript Programming Guide. Solution: FAQ | Strategies and WealthScript > Alerts are not triggered
profile picture

superticker

#10
Alerts are only created for the off-the-chart bar (i.e. "bar+1" when bar=Bars.Count-1 in the trading FOR loop). Change the code to:
CODE:
Please log in to see this code.

I'm not sure why you want to unconditionally sell the LastPosition. This doesn't make sense to me unless you want to hold the position for only one bar. Why would you want to do that?... day trading?
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).