"Price is lower by x%..." condition throws error
Author: digitalsculpture
Creation Date: 9/30/2020 11:40 AM
profile picture

digitalsculpture

#1
The strategy I'm currently using is to buy at limit channel low, and sell at limit channel high. I would like to add a double down market buy if a current open position drops by 3%. When I drag "buy at market" into the strategy window and add a condition to buy when "price is lower by x% than it was at current position's entry bar" I get an error that reads: "there were errors attempting to compile the strategy... :error CS1040: Preprocessor directives must appear as the first non-whitespace character on a line".

How can I setup the double down market buy correctly in the rules based strategy?
profile picture

Eugene

#2
QUOTE:
error CS1040: Preprocessor directives must appear as the first non-whitespace character on a line".

It's a bug in the condition. The companion one ("higher than") wasn't affected. Please download and overwrite the Community.Rules library, then reopen the Rule-based Strategy window. No WLD restart required.

QUOTE:
When I drag "buy at market" into the strategy window and add a condition to buy when "price is lower by x% than it was at current position's entry bar"

Nevertheless, this is not going to work. This condition is to be attached to an Exit rule only. It's incompatible with Entries.
profile picture

digitalsculpture

#3
Thanks. I've created an account for the wiki, but I'm unable to "see" the attachment link at the top of the page. Are you able to adjust a permission that will let me access the attachment, or is there a workaround I can do on my end?
profile picture

Eugene

#4
Just granted you the necessary permissions, please retry.
profile picture

digitalsculpture

#5
Thanks. I was able to access the attachment. Is there a way to set the double down buy up in a rules based strategy now that I have the new community rules library?
profile picture

Eugene

#6
Not with Rules but this task can be easily accomplished in code.
profile picture

digitalsculpture

#7
It's great to hear that there's a way of doing it. Do you have any time to help me with the code? Here are the details about the strategy setup:
- Buy at limit channel low 300 during market hours from 9:30 to 3:30pm EST
- Sell at limit channel high 30
- Sell all positions with market orders at last bar of the day
- Double-down buy with market order if current position drops by X% (I would want to set up the double-down buy as a variable so I can optimize)
profile picture

Eugene

#8
Here you go:
CODE:
Please log in to see this code.
profile picture

digitalsculpture

#9
Thanks so much!
profile picture

digitalsculpture

#10
Sorry I didn't think of this last time, but do you think you could make the limit buy and sell periods variables as well?
profile picture

Eugene

#11
Sure I can but one of the goals is to help you make it and utilize the program to the best extent possible. Please refer to the WealthScript Programming Guide > Programming Trading Strategies > Strategy Parameters for a hands-on tutorial on creating parameters. Good luck!
profile picture

digitalsculpture

#12
I took a look at it but it's way over my head. I don't have any experience coding, unfortunately.
profile picture

Eugene

#13
So it's a good time to start building some experience. And the walkthrough in Method 3 (which I was referring to) is quite visual to help this.
profile picture

joma

#14
Hi,

the condition produces as a buy at market entry condition weird results:

1) Error message: "Error processing symbol DOW DataSeries do not have equal number of values for mathematical operation
Error processing symbol DOW DataSeries do not have equal number of values for mathematical operation"

Surprisingly, this message does not appear when you perform the strategy on a friend's computer.


2) In addition, I receive no trades when using decimal number like 0,75 as a percentage. This error only appear when the entry buy at market is combined with another condition as "CMO is oversold".

Thanks for you help!

Best

Georg
profile picture

Eugene

#15
Hi Georg,

QUOTE:
do not have equal number of values for mathematical operation

Please refer to the Errors section > "DataSeries do not have equal number of values for mathematical operation". It has to do with data hence no problem on the friend's PC.

QUOTE:
when using decimal number like 0,75 as a percentage

Issue may be related to using German regional settings.
profile picture

joma

#16
Thanks, Eugene.

I updated the data and I still get the error message. I do perform any mathematical operation. The two Entry conditions I use is "CMO is oversold" and "Price is lower by X% than it was a number of bars ago". Backtesting is performed on Dow 30 (yahoo end of day data). Please note that I restarted the WL, the computer, rebuild the strategy etc.

Re decimal number: I also tried country settings. It still does not work. Strange enough 0,5 works, 0,75 does not work.

profile picture

Eugene

#17
0.75 works just fine as any other value so this is not an issue. And I did try various regional settings with different decimal/currency separators.

As for "DataSeries do not have equal number of values for mathematical operation", indeed you get it when you 1) switch from another DataSet where you executed the backtest and 2) click "Run the strategy" on Rules tab you get that message. Funny bug. Workaround: click either "Go" or "Backtest on all symbols...":



Voila.
profile picture

joma

#18
Thanks, Eugene.

Unfortunately, the issues persist. It does not matter whether I click on "Go", "Backtest on all Symbols in Dow 30" or "Run the Strategy".

Decimal figures don`t work properly either.

I am not sure what to do now. Any idea?
profile picture

Eugene

#19
You can 'Open strategy code in a new window' to attempt fix any issue there directly.

I have no idea what this means and what you did exactly: "I also tried country settings. It still does not work". Like I shown you it works with U.S. regional settings.
profile picture

joma

#20
Unfortunetly, I cannot code.

Could you please check the code:

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

Eugene

#21
There is nothing wrong with the code. I don't have much to suggest you but to switch to other regional settings like U.S. Make sure that both numeric and currency decimal separators in Windows (Control panel - Regional options) are set to "." (dot). You might have need to replace "," to " " (blank space) in digit grouping symbol, if applicable.
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).