There isn't a checkbox in the backtester to always exit on the 3rd Friday.
In your strategy you would have to get the current bar's date and then use the Date.getDay() method to determine the day of the week. Then use the plain getDay() method to get the day of the month to determine if it's the 3rd Friday.
Daniel
There are several errors in the script
1. function Main() should be function main()
2. Day() is not an existing object. To create a Date Object based on bar time you need to use getValue("time") (see the link to the article in the EFS KnowledgeBase for the description and syntax of the function). To correct this replace var weekday = new Day();
with var weekday = getValue("time");
3. In the condition if (weekday == 6) you omitted to use the method .getDay() to retrieve the day of the week from the object (for the description and syntax of the method see this article in the EFS KnowledgeBase on the Date Object). Also you are evaluating if the weekday is equal to 6 which corresponds to Saturday and not Friday. To correct this replace if (weekday == 6 ) {
with if (weekday.getDay() == 5 ) {
4. The line drawTextAbsolute( 0, AboveBar1, "Friday" ); is incorrect or incomplete depending on which function you intended to use (see this or this article on drawText() or drawTextRelative() functions). To correct this replace the line with either drawText("Friday", AboveBar1);
or drawTextRelative(0, AboveBar1, "Friday", Color.blue, null, Text.PRESET, "Arial", 10, "TextA"+rawtime(0));
If you use the first option you may also want to add a setDefaultFont() statement in the preMain() function to set the font and its properties
Once you make the above corrections the formula should write Friday on each bar that is time stamped as Friday
Alex
Originally posted by guterm Hmm, I must be a fool, I can't have a text on the Friday:
/** draw test "Friday" on the 3rd Friday of the Month
************************************************** ****/
function preMain() {
setPriceStudy(true);
setStudyTitle("Friday");
}
function Main() {
var weekday = new Day();
var monthday = new Date();
if (weekday == 6 ) {
// if (weekday == 6 && monthday >=15 && monthday <= 21)
// then 3rd friday
drawTextAbsolute( 0, AboveBar1, "Friday" );
}
return;
}
Daniel
Adding to my reply. Once you have made the changes I suggested you will also need to modify the following line (which is currently commented out) // if (weekday == 6 && monthday >=15 && monthday <= 21)
with the following to get it to work if (weekday.getDay() == 5 && weekday.getDate() >=15 && weekday.getDate() <= 21)
Note that in the second and third condition I use the .getDate() method of the Date Object which returns the date of the month. At this point the text should print only on the third Friday of each month
Then you can comment out (or delete) the following line of code as it is not required in the context of your script var monthday = new Date();
Hope this helps
Alex
Daniel
That is because you have Text.PRESENT instead of Text.PRESET in the drawTextRelative() function
Once you correct that the text should display.
Alex
Originally posted by guterm Alex
Thank you very much for your kindly help and explanations.
But I still get no text on the chart with the following:
function preMain() {
Comment