#define H1 (60/BarPeriod)
#define H24 (1440/BarPeriod)
#define W1 (7200/BarPeriod)
int myTMF1() {
if (TradeIsEntry) {
AssetVar[2] += 1;
if (TradeIsLong) AssetVar[3] += 1;
if (TradeIsShort) AssetVar[4] += 1;
printf("A. \nTradeIsEntry: %.5f, AssetVar[2]: %.5f, AssetVar[3]: %.5f, AssetVar[4]: %.5f\n",TradeIsEntry,AssetVar[2],AssetVar[3],AssetVar[4]);
}
return 0;
}
int myTMF() {
if (TradeIsEntry) {AssetVar[2] = AssetVar[2] + 1;
if (TradeIsLong) AssetVar[3] += 1;
if (TradeIsShort) AssetVar[4] += 1;
}
if (TradeIsLong and TradeIsStop and AssetVar[4] < 1){
enterShort(myTMF);
printf("\nB. entershort\n");
printf("\nC. TradeIsEntry: %.5f, AssetVar[2]: %.5f, AssetVar[3]: %.5f, AssetVar[4]: %.5f\n",TradeIsEntry,AssetVar[2],AssetVar[3],AssetVar[4]);
}
return 0;
if (TradeIsShort and TradeIsStop and AssetVar[3] < 1) {
enterLong(myTMF);
printf("\nD. entershort\n");
}
return 0;
return 0;
}
function frameAlign(BOOL Event){
// Let time frame start when Event == true
// f.i. frameAlign(hour() == 0); aligns to midnight
TimeFrame = 1;
vars Num = series(0); // use a series for storing Num between calls
Num[0] = Num[1]+1; // count Num up once per bar
if(!Event)
TimeFrame = 0; // continue current time frame
else {
TimeFrame = -Num[0]; // start a new time frame
Num[0] = 0; // reset the counter
}
}
function run() {
set(TICKS|PARAMETERS|FACTORS|LOGFILE);
Weekend = 3; // don't run TMF at weekend
StartDate = 20140901;
EndDate = 20141231; //preserve 2015 data for OOS testing
BarPeriod = 60;
LookBack = 209;
if (is(INITRUN)) { AssetVar[0] = 0; AssetVar[1] = 0; AssetVar[2] = 0; AssetVar[3] = 0; AssetVar[4] = 0; }
TimeFrame = W1;
frameAlign(dow() == 7 and hour() == 23); //align weekly chart to a UTC open time of Sunday 2200 (note it is 2100 in summer)
vars closeW1 = series(priceClose());
AssetVar[1] = closeW1[0];
TimeFrame = H1;
if (dow() == 7 and hour() == 23) { AssetVar[2] = 0; AssetVar[3] = 0; AssetVar[4] = 0; } //reset to zero at start of each week
int exitDay = 5;
int exitHour = 16;
var entryMultiple = 4;//
Stop = 30 *PIP;
Trail =2 * entryMultiple * ATR(168); // optimize(0.5, 0.25, 3.0, 0.25) * entryMultiple * ATR(168); //
if (AssetVar[2] == 0) {
if (!(dow() == exitDay and hour() >= exitHour)) {
Entry = closeW1[0] + entryMultiple*ATR(168);
if (NumOpenLong == 0) enterLong(myTMF1);
Entry = closeW1[0] - entryMultiple*ATR(168);
if (NumOpenShort == 0) enterShort(myTMF1);
}
}
if (AssetVar[2] > 0) {
if (!(dow() == exitDay and hour() >= exitHour)) {
Entry = closeW1[0];
if (NumOpenLong == 0 and AssetVar[3] < 1) { enterLong(myTMF);}
if (NumOpenShort == 0 and AssetVar[4] < 1) { enterShort(myTMF);}
}
}
if (dow() == exitDay and hour() == exitHour) {exitLong("*"); exitShort("*");}
plot("closeW1", closeW1, MAIN, RED);
}