I built a strategy that buys x-days before month end and sells y-days after beginning of month. Therefore I used the "DaysFromBOM" and "DaysBeforeEOM" function, which calculates the number of trading days left ("DaysBeforeEOM") and finished ("DaysFromBOM"). Lets take a look at an example applied to an Daily chart: In this case ss stands for the number of days before month end and rr descibes the count starting from a new month.
Code: Select all
Inputs:ss(2),rr(4);
Variablespatterndetected1(false);
patterndetected1=false;
if (DaysFromBOM(Date)<rr or DaysBeforeEOM(Date)<ss) then patterndetected=true;
if patterndetected1=false then sell 1 contract this bar close;
if patterndetected1=true then buy 1 contract next bar open;
Looks as supposed so far.
Lets add a sendond time span for days within a month to also go long:
Code: Select all
Inputs:ss(0),rr(0);
Variables:patterndetected(false),patterndetected1(false);
patterndetected1=false;
patterndetected=false;
if (DaysFromBOM(Date)<rr or DaysBeforeEOM(Date)<ss) then patterndetected1=true;
if patterndetected1=false then sell 1 contract from entry ("1") this bar close;
if patterndetected1=true then buy ("1") 1 contract next bar open;
if (DaysFromBOM(Date)=7 or DaysFromBOM(Date)=8 or DaysFromBOM(Date)=9 or DaysFromBOM(Date)=10) then patterndetected=true;
if patterndetected=false then sell 1 contract from entry ("2") this bar close;
if patterndetected=true then buy ("2") 1 contract next bar open;
Now instead of buy orders I want conditions to be met first, which can lead to a buy order if wanted:
As you can see I remodeled the initial strategy using the MRO function, which takes into account the condition (DaysBeforeEOM(Date)) entering 2 days before month end and condition staying true for the next 6 bars (again to exit after 4 trading days in new month). This also works fine for the moment.
Code: Select all
if value1=-1 then condition1=false;
If condition1=false then sell 1 contract this bar close;
value1=MRO(DaysBeforeEOM(Date)=3,6,1);
if value1=1 then condition1=true;
If condition1=true then buy 1 contract next bar open;
Code: Select all
if value1=-1 then condition1=false;
if value2=-1 then condition2=false;
If condition1=false or condition2=false then sell 1 contract this bar close;
value1=MRO(DaysBeforeEOM(Date)=3,6,1);
value2=MRO(DaysFromBOM(Date)=6,3,1);
if value1=1 then condition1=true;
if value2=1 then condition2=true;
If condition1=true or condition2=true then buy 1 contract next bar open;
The dates are still correct but instead of keeping the condition true and buying and selling only once for every time span an order is entered and exited every day. Why is that: I guess the conditon 1 and 2 "cross" each other at same point.
In one of the first buying examples I gave you I was able to avoid that by naming the entry and exit conditions. How could I do something similar for the conditions?