public class ShortTermBreakOutATR : Strategy
{
#region Variables
// Wizard generated variables
private int myInput0 = 1; // Default setting for MyInput0
// 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()
{
if (Position.MarketPosition == MarketPosition.Long)
{
//Print ATRStopLoss
double value = Position.AvgPrice-(ATR(14)[1]*2);
Print ("The Current value is " + value.ToString());
SetStopLoss(CalculationMode.Price,(Position.AvgPri ce-(ATR(14)[1]*2)));
}
if (Position.MarketPosition == MarketPosition.Short)
{
//Print ATRStopLoss
double value = Position.AvgPrice-(ATR(14)[1]*2);
Print ("The Current value is " + value.ToString());
SetStopLoss(CalculationMode.Price,(Position.AvgPri ce+(ATR(14)[1]*2)));
}
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Condition set 1
if (GetCurrentBid() > Close[15]
&& RSI(14, 3).Avg[0] < 70)
{
EnterLong(DefaultQuantity, "Long");
DrawDot("My dot" + CurrentBar, false, 0, 0, Color.Green);
}
// Condition set 2
if (Close[0] < Close[7])
{
ExitLong("Exit", "Long");
}
// Condition set 3
if (GetCurrentBid() < Close[15]
&& RSI(14, 3).Avg[0] > 30)
{
EnterShort(DefaultQuantity, "Short");
DrawDot("My dot" + CurrentBar, false, 0, 0, Color.Red);
}
// Condition set 4
if (Close[0] > Close[7])
{
ExitShort("Exit", "Short");
}
}
Comment