I have a grid order EA with code. I need EA to close pending orders after 5 minutes. So if orders with magic number 1 open at 00:00, pending orders with magic number 1 are delete at 00:005
See code below
//+------------------------------------------------------------------+
//--External variables
extern int MagicNumber = 1;//Magic number
extern string EaComment = "Grid_Template";//Order comment
extern double StaticLot = 0.01;//Static lots size
extern bool MM = false;//Money Management
extern int Risk = 2;//Risk %
extern double TakeProfit = 20.;//Take Profit in pips
extern double StopLoss = 10.;//Stop loss in pips
extern double PriceDistance = 15.;//Distance from price in pips
extern double GridStep = 15.;//Step between grid orders in pips
extern int GridOrders = 2;//Amount of grid orders
extern int PendingExpiration = 15;//Pending expiration after xx minutes
//--Internal variables
double PriceB,PriceS,StopB,StopS,
TakeB,TakeS,_points,PT,Lots;
int LotDigits;
datetime _e = 0;
int Ticket = 0;
//--
int OnInit()
{
//--Determine digits
_points=MarketInfo(Symbol(),MODE_POINT);
//--
if(Digits==5 || Digits==3)
PT = _points*10;
else
PT = _points;
//--
return(INIT_SUCCEEDED);
}
//--
void OnDeinit(const int reason)
{
}
//--
void OnTick()
{
//If trade allowed and no positions exists by any chart - open a new set of grid orders
if(IsTradeAllowed() && !IsTradeContextBusy())
{
if(PosSelect()==0)
{
GridPos(PriceDistance,TakeProfit,StopLoss);//Place grid
}
return;
}
}
///////////////////////////////////////////////////////////
//Grid order send function
void GridPos(double _Dist,double _Take,double _Stop)
{
int i;
_e=TimeCurrent()+PendingExpiration*60;
//--
for(i=0; i<GridOrders; i++)
{
PriceB = NormalizeDouble(Ask+(_Dist*PT)+(i*GridStep*PT),Digits);
TakeB = PriceB + _Take * PT;
StopB = PriceB - _Stop * PT;
Ticket=OrderSend(Symbol(),OP_BUYSTOP,LotSize(),PriceB,3,StopB,TakeB,EaComment,MagicNumber,_e,Green);
//--
PriceS = NormalizeDouble(Bid-(_Dist*PT)-(i*GridStep*PT),Digits);
TakeS = PriceS - _Take * PT;
StopS = PriceS + _Stop * PT;
Ticket=OrderSend(Symbol(),OP_SELLSTOP,LotSize(),PriceS,3,StopS,TakeS,EaComment,MagicNumber,_e,Red);
}
if(Ticket<1)
{
Print("Order send error - errcode: ",GetLastError());
return;
}
else
{
Print("Grid placed successfully!");
}
return;
}
//////////////////////////////////////////////////////////
//PositionSelector - Determines open positions
int PosSelect()
{
int posi=0;
for(int k = OrdersTotal() - 1; k >= 0; k--)
{
if(!OrderSelect(k, SELECT_BY_POS))
{
Print("Order pos selection failed - errcode: ",GetLastError());
}
if(OrderSymbol()!=Symbol()&&OrderMagicNumber()!=MagicNumber)
{
continue;
}
if(OrderCloseTime() == 0 && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
{
if(OrderType() == OP_BUY)
posi = 1; //Long position
if(OrderType() == OP_SELL)
posi = -1; //Short positon
if(OrderType() == OP_BUYSTOP)
posi = 1; //Pending Long position
if(OrderType() == OP_SELLSTOP)
posi = -1; //Pending Short positon
}
}
return(posi);
}
////////////////////////////////////////////////////////////
//Lots size calculation
double LotSize()
{
if(MM == true)
{ Lots = MathMin(MathMax((MathRound((AccountFreeMargin()*Risk/1000/100)
/MarketInfo(Symbol(),MODE_LOTSTEP))*MarketInfo(Symbol(),MODE_LOTSTEP)),
MarketInfo(Symbol(),MODE_MINLOT)),MarketInfo(Symbol(),MODE_MAXLOT));}
else
{
Lots = MathMin(MathMax((MathRound(StaticLot/MarketInfo(Symbol(),MODE_LOTSTEP))*MarketInfo(Symbol(),MODE_LOTSTEP)),
MarketInfo(Symbol(),MODE_MINLOT)),MarketInfo(Symbol(),MODE_MAXLOT));
}
return(Lots);
}
//+----------------End of Temi's Trader EA-------------------+
Ähnliche Aufträge
i need a free auto-trading robot for indices on meta trader 5.(dow jones, nasdaq, sp500, ger40, euro50, etc.) my capital is 100 usd.Please suggest free and succesful robots for my mt5 account
I have an existing MT5 Expert Advisor that has already been developed and debugged. I am looking for an experienced MQL5 EA developer with strong strategy-analysis, backtesting and optimization experience to review and improve the existing system. This is not simply a coding job. I am specifically looking for someone who can analyze an existing EA and independently identify weaknesses in its trading logic, rather
I want a robot that will monitor the h4 time frame. wait for 10ema to cross below or above 50 ema. look for candles to touch the 10 ema, wait for a break of structure and a reversal to the neckline. the robot must send me notification when the reversal touches the neckline and give visual indication on the chart
Hello, I have an existing XAUUSD market-analysis system called I am looking for an experienced MQL5 developer to perform a technical review and prepare a precise architecture for rebuilding the existing SIGNAL ENGINE / ANALYSIS LOGIC in MQL5. IMPORTANT: This request is ONLY about the signal-analysis engine. I am NOT requesting an Expert Advisor (EA), automated trading system, order execution, or live trading
Hi, I'm looking for an experienced MQL5 developer to build a profitable Expert Advisor for MetaTrader 5. The goal is to get the highest possible return from a small account while keeping the account alive. ACCOUNT - Broker: IC Markets (EU, regulated), MT5, hedging account - Leverage: 1:30 - Deposit: 200 USD - Instruments: Forex and/or XAUUSD, your choice. Please check that the margin for the minimum lot size is
I need a professional MT5 Expert Advisor for multi-symbol trade monitoring and risk management. The EA should focus on trade management rather than generating trading signals. Requirements: Platform: MetaTrader 5 / MQL5 Monitor all open positions on the account Multi-symbol support Display a dashboard showing: Symbol Buy/Sell direction Lot size Entry price Current profit/loss Stop Loss Take Profit Configurable
Hi, I’m looking for an experienced MQL5/MT5 developer to build a complex AI-powered adaptive Expert Advisor for XAUUSD+ on Ultima Markets. I have a detailed 28-section technical specification, and the requirements are fixed. I’m looking for the complete implementation , not a simplified EA or a conventional indicator-based system. The project includes: Genuine AI/ML integration AI-based market regime classification
This may be a weird request but if anyone has an EA that is actually consistently profitable I want to buy a copy from you. Ideally trades a lot, I'm sure theres a coder out there who has made a profitable EA, I want to backtest if you have, I have been trying to code a few on my own with no success as I'm not yet good at coding, lets see what ya got.thanks
I need a simple MetaTrader 5 Expert Advisor based on a MACD crossover. Requirements: Platform: MetaTrader 5 / MQL5 Buy when the MACD main line crosses above the signal line Sell when the MACD main line crosses below the signal line Use completed candles only MACD parameters configurable Fixed lot size configurable Stop Loss configurable Take Profit configurable Maximum one open position per symbol Configurable Magic
I need a simple MT5 Expert Advisor based on Bollinger Bands. Requirements: Platform: MetaTrader 5 / MQL5 Buy when price closes below the lower Bollinger Band Sell when price closes above the upper Bollinger Band Bollinger period configurable, default 20 Deviation configurable, default 2.0 Fixed lot size configurable Stop Loss configurable Take Profit configurable Maximum one open position per symbol Use completed