I am trying out the following pending order code and see what happens.
Code: Select all
//Long
if (SendLong)
{
stype = " BuyStop ";
type = OP_BUYSTOP;
price = NormalizeDouble(iHigh(NULL, 240, 1) + (Buffer / factor), Digits);
if (!SendAlertNotTrade)
{
stop = CalculateStopLoss(OP_BUY, price);
take = CalculateTakeProfit(OP_BUY, price);
//Lot size calculated by risk
if (RiskPercent > 0) SendLots = CalculateLotSize(price, NormalizeDouble(stop + (HiddenPips / factor), Digits) );
type = OP_BUY;
}//if (!SendAlertNotTrade)
SendTrade = true;
}//if (SendLong)
//Short
if (SendShort)
{
stype = " SellStop ";
type = OP_SELLSTOP;
price = NormalizeDouble(iLow(NULL, 240, 1) - (Buffer / factor), Digits);
if (!SendAlertNotTrade)
{
stop = CalculateStopLoss(OP_SELL, price);
take = CalculateTakeProfit(OP_SELL, price);
//Lot size calculated by risk
if (RiskPercent > 0) SendLots = CalculateLotSize(price, NormalizeDouble(stop - (HiddenPips / factor), Digits) );
type = OP_SELL;
}//if (!SendAlertNotTrade)
SendTrade = true;
}//if (SendShort)
if (SendTrade)
{
if (!SendAlertNotTrade)
{
result = SendSingleTrade(Symbol(), type, TradeComment, SendLots, price, stop, take);
if (result)
{
if (EmailTradeNotification) SendMail("Trade sent ", Symbol() + stype + "trade at " + TimeToStr(TimeCurrent(), TIME_DATE|TIME_MINUTES));
if (AlertPush) AlertNow(WindowExpertName() + " " + Symbol() + " " + stype + " " + DoubleToStr(price, Digits) );
OrderSelect(TicketNo, SELECT_BY_TICKET, MODE_TRADES);
CheckTpSlAreCorrect(type);
}//if (result)
}//if (!SendAlertNotTrade)
if (SendAlertNotTrade && !AlertSent)
{
Alert(WindowExpertName(), " ", Symbol(), " ", stype, "trade has triggered. ", TimeToStr(TimeLocal(), TIME_DATE|TIME_MINUTES|TIME_SECONDS) );
SendMail("Trade alert. ", Symbol() + " " + stype + " trade has triggered. " + TimeToStr(TimeLocal(), TIME_DATE|TIME_MINUTES|TIME_SECONDS ));
if (AlertPush) AlertNow(WindowExpertName() + " " + Symbol() + " " + stype + " " + DoubleToStr(price, Digits) );
AlertSent=true;
}//if (SendAlertNotTrade && !AlertSent)
}//if (SendTrade)
//Actions when trade send succeeds
if (SendTrade && result)
{
if (!SendAlertNotTrade && !CloseEnough(HiddenPips, 0) ) ReplaceMissingSlTpLines();
}//if (result)
//Actions when trade send fails
if (SendTrade && !result)
{
OldBarsTime = 0;
}//if (!result)
The same code has been used in some old ea's and theoretically should work.