4 ms·
The following code is for a backtester. I created the application on tickmarkt. It checks when an exponential moving average with 5 day lags crosses over the 10
by cashua 17y ago
The following code is for a backtester. I created the application on tickmarkt. It checks when an exponential moving average with 5 day lags crosses over the 10 day moving average and will open a trade. You might need a large time period for this to work or you can lower the lag and it will fire off sooner. I have some technical analysis indicators built into the system that I will soon open source as well.
here is some example backtester code:
var hasTrade = false;
function Init()
{
}
function Tick()
{
//5-day exponential moving average
var ma5=analysis.Technical.ema('AAPL',
1 ,
1 ,
5 );
//10-day exponential moving average
var ma10=analysis.Technical.ema('AAPL',
1 ,
1 ,
10 );
//invalid time data because of weekend
if (ma5.length == 0 || ma10.length == 0)
return;
if (ma5[0].value > ma10[0].value)
{
//open a trade if we dont have one
if (hasTrade == false)
{
api.Broker.OpenTrade('AAPL',
100,
'open trade on cross');
hasTrade = true;
}
}
else if (ma5[0].value < ma10[0].value)
{
//close a trade since we have one
if (hasTrade == true)
{
api.Broker.OpenTrade('AAPL',
-1100,
'close trade on cross');
hasTrade = false;
}
}
}
function Destroy()
{
}
- matticakes 17y agocan I email you at any particular address?
- cashua 17y agotickmarkt at gmail Sorry Edit its tickmarkt not tickmark