I am trying to develop an indicator that does the following:
1 - If Price is > EMA20 && Price is > SMA5 --> DO NOTHING
2 - When I make an entry or I set an Order Entry and the Nr 1 conditions are FALSE, then Flatten my accounts (please be aware that the calculation has to be made untill an order is filled or submitted) and set a LogLevel.Alert (ONLY ONCE, I GET CURRENTLY A LOOP).
3 - If an order is filled and the Nr 1 conditions are true but the price goes below the EMA20 and SMA5 --> let the trade continue untill the stop loss is filled, do not flatten everything.
Regarding this, I have the following questions:
1 - Is there a way to see if an order has been filled/submitted and if so flatten everything when the conditions Nr 1 are met?
2 - How can I Flatten all accounts? Can I make an account selector in the indicator, so that the indicator only works in the selected account?
3 - How can I make the Alert only to show once? Now I am getting an annoying loop, I think that is because I did not set up the order filled/submitted detection...
Here the code:
public class TEACHER : Indicator
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "TEACHER";
Calculate = Calculate.OnEachTick;
IsOverlay = false;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
//Disable this property if your indicator requires custom values that cumulate with each new market data event.
//See Help Guide for additional information.
IsSuspendedWhileInactive = true;
ArePlotsConfigurable = false;
}
else if (State == State.Configure)
{
}
}
protected override void OnBarUpdate()
{
if (State == State.Historical)
return;
if ((Close[0] > EMA(Close, 20)[0])
&& (Close[0] > SMA(Close, 5)[0]))
{
return;
}
else
{
Account myAccount = Account.All.FirstOrDefault(a => a.Name == "Playback101");
myAccount.Flatten(new [] { Instrument.GetInstrument(Instrument.ToString()) });
Log("YOU CAN'T TRADE HERE, PLEASE WAIT!!!", LogLevel.Alert);
}
}
}[B][U][/U][/B]
Thanks a lot for your help!!!!

Comment