5
« on: 27.03.2015, 12:45:00 »
Попробуй так:
//Проба - stoch
//prstoch
#line 0 solid lime
#line 1 solid red
extern "number" perstoh = 14; // Период стохастика
extern "number" skol = 3; // Период скользящей
extern "number" lots = 1; // Базовое число лотов актива
static SecName;
static lotsize;
static NewCandle;
static CandleTime;
static quantity;
static posn = 0;
function init()
{
setInitCandles(perstoh+1);
SecName = getSecName();
lotsize = getLotSize();
NewCandle = false;
CandleTime = getFormattedTime(getServerTime());
}
function onNewCandle()
{
NewCandle = true;
CandleTime = getFormattedTime(getCandleTime());
quantity = lots*2;
// Определим число лотов в портфеле
}
function calc()
{
line[0] = IndRef("stochastic", perstoh, skol, ind_sma)[0];
line[1] = IndRef("stochastic", perstoh, skol, ind_sma)[1];
// автозапуск при позиция = 0
if (posn == 0 && line[0][-1] > line[1][-1] && line[0] < line[1])
{
var order = new_object("hash");
order["quantity"] =2 ;
order["operation"] = OP_BUY;
trade_action::transact(order);posn = 1;
}
if(posn ==0 && line[0][-1] > line[1][-1] && line[0] < line[1])
{
var order = new_object("hash");
order["quantity"] =2 ;
order["operation"] = OP_SELL;
trade_action::transact(order);posn = -1;
}
if (NewCandle ) {
if(posn ==-1 && line[0][-1] > line[1][-1] && line[0] < line[1])
{
var order = new_object("hash");
order["quantity"] =2 ;
order["operation"] = OP_BUY;
trade_action::transact(order);posn = 1;
}
if(posn ==1 &&line[0][-1] < line[1][-1]&& line[0] > line[1])
{
var order = new_object("hash");
order["quantity"] =2 ;
order["operation"] = OP_SELL;
trade_action::transact(order);posn = -1;
}
NewCandle = false;
}
}
Усgехов!