По просьбе участников вебинара ниже представлены тексты программ, использованных при построении робота, использующего нейронную сеть
Input script
[CODE]using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;
using NL;
namespace WealthLab.Strategies
{
public class MyInputScript : WealthScript
{
public NeuroLab neuroLab = new NeuroLab();
protected override void Execute()
{
// Bars Bars = GetExternalSymbol("RTSNeuro", "RTSI", true);
DataSeries vol = WealthLab.Indicators.StdDev.Series(Bars.Close, 50, WealthLab.Indicators.StdDevCalculation.Sample);
DataSeries fastma = WealthLab.Indicators.SMA.Series(Bars.Close, 10);
DataSeries slowma = WealthLab.Indicators.SMA.Series(Bars.Close, 50);
DataSeries RSI = WealthLab.Indicators.RSI.Series(Bars.Close, 50);
neuroLab.Input(vol);
neuroLab.Input((fastma - slowma)/slowma);
neuroLab.Input(RSI);
}
}
}[/CODE]
Output script
[CODE]using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;
using NL;
using ZIndicators;
namespace WealthLab.Strategies
{
public class MyOutputScript : WealthScript
{
public NeuroLab neuroLab = new NeuroLab();
protected override void Execute()
{
ZigZag z = ZigZag.Series(Bars,0.5);
DataSeries Signal = new DataSeries(Bars, "Trade Signal");
Signal[0]=0;
int i = 0;
for (i = 1; i < Bars.Count; i++)
{
if (z.Bin==0) Signal = Signal[i-1];
else Signal = z.Bin;
}
neuroLab.Output(Signal);
}
}
}[/CODE]
Тестирование на истоорических данных
[CODE]using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;
using NL;
using ZIndicators;
namespace WealthLab.Strategies
{
public class MyStrategy : WealthScript
{
protected override void Execute()
{
SetShareSize(1);
double delta=10;
double mean = 50;
PrintDebug("Start calc nn");
Bars bb = new Bars("ss", BarScale.Minute, 1);
double scale = 100;
if (Bars.Symbol == "RTSI") scale = 1;
bb.Append(Bars);
for (int b = 0; b < Bars.Count; b++)
{
bb.Close = bb.Close/scale;
bb.Open = bb.Open/scale;
bb.Low = bb.Low/scale;
bb.High = bb.High/scale;
}
PrintDebug("Scale: " + scale);
System.Diagnostics.Stopwatch wch = System.Diagnostics.Stopwatch.StartNew();
DataSeries zz = NNIndicator.Series(bb, "SampleNet");
PrintDebug("Neuro net: " + wch.ElapsedMilliseconds);
ZigZag zigzag = ZigZag.Series(Bars, 0.5);
DataSeries Signal = new DataSeries(Bars, "Trade Signal");
Signal[0]=0;
int i = 0;
for (i = 1; i < Bars.Count; i++)
{
if (zigzag.Bin==0) Signal = Signal[i-1];
else Signal = (zigzag.Bin+1)*50;
}
for (i = Bars.Count - 1; zigzag==0; i--)
{}
for (int j = i; j < Bars.Count; j++)
{
zigzag[j]=zigzag;
}
PlotSeries(PricePane, zigzag, Color.Black, WealthLab.LineStyle.Dashed, 2);
PrintDebug("Stop calc nn");
ChartPane nnpane = CreatePane(50, true, true);
PlotSeries(nnpane, zz, Color.Blue, WealthLab.LineStyle.Solid, 1);
PlotSeries(nnpane, Signal, Color.Red, WealthLab.LineStyle.Dashed, 2);
for (int bar = 0; bar < Bars.Count; bar++)
{
// PrintDebug(bar);
if (zz[bar] > mean + delta)
{
//sell signal
if (IsLastPositionActive)
{
if (LastActivePosition.PositionType == PositionType.Long)
{
SellAtMarket(bar+1, LastPosition, "NN Short");
ShortAtMarket(bar + 1, "NN Short");
}
}
else
{
ShortAtMarket(bar+1, "NN Short");
}
}
else if (zz[bar] < mean - delta)
{
//buy signal
if (IsLastPositionActive)
{
if (LastActivePosition.PositionType == PositionType.Short)
{
CoverAtMarket(bar + 1, LastActivePosition, "NN Long: Close short");
BuyAtMarket(bar+1, "NN Long: open long");
}
}
else
{
BuyAtMarket(bar + 1, "NN Long: open long");
}
}
}
}
}
}[/CODE]
Торговый робот на платформе WLRTAlgoTrading
[CODE]using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;
using NL;
using ZIndicators;
namespace WealthLab.Strategies
{
public class MyStrategy : WLRT.LiveTrading.WealthScript
{
protected override void Execute()
{
SetShareSize(1);
double delta=10;
doubhfdkjfhle mean = 50;
PrintDebug("Start calc nn");
Bars bb = new Bars("ss", BarScale.Minute, 1);
double scale = 100;
if (Bars.Symbol == "RTSI") scale = 1;
bb.Append(Bars);
for (int b = 0; b < Bars.Count; b++)
{
bb.Close = bb.Close/scale;
bb.Open = bb.Open/scale;
bb.Low = bb.Low/scale;
bb.High = bb.High/scale;
}
PrintDebug("Scale: " + scale);
System.Diagnostics.Stopwatch wch = System.Diagnostics.Stopwatch.StartNew();
DataSeries zz = NNIndicator.Series(bb, "SampleNet");
PrintDebug("Neuro net: " + wch.ElapsedMilliseconds);
ZigZag zigzag = ZigZag.Series(Bars, 0.5);
DataSeries Signal = new DataSeries(Bars, "Trade Signal");
Signal[0]=0;
int i = 0;
for (i = 1; i < Bars.Count; i++)
{
if (zigzag.Bin==0) Signal = Signal[i-1];
else Signal = (zigzag.Bin+1)*50;
}
for (i = Bars.Count - 1; zigzag==0; i--)
{}
for (int j = i; j < Bars.Count; j++)
{
zigzag[j]=zigzag;
}
PlotSeries(PricePane, zigzag, Color.Black, WealthLab.LineStyle.Dashed, 2);
PrintDebug("Stop calc nn");
ChartPane nnpane = CreatePane(50, true, true);
PlotSeries(nnpane, zz, Color.Blue, WealthLab.LineStyle.Solid, 1);
PlotSeries(nnpane, Signal, Color.Red, WealthLab.LineStyle.Dashed, 2);
for (int bar = 0; bar < Bars.Count; bar++)
{
// PrintDebug(bar);
if (zz[bar] > mean + delta)
{
//sell signal
if (IsLastPositionActive)
{
if (LastActivePosition.PositionType == PositionType.Long)
{
SellAtMarket(bar+1, LastPosition, "NN Short");
ShortAtMarket(bar + 1, "NN Short");
}
}
else
{
ShortAtMarket(bar+1, "NN Short");
}
}
else if (zz[bar] < mean - delta)
{
//buy signal
if (IsLastPositionActive)
{
if (LastActivePosition.PositionType == PositionType.Short)
{
CoverAtMarket(bar + 1, LastActivePosition, "NN Long: Close short");
BuyAtMarket(bar+1, "NN Long: open long");
}
}
else
{
BuyAtMarket(bar + 1, "NN Long: open long");
}
}
}
}
}
}[/CODE]