int count=1;
int lastcount=1;
int b=0;
int tmfTick()
{
if(b==Bar) count++; else {lastcount=count;count=1;b=Bar;}
return 0;
}
// start a pending phantom trade for activating a TMF
bool initTick()
{
static TRADE* tick = 0;
if(tick || Bar < LookBack)
return false;
Lots = -1; // phantom trade
Entry = 2*priceClose(); // high entry limit
EntryTime = 999999; // keep pending forever
tick = enterLong(tmfTick);
Lots = 1; // back to default values
Entry = 0.;
EntryTime = 1;
return tick != 0;
}
function run()
{
set(TICKS+PLOTNOW);
Weekend=1;
BarPeriod=1;
StartDate=20141202;
EndDate=20141209;
PlotWidth=1024;
Hedge=5;
LookBack=201;
Lots=100;
vars Price=series(price());
var Dom=DominantPeriod(Price,100);
vars BP=series(BandPass(Price,Dom*2,0.1));
plot("BP",BP[0],NEW,BLACK);
vars tc=series(count);
vars SM=series(SMA(tc,200));
var w=(MaxVal(tc,200)-MinVal(tc,200))/3;
//if (is(INITRUN))
initTick();
// plot("tickCount",lastcount,NEW,BLACK);
plot("count",count,NEW,BLUE);
plot("sm",SM[0],0,BLACK);
plot("upper",SM[0]+w,0,CYAN);
plot("lower",SM[0]-w,0,MAGENTA);
plot("Bar",Bar,NEW,BLACK);
Stop=3*ATR(60);
Trail=2*ATR(60);
TrailSlope=350;
// TrailLock=80;
if (crossOver(tc,SM[0]-w)and falling(BP) and NumOpenLong<1 //and Bar>360
) enterLong();
if (crossOver(tc,SM[0]-w) and rising(BP) and NumOpenShort<1 //and Bar>360
) enterShort();
}