Enter on a price change and exit after N bars
Author: tradeoholic
Creation Date: 4/2/2021 12:50 PM
profile picture

tradeoholic

#1
Hi,

I would need some coding help for the next script in order to run some simply EOD analysis.
I tried to write the code, but it does nothing. The rules are:

Entry:
-if 2 day's percentage change on close price is larger then 2%
-then short at close

Exit:
-cover at close after 3 days

It should open short positions every day, when 2 day's percentage change on close price is larger
then 2%, and should cover each of them after 3 days. More positions are possible at once. See the
code I wrote below.

Another question from my side, I have read somewhere in the forum about a plan to provide with
paid coding service for WL users. What about this ? I would be interested in it because it would
facilitate our learning, and we shouldn't turn to you with every petty problems. Is it planned for WL6
as well, or only for WL7 ?

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

tradeoholic

#2
OK, I think I figured out the right solution. (See code below).
But there is one thing that I don't understand: I enter position on 'bar' and exit on 'bar+3',
then why is the 'Bars Held' 5 in the trades list ?

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

Eugene

#3
QUOTE:
Another question from my side, I have read somewhere in the forum about a plan to provide with paid coding service for WL users. What about this ? I would be interested in it because it would facilitate our learning, and we shouldn't turn to you with every petty problems. Is it planned for WL6 as well, or only for WL7 ?

For WL6 nothing is planned because this product is not sold or supported anymore. No new development, fixes to extensions, strategy coding assistance from yours truly.

But WL6 customers can of course expect our ongoing help with WL6 keying, license transfer and maintenance renewal issues to ensure the product is operational.

Development only takes place around WL7, and it's been going at a pretty high pace. Thank you for the suggestion, we'll discuss a paid coding service for WL7 with the team!

QUOTE:
OK, I think I figured out the right solution. (See code below).

While I doubt that the solution is correct, it's worth noting that the sometimes confusing bar loop concept has been eliminated from Wealth-Lab 7.
profile picture

tradeoholic

#4
Then you say, that my solution for the code above is not correct ? (it is very suspicious for me, too, because if I enter position on 'bar' and exit three bars later, then the 'Bars Held' should be 4 and not 5 in the trades list.

What is the correct solution ?
profile picture

Cone

#5
CODE:
Please log in to see this code.


If you buy today and sell today, that's 1 bar. Buy today, sell tomorrow, that's 2 bars. This is by design to provide more pessimistic per bar results.

Long story short, if it's not exiting on the bar you want, change the control variable (in this case, it's just a constant 3).
profile picture

tradeoholic

#6
Thanks.
profile picture

tradeoholic

#7
OK, then the question arises, what if when I entered the position on bar at market (open), and want to exit on the same bar at close ? If I change the control variable to 0, it still exits on the next bar. What shell I write to exit on the same bar as the entry?

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

Cone

#8
If you want to exit on the same bar, you need to execute the Cover/Sell on the same bar. You can't wait for the next iteration of the loop.


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

tradeoholic

#9
OK, it's clear. Thanks.
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).