Простой робот на 2EMA
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;
namespace WealthLab.Strategies
{
public class MyStrategy : WealthScript
{
private StrategyParameter slider1;
private StrategyParameter slider2;
public MyStrategy()
{
slider1 = CreateParameter("Fast Period",12,2,200,20);
slider2 = CreateParameter("Slow Period",24,2,200,20);
}
protected override void Execute()
{
DataSeries maFast = EMAModern.Series(Close, slider1.ValueInt);
DataSeries maSlow = EMAModern.Series(Close, slider2.ValueInt);
PlotSeries(PricePane,EMAModern.Series(Close,slider1.ValueInt),Color.Red,LineStyle.Solid,2);
PlotSeries(PricePane,EMAModern.Series(Close,slider2.ValueInt),Color.Green,LineStyle.Solid,2);
for(int bar = GetTradingLoopStartBar(24); bar < Bars.Count; bar++)
{
if (IsLastPositionActive)
{
Position p = LastPosition;
if (p.EntrySignal.Contains("Group1|"))
{
if (CrossUnder(bar, maFast, maSlow))
{
SellAtClose(bar, p, "Group1");
}
}
}
else
{
if (CrossOver(bar, maFast, maSlow))
{
BuyAtClose(bar, "Group1|");
}
}
}
}
}
}
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;
namespace WealthLab.Strategies
{
public class MyStrategy : WealthScript
{
private StrategyParameter slider1;
private StrategyParameter slider2;
public MyStrategy()
{
slider1 = CreateParameter("Fast Period",12,2,200,20);
slider2 = CreateParameter("Slow Period",24,2,200,20);
}
protected override void Execute()
{
DataSeries maFast = EMAModern.Series(Close, slider1.ValueInt);
DataSeries maSlow = EMAModern.Series(Close, slider2.ValueInt);
PlotSeries(PricePane,EMAModern.Series(Close,slider1.ValueInt),Color.Red,LineStyle.Solid,2);
PlotSeries(PricePane,EMAModern.Series(Close,slider2.ValueInt),Color.Green,LineStyle.Solid,2);
for(int bar = GetTradingLoopStartBar(24); bar < Bars.Count; bar++)
{
if (IsLastPositionActive)
{
Position p = LastPosition;
if (p.EntrySignal.Contains("Group1|"))
{
if (CrossUnder(bar, maFast, maSlow))
{
SellAtClose(bar, p, "Group1");
}
}
}
else
{
if (CrossOver(bar, maFast, maSlow))
{
BuyAtClose(bar, "Group1|");
}
}
}
}
}
}
Последнее редактирование: