I tried to code some very simple signal using my own indicator as below:
Code: Select all
using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;
using ATCenterProxy.interop;
namespace PowerLanguage.Strategy {
public class Jeffrey_SimpleHMADailyLE : SignalObject {
public Jeffrey_SimpleHMADailyLE(object _ctx):base(_ctx){}
private int _Period;
[Input]
public int Period
{
get { return this._Period; }
set {
if (value<1) {
this._Period = 1;
} else {
this._Period = value;
}
}
}
private IOrderMarket buy_order;
private IOrderMarket sell_order;
private PowerLanguage.Indicator.Jeffrey_ATR_v2 atr;
private PowerLanguage.Indicator.Jeffrey_HMA hma;
protected override void Create() {
// create variable objects, function objects, order objects etc.
// create variable objects, function objects, order objects etc.
buy_order = OrderCreator.MarketNextBar(new SOrderParameters(Contracts.Default, EOrderAction.Buy));
sell_order = OrderCreator.MarketNextBar(new SOrderParameters(Contracts.Default, EOrderAction.Sell));
/*
atr = (PowerLanguage.Indicator.Jeffrey_ATR_v2)AddIndicator("Jeffrey_ATR_v2");
atr.Mode=1;
atr.Period=Period;
*/
hma = (PowerLanguage.Indicator.Jeffrey_HMA)AddIndicator("Jeffrey_HMA");
hma.Period=Period;
}
protected override void StartCalc() {
// assign inputs
#if DEBUG
Output.Clear();
Output.WriteLine("{0} StartCalc()", this.GetType().ToString());
Output.WriteLine("[{0}] CurrentBar={1} CurrentBarAbsolute+1={2} MaxBarsBack={3} Period={4} Close[0]={5}",
Bars.Time[0].ToString("yyyy/MM/dd HH:mm:ss"),
Bars.CurrentBar,
Bars.CurrentBarAbsolute()+1,
ExecInfo.MaxBarsBack,
Period,
Bars.Close[0]);
#endif
#if DEBUG
Output.WriteLine("StartCalc()");
Output.WriteLine("");
#endif
}
protected override void CalcBar(){
// strategy logic
#if DEBUG
Output.WriteLine("CalcBar()");
Output.WriteLine("[{0}] CurrentBar={1} CurrentBarAbsolute+1={2}",
Bars.Time[0].ToString("yyyy/MM/dd HH:mm:ss"),
Bars.CurrentBar,
Bars.CurrentBarAbsolute()+1);
#endif
bool entryCondition1 = hma.Plots[0].Values[0] > hma.Plots[0].Values[1];
bool exitCondition1 = hma.Plots[0].Values[0] < hma.Plots[0].Values[1];
if (entryCondition1) {
buy_order.Send();
}
if (exitCondition1) {
sell_order.Send();
}
#if DEBUG
Output.WriteLine("CalcBar()");
Output.WriteLine("");
#endif
}
}
}
It is totally fine if I use my own HMA indicator as study since I will set the period to 2 as minimum programmatically. Not sure why it become so trouble when it is referenced inside a strategy.