Are there any glaring errors in my syntax, or logic for that matter? (Btw I know I have some redundant code and could use a couple of helper methods):
#region Variables
// Wizard generated variables
private int regPeriod = 1; // Default setting for RegPeriod
private double stDev = 2; // Default setting for StDev
private int countOfOutside = 1; // Default setting for CountOfOutside
private int ticksInProfitForInitialStop = 1; // Default setting for TicksInProfitForInitialStop
private int trailStopTicks = 1; // Default setting for TrailStopTicks
private int secondSeriesMins = 1; // Default setting for SecondSeriesMins
// User defined variables (add any user defined variables below)
#endregion
/// <summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
/// </summary>
protected override void Initialize()
{
Add(PeriodType.Minute,secondSeriesMins);
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
//1
protected override void OnBarUpdate()
{
if (CurrentBars[0] <= BarsRequired) return;
int countOfOut = 0;
//is the 2ndary series uptrending? (50 per lin reg)
if(RegressionChannel(Closes[1],50,2)[1] > RegressionChannel(Closes[1],50,2)[5])
{
if(Low[1] < RegressionChannel(regPeriod,stDev).Lower[1])
{
while(Low[countOfOut + 1] < RegressionChannel(regPeriod,stDev).Lower[countOfOut + 1])
{
countOfOut++;
}
if(countOfOut == countOfOutside)
{
EnterLong(1,"Signal");
SetStopLoss("Signal",CalculationMode.Ticks,8,true);
SetTrailStop("Signal",CalculationMode.Ticks,10,true);
}
}
}
//is the 2ndary series downtrending? (50 per lin reg)
else if(RegressionChannel(Closes[1],50,2)[1] < RegressionChannel(Closes[1],50,2)[5])
{
if(High[1] > RegressionChannel(regPeriod,stDev).Lower[1])
{
while(High[countOfOut + 1] > RegressionChannel(regPeriod,stDev).Upper[countOfOut + 1])
{
countOfOut++;
}
if(countOfOut == countOfOutside)
{
EnterShort(1,"Signal");
SetStopLoss("Signal",CalculationMode.Ticks,8,true);
SetTrailStop("Signal",CalculationMode.Ticks,10,true);
}
}
}
if (Position.MarketPosition == MarketPosition.Long)
{
//check the current profit in ticks
double profitInTicks = (Close[0] - Position.AvgPrice) / .25;
//is the last close greater than the initial profit price to set the first stop, + the trailing stop ticks?
if(profitInTicks >= ticksInProfitForInitialStop + trailStopTicks)
{
SetTrailStop("Signal",CalculationMode.Ticks,trailStopTicks,true);
}
else if(profitInTicks >= ticksInProfitForInitialStop)
{
SetStopLoss("Signal",CalculationMode.Ticks,ticksInProfitForInitialStop,true);
}
}
if(Position.MarketPosition == MarketPosition.Short)
{
//check for profit target
double profitInTicks = (Position.AvgPrice - Close[0]) / .25;
//is the last close greater than the initial profit price to set the first stop, + the trailing stop ticks?
if(profitInTicks >= ticksInProfitForInitialStop + trailStopTicks)
{
SetTrailStop("Signal",CalculationMode.Ticks,trailStopTicks,true);
}
else if(profitInTicks >= ticksInProfitForInitialStop)
{
SetStopLoss("Signal",CalculationMode.Ticks,ticksInProfitForInitialStop,true);
}
}
}



Comment