I have a strategy - stop&reverse system, when price crossing a SMA
After i get 10 ticks in profit, i want to move my stop loss to breakeven + 1 tick
I tried to do my self after i found few examples here, but is not working.
I will be very happy if someone can help me.
Here is the code.
I do not know where to modify and what.
Thank you.
[Description("Price cross SMA")]
public class PriceCrossSMA : Strategy
{
#region Variables
// Wizard generated variables
private int sma = 50; // Default setting for Sma
private int target = 100; // Default setting for Target
private int stopLoss = 10; // Default setting for StopLoss
// 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(SMA(Sma));
Add(SMA(Sma));
SetProfitTarget("", CalculationMode.Ticks, Target);
SetStopLoss("", CalculationMode.Ticks, StopLoss, false);
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Condition set 1
if (CrossAbove(Close, SMA(Sma), 1))
{
EnterLong(DefaultQuantity, "");
}
// Condition set 2
if (CrossBelow(Close, SMA(Sma), 1))
{
EnterShort(DefaultQuantity, "");
}
}
Comment