I am currently in the process of gaining experience with the wizard and the script.
Unfortunately, I'm not getting any further with a few points concerning the wizard.
I would like to build the following strategy.
there are 3 time frames i would like to use:
15 min with SMA 24
5 min with SMA 24 and SMA 8
2 min with SMA 6
my rules should be the following:
enter long when the most recent candle is closed above all sma.
enter short when the most recent candle closes below all sma.
additionally i would like to exit when the latest candle crosses the 2 min sma 6.
enter long or exit should only go from 2 min.
further rules:
i would like to calculate the size of open to close of the last 30 bars. i only want to go long or short if the most recent bar is 2x bigger than 20-3 bars and 4x bigger than the last 2 bars.
in addition, the close of the most recent bar should be 90% or more of the high (wick)
i have used last recent bars but that doesn't seem to work. not with the last 30 and not for every single bar. also an offset of 150% etc doesn't work the way i want it to.
how can i build this strategy and is it even possible to this extent?
public class strategie : Strategy
{
private SMA SMA1;
private SMA SMA2;
private SMA SMA3;
private SMA SMA4;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Geben Sie hier die Beschreibung für die neue benutzerdefinierte Strategie.";
Name = "strategie";
Calculate = Calculate.OnBarClose;
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;
IsExitOnSessionCloseStrategy = true;
ExitOnSessionCloseSeconds = 30;
IsFillLimitOnTouch = false;
MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
OrderFillResolution = OrderFillResolution.Standard;
Slippage = 0;
StartBehavior = StartBehavior.WaitUntilFlat;
TimeInForce = TimeInForce.Gtc;
TraceOrders = true;
RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
StopTargetHandling = StopTargetHandling.PerEntryExecution;
BarsRequiredToTrade = 20;
// Disable this property for performance gains in Strategy Analyzer optimizations
// See the Help Guide for additional information
IsInstantiatedOnEachOptimizationIteration = true;
Purple = 24;
Blue = 8;
Dotted = 6;
Green = 24;
}
else if (State == State.Configure)
{
AddDataSeries(Data.BarsPeriodType.Minute, 2);
AddDataSeries(Data.BarsPeriodType.Minute, 5);
AddDataSeries(Data.BarsPeriodType.Minute, 15);
}
else if (State == State.DataLoaded)
{
SMA1 = SMA(Closes[3], Convert.ToInt32(Green));
SMA2 = SMA(Closes[2], Convert.ToInt32(Purple));
SMA3 = SMA(Closes[2], Convert.ToInt32(Blue));
SMA4 = SMA(Closes[1], Convert.ToInt32(Dotted));
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 30
|| CurrentBars[1] < 1
|| CurrentBars[2] < 0
|| CurrentBars[3] < 0)
return;
// set 1
if ((Closes[1][0] > SMA1[0])
&& (Closes[1][0] > SMA2[0])
&& (Closes[1][0] > SMA3[0]))
{
}
// set 2
if ((Closes[1][0] < SMA1[0])
&& (Closes[1][0] < SMA2[0])
&& (Closes[1][0] < SMA3[0])
&& (Close[0] > (Close[30] * 1.5) ))
{
}
// set 3
if ((CrossAbove(Close, SMA4, 1))
|| (CrossBelow(Close, SMA4, 1)))
{
ExitLong(Convert.ToInt32(DefaultQuantity), "", "");
ExitShort(Convert.ToInt32(DefaultQuantity), "", "");
}
}
Comment