I was able to code this but there seems to be an issue.
For the 5-minute chart conditioins, i need to have the last 2 candles plus the current 5-minute candle low to be >= the 5-minute sma.
For the 15-minute chart condition, I need to have at least the current candle low to be >= the 15-minute 5ma.
However, it will only trigger the long if all the 15-minute candle lows are >= the 15-minute sma within the whole condition of the 5-minute.
I need it to trigger as long as the current 15-minute low >= the 15-sma regardless if the previous 15-minute low is not greater than the previous 15-minute sma while it is still calculating the 5-minute condition.
This may sound confusing so I added some images. Hope this helps.
If anyone can help me restructure the code the right way for it to work, it would be greatly appreciated. I am stuck here already for days.
public class newplayaround : Strategy
{
private SMA SMA5;
private SMA SMA15;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Strategy here.";
Name = "newplayaround";
Calculate = Calculate.OnEachTick;
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 = false;
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;
AddPlot(Brushes.Orange, "PLOTA");
AddPlot(Brushes.Green, "PLOTB");
}
else if (State == State.Configure)
{
AddDataSeries(Data.BarsPeriodType.Minute, 15);
}
else if (State == State.DataLoaded)
{
SMA15 = SMA(BarsArray[1],5);
SMA5 = SMA(Close, 5);
}
}
protected override void OnBarUpdate()
{
if (CurrentBars[0] < 5 || CurrentBars[1] < 5)
return;
Values[0][0] = SMA15[0];
Values[1][0] = SMA5[0];
if ((Low[2] >= SMA5[2])
&& (Low[1] >= SMA5[1])
&& (Low[0] >= SMA5[0])
&& (High[0] > High[1])
&& (Lows[1][0] >= SMA(BarsArray[1], 5)[0]))
{
EnterLong(100,@"");
}
if (GetCurrentBid(0) < SMA5[0])
{
ExitLong(100,@"",@"");
}
}
}
}
Comment