Ask! - page 117

 

int start(){

if(TimeCurrent()>D'2008.07.01 12:00:00'){Comment("EXPIRED"); return(0);}

...

return(0);

}

amatrader:
Please can some tell me if it is possible to have a date limit in an EA, what I mean is can I set an expiry date in an EA that once it reaches the set date it just stops trading.

It would probably say something like this:-

check date, if date is equal to or grater than (set date) do nothing.

That's the english version, I need the MQL4 version...lol

Thanks if anyone can help.
 
amatrader:
Please can some tell me if it is possible to have a date limit in an EA, what I mean is can I set an expiry date in an EA that once it reaches the set date it just stops trading.

It would probably say something like this:-

check date, if date is equal to or grater than (set date) do nothing.

That's the english version, I need the MQL4 version...lol

Thanks if anyone can help.

Look at this thread https://www.mql5.com/en/forum/174194

 

Thank you sir... Much appreciated.

 

Weekly High Low.

Can anyone post a weekly High Low indicator like the attached for the daily?

Or maybe change the attached to a weekly for me please.

Thanks in advance.

Files:
 

Use this indicator https://www.mql5.com/en/forum/173574/page32 (it is daily, weekly and monthly).

Or this one https://www.mql5.com/en/forum/177792

Or this one https://www.mql5.com/en/forum/178698

 

Hello All

Here is the ea i am using. Can someone please tell me what to change in order to have a BUY-STOP and a SELL_Stop taken at the same time. The way it is now, either a buy-stop or a sell-stop is triggered. i'd like to have both. Secondly, what should i do to limit the number of orders for each candle.

I thank you all in advance.

here is the code:

void start() {

//---- check for history and trading

if(Bars<100 || IsTradeAllowed()==false) return;

co=CalculateCurrentOrders(Symbol());

CheckForSignals();

if (co>0) CheckForClose();

CheckForOpen();

co=CalculateCurrentOrders(Symbol());

if (mkt>0) {

BreakEvenStop(BreakEven,0);

double pcnt =( (AccountEquity()-AccountBalance()) / AccountBalance())*100;

Print("Account equity = ",AccountEquity());

Print("Account balance = ",AccountBalance());

if(pcnt>EquityGainPercent)

{

int total = OrdersTotal();

for(int i=total-1;i>=0;i--)

{

OrderSelect(i, SELECT_BY_POS);

int type = OrderType();

bool result = false;

switch(type)

{

//Close opened long positions

case OP_BUY : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );

break;

//Close opened short positions

case OP_SELL : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );

break;

//Close pending orders

case OP_BUYLIMIT :

case OP_BUYSTOP :

case OP_SELLLIMIT :

case OP_SELLSTOP : result = OrderDelete( OrderTicket() );

}

if(result == false)

{

Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() );

Sleep(3000);

}

}

Print("ALL ORDERS CLOSE-->Locked in on Profits");

}

return(0);

}

}

//+------------------------------------------------------------------+

//| Calculate open positions |

//+------------------------------------------------------------------+

int CalculateCurrentOrders(string symbol)

{

int ord; mkt=0;

//----

for(int i=0;i<OrdersTotal();i++) {

if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) continue;

if(OrderSymbol()==symbol && OrderMagicNumber()==MagicNumber) {

ord++;

if (OrderType()==OP_BUY || OrderType()==OP_SELL) mkt++;

}

}

//---- return orders volume

return(ord);

}

//+------------------------------------------------------------------+

//| Check for open order conditions |

//+------------------------------------------------------------------+

void CheckForSignals() {

//check long,short,exit signals

buysig=false;

sellsig=false;

closebuy=false;

closesell=false;

remorder=false;

int isins,isouts,iskeyrev,is2brev;

if (InsideBar) isins=IsInsideBar(shift);

if (OutSideBar) isouts=IsOutSideBar(shift);

if (KeyReversalBar) iskeyrev=IsKeyReversalBar(shift);

if (TwoBarReversal) is2brev=IsTwoBarReversal(shift);

//long entry signal condition

if (isins>0 || isouts>0 || iskeyrev>0 || is2brev>0) {

buysig=true;

closesell=true;

}

//short entry signal

if (isins<0 || isouts<0 || iskeyrev<0 || is2brev<0) {

buysig=false;

sellsig=true;

closebuy=true;

}

if (last>0 && (Time[0]-last)/(Period()*60)>=CancelOrderBars) {

remorder=true;

}

}

void CheckForOpen() {

int res,tr;

//---- sell conditions

co=CalculateCurrentOrders(Symbol());

if(sellsig && lastsig!=-1) {

co=CalculateCurrentOrders(Symbol());

if (co==0) {

res = OpenStop(OP_SELLSTOP,LotsRisk(StopLoss), Low[shift]-OrderPipsDiff*Point, StopLoss, TakeProfit1);

}

lastsig=-1;

last=Time[0];

return;

}

//---- buy conditions

if(buysig && lastsig!=1) {

co=CalculateCurrentOrders(Symbol());

if (co==0) {

res = OpenStop(OP_BUYSTOP,LotsRisk(StopLoss), High[shift]+OrderPipsDiff*Point, StopLoss, TakeProfit1);

}

last=Time[0];

lastsig=1;

return;

}

}

void BreakEvenStop(int BES, int BELP) {

//move stoploss to lock some profit

bool bres;

double StopLoss;

if ( BES > 2 ) {

for (int i = 0; i < OrdersTotal(); i++) {

if ( OrderSelect (i, SELECT_BY_POS) == false ) continue;

if ( OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber ) continue;

if ( OrderType() == OP_BUY ) {

if ( Bid < OrderOpenPrice()+BES*Point ) continue;

StopLoss = OrderOpenPrice()+BELP*Point;

if ( StopLoss > OrderStopLoss() ) {

bres=OrderModify (OrderTicket(), OrderOpenPrice(), StopLoss, OrderTakeProfit(), 0, White);

if (!bres) Print("Error Modifying BUY order : ",ErrorDescription(GetLastError()));

}

}

if ( OrderType() == OP_SELL ) {

if ( Ask > OrderOpenPrice()-BES*Point ) continue;

StopLoss = OrderOpenPrice()-BELP*Point;

if ( StopLoss < OrderStopLoss() ) {

bres=OrderModify (OrderTicket(), OrderOpenPrice(), StopLoss, OrderTakeProfit(), 0, Gold);

if (!bres) Print("Error Modifying SELL order : ",ErrorDescription(GetLastError()));

}

}

}

}

return;

}

int IsKeyReversalBar(int shift) {

//Key Reversal Bar, The open of the key bar should be at least ?pips higher than the high of the previous bar.

//The close of the key bar should be with in the high and close of the previous bar. The open of the current bar should be

//lower than the close of the key bar. A SellStop order should be place on the low of the key bar if it is not executed within

//the next 4 bars then cancel the order. See picture below - short!

if (Open[shift]=Low[shift+1] && Close[shift]Close[shift]) return(1);

if (Open[shift]>High[shift+1] && Close[shift]=Close[shift+1] && Open[shift-1]<Close[shift]) return(-1);

return(0);

}

int IsTwoBarReversal(int shift) {

//Two Bar Reversal, The open of the first bar should be near the low the previous bar and the close should be much lower and

//have a good size body. The open of the second bar should be very near the close of the first bar but both should be well below

//the midpoint of each bar with the close to be very near the low 2 bar previous. A BuyStop Order should be place at the high of

//the bar 1 if it is not executed within 4 bars cancel order. See picture below

if (MathAbs(Open[shift+1]-Close[shift+1])> MathAbs(Open[shift+1]-Low[shift+2])<=

MathAbs(Close[shift]-Low[shift+2])<=

MathAbs(Open[shift]-Close[shift+1]) &&

Close[shift+1]<(High[shift+1]+Low[shift+1])/2 &&

Open[shift]<(High[shift]+Low[shift])/2)

return(1);

if (MathAbs(Open[shift+1]-Close[shift+1])> MathAbs(Open[shift+1]-High[shift+2])<=

MathAbs(Close[shift]-Low[shift+2])<=

MathAbs(Open[shift]-Close[shift+1]) &&

Close[shift+1]>(High[shift+1]+Low[shift+1])/2 &&

Open[shift]>(High[shift]+Low[shift])/2)

return(-1);

return(0);

}

int OpenStop(int mode,double lot, double prc, int SL, int TP) {

int res,tr,col;

string mail;

double openprice,sl,tp,stlev;

tries=0;

stlev=(1+MarketInfo(Symbol(),MODE_STOPLEVEL))*Point;

while (res<=0 && tries<OrderTriesNumber) {

tr=0; while (tr<5 && !IsTradeAllowed()) { tr++; Sleep(2000); }

RefreshRates();

if (mode==OP_SELLSTOP) {

if (prc<=Bid-stlev) openprice=prc;

else openprice=Bid-stlev;

if (SL>0) sl=openprice+SL*Point;

if (TP>0) tp=openprice-TP*Point;

col=Red;

} else

if (mode==OP_BUYSTOP) {

if (prc>=Ask+stlev) openprice=prc;

else openprice=Ask+stlev;

if (SL>0) sl=openprice-SL*Point;

if (TP>0) tp=openprice+TP*Point;

col=Blue;

} else return;

Print(Ask," ",Bid," ",Symbol()," ",mode," ",lot," ",openprice," ",sl," ",tp," ");

res=OrderSend(Symbol(),mode,lot,openprice,slippage,sl,tp,EAName+"_"+MagicNumber,MagicNumber,0,col);

tries++;

}

if (res<=0) Print("Error opening pending order : ",ErrorDescription(GetLastError()));

return(res);

}

void CheckForClose() {

bool bres; int tr;

for(int i=0;i<OrdersTotal();i++) {

if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) continue;

if(OrderMagicNumber()!=MagicNumber || OrderSymbol()!=Symbol()) continue;

//---- check order type

if(OrderType()==OP_BUY && closebuy) {

bres=CloseAtMarket(OrderTicket(),OrderLots());

continue;

}

if(OrderType()==OP_SELL && closesell) {

bres=CloseAtMarket(OrderTicket(),OrderLots());

continue;

}

if(OrderType()==OP_BUYSTOP && (closebuy || remorder)) {

bres=DeletePending(OrderTicket());

continue;

}

if(OrderType()==OP_SELLSTOP && (closesell || remorder)) {

bres=DeletePending(OrderTicket());

continue;

}

}

}

bool DeletePending(int ticket) {

bool bres=false; int tr;

tries=0;

while (!bres && tries<OrderTriesNumber) {

bres=OrderDelete(ticket);

tries++;

tr=0; while (tr<5 && !IsTradeAllowed()) { tr++; Sleep(2000); }

}

if (!bres) Print("Error deleting order : ",ErrorDescription(GetLastError()));

return (bres);

}

 

Does anyone know the code to make an EA only work with a certain account number? Thanks!

 
 

You ave too many this one

}
 
newdigital:
It is here https://www.mql5.com/en/forum/174194 (post #7)

Thanks newdigital.

I have my initialization code (which has a time expiration in it) set up like such:

int init()

{if (TimeCurrent()>D'2008.06.07 12:00:00'){Comment("please renew your subscription"); return(0);}

return(0);

}

}

if (Account != AccountNumber()){

Comment("Trade on account :"+AccountNumber()+" FORBIDDEN!");

return(0);

}else {Comment("");}

And now I am returning this error:

'}' - unbalanced parentheses

What am I doing wrong here? Also, does "int Account = 111111;" go with the EA's setting? Thanks.