Friday, August 20, 2010 3:32 PM
I would like to test/tweak this strategy.
1. Price crosses above the 50 EMA and RSI(20) crosses above the 50 level at the same time
2. Price crosses above the 50 EMA first, and then RSI(20) crosses above the 50 level
3. RSI(20) crosses above the 50 level first, and then Price crosses above the 50 EMA
Note1: Can we set the number of bars within which the 1st cross occurs (EMA or RSI) followed by the second cross? That way we can optimize the strategy based on the number of bars. If not we can arbitrarily set it at 5 bars.
2. I would like the scan to use the weekly chart and daily chart. But I don't see a way in chartscripts to make the closing price 'context sensitive'. That way if the condition occurs in weekly charts I want to switch to daily to see if the lower time frame shows similar conditions.
Note 3. The exit condition will be the same in reverse. i.e., Long entry on crossing up, exit on crossing down.
Chris White responded "Coding & Testing a simple strategy"
I'll try and answer this question in several parts - here's the first:
1. The ChartScript code for Price crosses above 50 EMA and RSI(20) crosses above 50 on the same bar is as follows:
Code: Select all
cond1: CROSS(C, EMA(C, 50));
cond2: CROSS(RSI(C, 20), 50);
event: cond1 & cond2;

Because this script has an 'event' output it can be dragged into a security selector to see the results over your entire snapshot.
Part 2: Price crosses above the 50 EMA first, and then RSI(20) crosses above the 50 level
The trick here is to generate a true signal for 'x' bars after the first condition hits and then generate an event if the second condition hits during the period.
The script could be written like this:
Code: Select all
cond1: CROSS(C, EMA(C, 50));
cond2: CROSS(RSI(C, 20), 50);
within4: Count(cond1, 4) > 0;
event: within4 & cond2;
Here's the output from the above script:

Your third question is just the reverse of this - I'll leave that one to you.
Final Part...
If you want to fix the cycle to weekly for everything in the script (Close, RSI, EMA) you can create a new script and call the existing one specifying to use a weekly cycle:
Code: Select all
event: "My.Batman2[event]#WEEK1";
If you view this on a weekly chart you would see an event for 1 bar, but if you viewed it on a daily chart you would see the event span 5 bars (1 for each day of the week that the signal was true).
If you run the scan through the selector it will run over daily bars using weekly values. If you want to make sure the event only fires on a friday you can add a condition such as DAY==5:
Code: Select all
event: "My.Batman2[event]#WEEK1" && DAY==5;
Chris.
Batman responded "Coding & Testing a simple strategy"
That helps a lot. I understand using the ampersand "&" operator to combine conditions like
Code: Select all
Event: Cond1 & Cond2 & Cond3
Code: Select all
Event: Cond1 OR Cond2 OR Cond3
How can I save my layouts? For example, if I have a layout with the price chart, volume, EMA with another pane for the RSI. Lets say later I want another with price, BB, Williams %R do I have to redo the layout each time or can I simply load it by "template"?
Chris White responded "Coding & Testing a simple strategy"
The OR operator is the pipe character as in:
Code: Select all
event: cond1 | cond2;
"My.Batman2[event]#WEEK1"
Putting double quotes around a statement is shorthand for 'call the script', so in this case it is calling the My.Batman script. If you put your scripts into the MyScripts file in the recommended way then they should be prefixed with My. whenever you call them, so a script called Batman in the MyScripts file can be called by another script using the syntax My.Batman.
You can add square brackets to the script call to get at any one of the output lines contained in the script and so in this case we are getting the 'event' output line.
The #WEEK1 defines an aggregation period for the bars in the called script, so #WEEK1 means aggregate bars over a 1 week period.
Putting it all together the line means:
Call a script with the name Batman2 that is contained in MyScripts file and get the event output but use bars made up of 1 weeks worth of daily bars when doing the calculations contained in that script.
if you want to use daily bars you can substitute #DAY1, or just leave off that bit altogether.
Right now you cannot save chart templates but that is high on the priority list of things to add.
Thanks,
Chris.