Using Weekly and Monthly Time Frames in Script
Posted: Tue Aug 02, 2016 12:34 pm
A script will be run automatically in weekly mode if it is placed onto a weekly chart and monthly if placed on a monthly chart, but what if you want to have the script always run in Weekly or Monthly mode regardless of the chart it is placed on?
The way to do that is to have the 'Period Independent' version of the script as one script and call it with a period specified from another.
Imagine the following script is called Test1 and is in your 'My Scripts' library
Params:
Name Type Default Min Max
N Double 4 1 10000
Now you could create a script called Test1Weekly which would look like this:
Params:
Name Type Default Min Max
N Double 4 1 10000
Note that to call a script in your 'My Scripts' Library you have to prefix the script name with 'My.'
You could write a similar script for the Monthly version.
These scripts can be added to a chart and also to the Entries and Exits area of the program for generating trading signals.
If you are just creating a Trading Template to show the current state of the indicator, you don't actually need to create separate versions of the script. The template allows you to specify #WEEK1, #MONTH1 at the end of the script name. Take a look at the weekly squeeze template for an example - there cell H2 contains the value 'GL_SqueezeLength(1)#WEEK1' which calls the GL_SqueezeLength script in Weekly mode (1 week cycle).
The way to do that is to have the 'Period Independent' version of the script as one script and call it with a period specified from another.
Imagine the following script is called Test1 and is in your 'My Scripts' library
Code: Select all
Event: STREAK(C)==N;
Name Type Default Min Max
N Double 4 1 10000
Now you could create a script called Test1Weekly which would look like this:
Code: Select all
Event: FML('My.Test1(N)#WEEK1');
Name Type Default Min Max
N Double 4 1 10000
Note that to call a script in your 'My Scripts' Library you have to prefix the script name with 'My.'
You could write a similar script for the Monthly version.
These scripts can be added to a chart and also to the Entries and Exits area of the program for generating trading signals.
If you are just creating a Trading Template to show the current state of the indicator, you don't actually need to create separate versions of the script. The template allows you to specify #WEEK1, #MONTH1 at the end of the script name. Take a look at the weekly squeeze template for an example - there cell H2 contains the value 'GL_SqueezeLength(1)#WEEK1' which calls the GL_SqueezeLength script in Weekly mode (1 week cycle).