I'm sure the answer is already there somewhere but despite looking for hours and trying several things I was not able to do it. So I hope one of you can be so kind to help this rookie. Thanks in advance!:
I run below code on the 1 minute data. The problem is that once the buy/sell conditions are met for as example 15 bars after each other, I receive 15 emails while I would like to receive only one email. Basically my question is how can I make sure that if the order that is placed during the current bar update, is equal to the open order, I do not receive an email. Or even better not a new order is placed at all.
Using the EntryOrderBuy.StopPrice function seems to not work when the code starts running and there's no order placed yet. if (EntryOrderBuy.StopPrice || EntryOrderBuy = null) also doesn't work as it also fails when there's no order placed yet.
protected override void Initialize()
{
CalculateOnBarClose = true;
SetStopLoss( CalculationMode.Ticks, (profitPips * RiskReward));
SetProfitTarget( CalculationMode.Ticks, profitPips );
ExitOnClose = false;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
private IOrder EntryOrderBuy = null;
private IOrder EntryOrderSell = null;
protected override void OnBarUpdate()
{
//CALCS
double HighOverPeriod = MAX(High, timeBack)[0];
double LowOverPeriod = MIN(Low, timeBack)[0];
double EntryPriceBuy = (Math.Floor(HighOverPeriod / RoundingOn)) * RoundingOn;
double EntryPriceSell = (Math.Ceiling(LowOverPeriod / RoundingOn)) * RoundingOn;
//BUY CONDITION
if (Math.Abs(HighOverPeriod - EntryPriceBuy) < DiffRoundedAndReal)
{
if (Math.Abs(EntryPriceBuy - Close[0]) > DiffEntryAndClose)
{
string MailBody = ("Buy " + EntryPriceBuy);
SendMail("[email protected]", "[email protected]", Instrument.FullName, MailBody);
EntryOrderBuy = EnterLongStop(0, true, 10000, EntryPriceBuy, "BuyStop");
}
}
//SELL CONDITION
if (Math.Abs(LowOverPeriod - EntryPriceSell) < DiffRoundedAndReal)
{
if (Math.Abs(EntryPriceSell - Close[0]) > DiffEntryAndClose)
{
string MailBody = ("Sell " + EntryPriceSell);
SendMail("[email protected]", "[email protected]", Instrument.FullName, MailBody);
EntryOrderSell = EnterShortStop(0, true, 10000, EntryPriceSell, "SellStop");
}
}
}

Comment