Hi, please advice.
What is my EA has no magic number?
If I did not put magic number, order is not closed?
How can I fix it?
What is my EA has no magic number?
If I did not put magic number, order is not closed?
How can I fix it?
How to close trade in Metatrader after amount of time or bars 30 replies
Default How to close trade in Metatrader after amount of time or amount of bars 5 replies
TP dollars amount and SL dollars amount columns (MT4) 0 replies
MT4 How to set TP to close a certain amount instead of entire amount? 3 replies
How to find out the lowest close from a certain amount of time back? 0 replies
DislikedMay someone help me? I dont know why my ea bot does not close order that incur loss after 3 hours that I have programmed. May you look at my code and see what wrong? if(OrderType()==OP_BUYLIMIT) { if(((TimeCurrent()- OrderOpenTime()>= 10800)&&(OrderOpenPrice() >= Open[0]))||((Close[1]<Close[7])Ignored
#property copyright "Copyright © 2013, Marc (fxdaytrader)" #property link "http://forexBaron.net" extern bool FilterByMagicNumber = FALSE;//true:filter by magic number, false:ignore magic numbers extern bool CurrentPairOnly = FALSE;//true:current chart pair only, false:all pairs extern int MagicNumber = 0;//0:manual trades extern string tbslh="----Time based StopLoss----"; extern bool UseTimeBasedStopLoss = TRUE; extern string tsmh="1:days, 2:hours, 3:minuts, 4:bars"; extern int TimeBasedSLmode = 4;//mode - 1:days, 2:hours, 3:minuts, 4:bars extern double TimeBasedSLperiod = 5; string bth="true:Send 2 orders when in backtester"; bool Send2OrdersWhenBacktesting = FALSE; int init() { Comment("SimpleTimeBasedSL OrderManager EA, © 2013 Marc (fxdaytrader) *** http://ForexBaron.net"); if (IsTesting() && Send2OrdersWhenBacktesting) {//sends 2 orders when backtesting, nice to check if everything works as desired OrderSend(Symbol(),OP_BUY,MarketInfo(Symbol(),MODE_MINLOT),MarketInfo(Symbol(),MODE_ASK),5000,0,0,"TESTORDER BUY", MagicNumber,0,Blue); OrderSend(Symbol(),OP_SELL,MarketInfo(Symbol(),MODE_MINLOT),MarketInfo(Symbol(),MODE_BID),0500,0,0,"TESTORDER SELL", MagicNumber,0,Red); //OrderSend(Symbol(),OP_BUYSTOP,MarketInfo(Symbol(),MODE_MINLOT),MarketInfo(Symbol(),MODE_ASK)+350*Point,5000,0,0,"TESTORDER BUYSTOP", MagicNumber,0,Blue); //OrderSend(Symbol(),OP_SELLSTOP,MarketInfo(Symbol(),MODE_MINLOT),MarketInfo(Symbol(),MODE_BID)-350*Point,5000,0,0,"TESTORDER SELLSTOP", MagicNumber,0,Red); }//if (IsTesting() && SendOrdersAtStartAtBacktesting) { return(0); } int deinit() { Comment(""); return(0); } int start() { if (UseTimeBasedStopLoss) TimeBasedSL(Symbol(),MagicNumber,TimeBasedSLperiod,TimeBasedSLmode); /* if you would like to delete pending orders only, the call should be */ /* if (UseTimeBasedStopLoss) TimeBasedSL(Symbol(),MagicNumber,TimeBasedSLperiod,TimeBasedSLmode,OP_BUYSTOP); if (UseTimeBasedStopLoss) TimeBasedSL(Symbol(),MagicNumber,TimeBasedSLperiod,TimeBasedSLmode,OP_BUYLIMIT); if (UseTimeBasedStopLoss) TimeBasedSL(Symbol(),MagicNumber,TimeBasedSLperiod,TimeBasedSLmode,OP_SELLSTOP); if (UseTimeBasedStopLoss) TimeBasedSL(Symbol(),MagicNumber,TimeBasedSLperiod,TimeBasedSLmode,OP_SELLLIMIT); */ } //timebased SL-stuff, Marc (fxdaytrader) *** http://ForexBaron.net //mode - 1:days, 2:hours, 3:minuts, 4:bars //type - if not -1 only the specified ordertypes will be closed, for example if type=OP_BUY it will only close buy-orders, or if type=OP_BUYSTOP it will delete pending buystop orders (nice if you broker does not support pending order expiration times) void TimeBasedSL(string symbol,int magicnumber,double TimeBasedSLperiod,int mode=4,int type=-1) { bool result; if (TimeBasedSLmode>4 || TimeBasedSLmode<=0) { Print("TimeBasedSL(): *** ERROR - mode must be 1,2,3 or 4 ..."); return; }//simple errorchecking double TimeBasedSL=0.0; string smode="unknown"; if (mode==1) {smode="days"; TimeBasedSL = TimeBasedSLperiod * 86400;}//days if (mode==2) {smode="hours"; TimeBasedSL = TimeBasedSLperiod * 3600;}//hours if (mode==3) {smode="minutes"; TimeBasedSL = TimeBasedSLperiod * 60;}//minutes if (mode==4) {smode="bars"; TimeBasedSL = TimeBasedSLperiod * Period() * 60;}//bars for (int cnt=OrdersTotal()-1; cnt>=0; cnt--) { if (!OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)) continue; if (CurrentPairOnly && OrderSymbol()!=symbol) continue; if (FilterByMagicNumber && OrderMagicNumber()!=magicnumber) continue; if (type!=-1 && OrderType()!=type) continue; { if ((TimeCurrent() - OrderOpenTime()) >= TimeBasedSL) { while(IsTradeContextBusy()) Sleep(100); RefreshRates(); if (OrderType()==OP_BUY) {//buy result=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),9999,CLR_NONE); if (result) Print("TimeBasedSL(): **** BUY order ticket "+OrderTicket()+" (opentime: "+TimeToStr(OrderOpenTime())+") closed (timebased SL="+DoubleToStr(TimeBasedSLperiod,2)+" "+smode+")"); } if (OrderType()==OP_SELL) {//sell result=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),9999,CLR_NONE); if (result) Print("TimeBasedSL(): **** SELL order ticket "+OrderTicket()+" (opentime: "+TimeToStr(OrderOpenTime())+") closed (timebased SL="+DoubleToStr(TimeBasedSLperiod,2)+" "+smode+")"); } if (OrderType()>1 && OrderType()<6) {//pending orders result=OrderDelete(OrderTicket()); if (result) Print("TimeBasedSL(): **** Pending Order ticket "+OrderTicket()+" (opentime: "+TimeToStr(OrderOpenTime())+") deleted (timebased SL="+DoubleToStr(TimeBasedSLperiod,2)+" "+smode+")"); } }//if (TimeCurrent() - ... } }//for (int cnt=OrdersTotal()-1; cnt>=0; cnt--) { }