I suspected I am using the wrong method to define the variable in the program, so that the calculation is in error. Here is the output as below:
Current Time:1/2/2001 9:57:00, Bars.High:15911, TempL:15890, Testing TempL
Current Time:2/2/2001 11:02:00, Bars.High:16140, TempL:16105, After Shortsell
Current Time:2/2/2001 11:02:00, Bars.High:16140, TempL:15890, After Buy
The variable m_TempL.Value was assigned to 16105 at 2/2/2001 11:02:00, but suddenly m_TempL.Value was reassigned to 15890 at next tick/bar. I have investigated this problem for a few weeks. Could I have any idea to solve this problem? Thank you.
using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;
using ATCenterProxy.interop;
namespace PowerLanguage.Strategy
{
[IOGMode(IOGMode.Enabled)]
public class W_KK_Wave_V6 : SignalObject
{
private VariableObject<Double> m_TempL, m_TempH;
public W_KK_Wave_V6(object _ctx):base(_ctx)
{
buyPct = 0.011;
sellPct = 0.011;
}
[Input]
public double buyPct { get; set; }
[Input]
public double sellPct { get; set; }
private IOrderMarket m_TrailingLE;
private IOrderMarket m_TrailingSE;
protected override void Create()
{
// create variable objects, function objects, order objects etc.
m_TrailingLE = OrderCreator.MarketNextBar(new SOrderParameters(Contracts.Default, "TrailingLE", EOrderAction.Buy));
m_TrailingSE = OrderCreator.MarketNextBar(new SOrderParameters(Contracts.Default, "TrailingSE", EOrderAction.SellShort));
m_TempL = new VariableObject<double>(this);
m_TempH = new VariableObject<double>(this);
Output.Clear();
}
protected override void StartCalc()
{
// assign inputs
m_TempL.DefaultValue = 99999;
m_TempH.DefaultValue = 0;
}
protected override void CalcBar()
{
// strategy logic
if (Bars.Low[0] < m_TempL.Value)
{
m_TempL.Value = Bars.Low[0];
Output.WriteLine("Current Time:{0}, Bars.High:{1}, TempL:{2}, Testing TempL", Bars.BarUpdateTime, Bars.High[0], m_TempL.Value);
}
if (Bars.High[0] > m_TempH.Value)
{
m_TempH.Value = Bars.High[0];
}
if (Bars.High[0] > (m_TempL.Value * (1 + buyPct)) && (StrategyInfo.MarketPosition == 0))
{
m_TrailingLE.Send();
}
if (Bars.Low[0] < (m_TempH.Value * (1 - sellPct)) && (StrategyInfo.MarketPosition == 0))
{
m_TrailingSE.Send();
}
if (Bars.High[0] > (m_TempL.Value * (1 + buyPct)) && (StrategyInfo.MarketPosition < 0))
{
m_TrailingLE.Send();
m_TempH.Value = Bars.High[0];
Output.WriteLine("Current Time:{0}, Bars.High:{1}, TempL:{2}, After Buy", Bars.BarUpdateTime, Bars.High[0], m_TempL.Value);
}
if (Bars.Low[0] < (m_TempH.Value * (1 - sellPct)) && (StrategyInfo.MarketPosition > 0))
{
m_TrailingSE.Send();
m_TempL.Value = Bars.Low[0];
Output.WriteLine("Current Time:{0}, Bars.High:{1}, TempL:{2}, After Shortsell", Bars.BarUpdateTime, Bars.High[0], m_TempL.Value);
}
}
}
}