using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TradeFunctions;
namespace TradeScript
{
public class UserScript : UserScriptMain
{
int NN = 20;
int M1 = 10;
int M_LONG = 20;
int Count = 1;
int DelaySec = 60 * 5;
List<double> RSV = null;//AutoList();//new List<double>();
List<double> KValue = null;//AutoList();//new List<double>();
double DValue;
//初始化,设置常数...
public override void Init()
{
RSV = AutoList();
KValue = AutoList();
}
//策略运行
public override void Run()
{
uint Color = PosColor();
if (HHV(High, NN) != LLV(Low, NN))
RSV[BarCp] = (C - LLV(Low, NN)) * 100 / (HHV(High, NN) - LLV(Low, NN));
else
RSV[BarCp] = 50;
KValue[BarCp] = SMA(RSV, M1, 1);
DValue = SMA(KValue, M_LONG, 1);
if (KValue[BarCp] > DValue && Positions <= 0)
{
ClearPositionsNextBar(DelaySec); //清除所持仓位
BuyNextBar(Count, DelaySec);
Color = RED;
}
if (KValue[BarCp] < DValue && Positions >= 0)
{
ClearPositionsNextBar(DelaySec); //清除所持仓位
SellNextBar(Count, DelaySec);
Color = GREEN;
}
Line("KValue", KValue[BarCp], 3, Color);
Line("DValue", DValue, 2, 0x808080);
Line("中线", 50, 1, 0x000000);
}
}
}