Slepil strategiyu(
Renko), bilo vse horosho.
Dobavil DayStopLoss DayTakeProfit i vse ploho.
Kto vidit oshibku?
Код:
{
#region Variables
// Wizard generated variables
private double mACD_plus = 0.0100; // Default setting for MACD_plus
private double basB = 0.1; // Default setting for BasB
private int udoB = 100; // Default setting for UdoB
private int udoM = -100; // Default setting for UdoM
private int udo_period = 10; // Default setting for Udo_period
private double basM = -0.1000; // Default setting for BasM
private double mACD_minus = -0.01; // Default setting for MACD_minus
private int stopProfit = 30; // Default setting for StopProfit
private double dayTakeProfit = 500; // Default setting for DayTakeProfit
private double dayStopLoss = 500; // Default setting for DayStopLoss
private double priorTradesCumProfit = 0;
private double priorTradesCount = 0;
private int timeStart1 = 100000; // Default setting for TimeStart
private int timeEnd1 = 220000; // Default setting for TimeEnd
private bool CheckTime()
{
// Проверка диапазона времени
bool rez=false;
if (timeStart1 < timeEnd1 && ToTime(Time[0]) >= timeStart1 && ToTime(Time[0]) < timeEnd1) rez=true;
if(timeStart1 > timeEnd1) rez=true;
return rez;
}
// 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()
{
SetProfitTarget("", CalculationMode.Ticks, StopProfit);
SetStopLoss("", CalculationMode.Ticks, StopProfit, false);
CalculateOnBarClose = false;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if(!CheckTime()) return;
// At the start of a new session
if (Bars.FirstBarOfSession)
{
// Store the strategy's prior cumulated realized profit and number of trades
priorTradesCount = Performance.AllTrades.Count;
priorTradesCumProfit = Performance.AllTrades.TradesPerformance.Currency.CumProfit;
/* NOTE: Using .AllTrades will include both historical virtual trades as well as real-time trades.
If you want to only count profits from real-time trades please use .RealtimeTrades. */
}
/* Prevents further trading if the current session's realized profit exceeds DayTakeProfit or if realized losses exceed DayStopLoss.
Also prevent trading if 10 trades have already been made in this session. */
if (Performance.AllTrades.TradesPerformance.Currency.CumProfit - priorTradesCumProfit >= dayTakeProfit
|| Performance.AllTrades.TradesPerformance.Currency.CumProfit - priorTradesCumProfit <= -dayStopLoss
|| Performance.AllTrades.Count - priorTradesCount > 10)
{
/* TIP FOR EXPERIENCED CODERS: This only prevents trade logic in the context of the OnBarUpdate() method. If you are utilizing
other methods like OnOrderUpdate() or OnMarketData() you will need to insert this code segment there as well. */
// Returns out of the OnBarUpdate() method. This prevents any further evaluation of trade logic in the OnBarUpdate() method.
return;
}
// Condition set 1
if (Udobar(Udo_period).UpDown[0] > UdoB
&& Baspal(0.02, 0.2, 0.02).Plot0[0] > BasM
&& CrossAbove(BOP(8), Variable0, 1))
{
EnterLong(DefaultQuantity, "");
}
// Condition set 2
if (Udobar(Udo_period).UpDown[0] < UdoB
&& Baspal(0.02, 0.2, 0.02).Plot0[0] < BasM
&& CrossBelow(BOP(8), Variable0, 1))
{
EnterShort(DefaultQuantity, "");
}
}
#region Properties
[Description("")]
[GridCategory("Parameters")]
public double MACD_plus
{
get { return mACD_plus; }
set { mACD_plus = Math.Max(0.001, value); }
}
[Description("")]
[GridCategory("Parameters")]
public double BasB
{
get { return basB; }
set { basB = Math.Max(0.0100, value); }
}
[Description("")]
[GridCategory("Parameters")]
public int UdoB
{
get { return udoB; }
set { udoB = Math.Max(1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public int UdoM
{
get { return udoM; }
set { udoM = Math.Max(-200, value); }
}
[Description("")]
[GridCategory("Parameters")]
public int Udo_period
{
get { return udo_period; }
set { udo_period = Math.Max(1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public double BasM
{
get { return basM; }
set { basM = Math.Max(-1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public double MACD_minus
{
get { return mACD_minus; }
set { mACD_minus = Math.Max(-0.1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public int StopProfit
{
get { return stopProfit; }
set { stopProfit = Math.Max(1, value); }
}
[Description("Default setting for TimeStart")]
[GridCategory("Parameters")]
[Gui.Design.DisplayName("\t\t\t\t\t\t\t\t\t\t\t\tTimeStart1")]
public int TimeStart1
{
get { return timeStart1; }
set { timeStart1 = Math.Max(0, value); }
}
[Description("Default setting for TimeEnd")]
[GridCategory("Parameters")]
[Gui.Design.DisplayName("\t\t\t\t\t\t\t\t\t\t\tTimeEnd1")]
public int TimeEnd1
{
get { return timeEnd1; }
set { timeEnd1 = Math.Max(0, value); }
}
[Description("Default setting for DayTakeProfit")]
[GridCategory("Parameters")]
public double DayTakeProfit
{
get { return dayTakeProfit; }
set { dayTakeProfit = Math.Max(1, value); }
}
[Description("Default setting for DayStopLoss")]
[GridCategory("Parameters")]
public double DayStopLoss
{
get { return dayStopLoss; }
set { dayStopLoss = Math.Max(1, value); }
}
#endregion
}
}
Dobavil DayStopLoss DayTakeProfit i vse ploho.
Kto vidit oshibku?