Entries on certain days if external symbol is trending
Author: 07nioe
Creation Date: 9/19/2014 5:49 AM
profile picture

07nioe

#1
Hi,

I was wondering if it is possible to code time-Conditions. For example: if S&P500 is trending up (EMA80 >S&P500), go long on Monday, Tuesday and Friday. If S&P500 is trending down (EMA80 <S&P500), go short and Wednesday and Thursday.

Thnak you for help.

Best
Niels
profile picture

Eugene

#2
Niels,

Couldn't find two key points in your question:

1. What type of strategy you're using, rule-based or code-based?

A. Code-based: there are lots of examples of using external symbol's data on the forum, QuickRef, WealthScript Guide. Here's an example of downloadable strategy (refer to "Instructions for Script Download") illustrating day of week trading:

Trading Day of Week

B. Rule-based: "External symbol trending up/down" could be expressed through "External Symbol Moving Average is trending up/down" with period = 1 (see screenshot below):




Download and install Community.Rules to get that rule and many more.

2. Is this going to be a SAR strategy (which you already know how to create) or not? In both cases, see this FAQ:

How to create a stop-and-reverse system in a Rule-based Strategy?
profile picture

Eugene

#3
Here's an example of a SAR system implementing your rules:

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

07nioe

#4
Thank you Eugene, it is exactly what I am looking for. Great.

Best
Niels
profile picture

07nioe

#5
Hi,

I tried to adjust the rules for the FDAX strategy a little bit. The explanation above is not complete. Here they are:

If the sma(80) < Close, go Long on Monday, Thursday, Friday and go Short on Tuesday and Wednesday.
If the sma(80)>Close, go Long on Tuesday and Wednesday and go Short an Monday, Thursday and Friday.

I tried to adapt the code, but it doesn*t work with yahoo data ^GDAXI. What have I done wrong? Here is the code:

CODE:
Please log in to see this code.


Thank you very much

Best
Niels
profile picture

Eugene

#6
Hi Niels,

1. When you edited my working code referencing external symbol...
CODE:
Please log in to see this code.

...it has become unclear what does your latest code have to do with the topic title which mentions "external symbol"?
CODE:
Please log in to see this code.

Where's the connection?

2.
QUOTE:
I tried to adapt the code, but it doesn*t work with yahoo data ^GDAXI.

Let me kindly recommend you this classic reading: "It doesn't work". After having finished with it, please follow author's suggestions and describe what exactly "doesn't work".
profile picture

07nioe

#7
Hi Eugene,

You are right, Sorry. The topic title is al little bit confusing. I haven't understood the strategy well, so I described it wrong.

First:

It is a pure FDAX strategy. The rules are as following:

1. If the EMA80 is above close, go long at market on Monday, Thursday and Friday and go Short at Market one Tuesday and Wednesday.
2. If the EMA80 is below close, go long at market on Tuesday and Wednesday and go short at market on Monday, Thursday and Friday.
3. Close the position on the same day at close. No overnight.

I thought the strategy code above would express these rules.


Second:

The problem is that the strategy does not run continuously for the whole time period chosen in the ^GDAXI. Sometimes the strategy indicates trades on the chart for two or three weeks than it doesn't trade at all for months; no trade indication on the chart. If you choose the S&P500 Index it works well. Maybe it is a data quality problem of Yahoo. Or the code is wrong. But to be honest, I don't know.

Thank you for help.

Best wishes
Niels






profile picture

Eugene

#8
QUOTE:
Sometimes the strategy indicates trades on the chart for two or three weeks than it doesn't trade at all for months; no trade indication on the chart.

There's not enough capital. ^GDAXI is an index. Indices tend to be priced (much) higher than stocks. If your size is 10000, trades will not be entered when ^GDAXI rises above 10000 even in raw profit mode. See FAQ | Strategies and WealthScript > Alerts are not triggered, items #4 and #5.
profile picture

07nioe

#9
Okay, Thank you. Is the code correct - especially the bool line

CODE:
Please log in to see this code.


I want to check, if the condition is true or false. That's why I have chosen bool. Is it right?

Best
Niels
profile picture

Eugene

#10
Yes.
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).