- Use "SRC" button to format your source code in the post
- You are getting an error because your function is named "delete" which is MQL4 reserved word and thus cannot be used as function or variable name anymore. This change is introduced more than two years ago, so you have a pretty old code.
- Read the documentation and MQL4 book to get basic knowledge about MQL4 coding
-
Play videoPlease edit your post.
For large amounts of code, attach it. - Since build 600 and Higher - MQL4 Articles 17.02.2014 delete is a keyword. Object Delete Operator delete - Operators - Language Basics - MQL4 Reference You must rename your function and its calls.
Second there goes the code...
I have to place full code? or only the part containing the problem?, I ask because is an expert with old code (like you teach me), and I think it should be checked completely???.
And finally I started reading about MQL4 code.Again thank you very much!!!
void delete(int type){ if(OrdersTotal()>0){ for(i=OrdersTotal();i>=0;i--){ OrderSelect(i,SELECT_BY_POS,MODE_TRADES); if(type!=6 && type!=7 && type!=8)if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderType()==type)OrderDelete(OrderTicket()); if(type==6)if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderType()==OP_BUYSTOP || OrderType()==OP_SELLSTOP || OrderType()==OP_BUYLIMIT || OrderType()==OP_SELLLIMIT) OrderDelete(OrderTicket()); if(type==7)if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderType()==OP_BUYSTOP || OrderType()==OP_BUYLIMIT)OrderDelete(OrderTicket()); if(type==8)if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderType()==OP_SELLSTOP || OrderType()==OP_SELLLIMIT)OrderDelete(OrderTicket()); } } }
//+----------------------------------------------------------------------------+ //| Close functions | //+----------------------------------------------------------------------------+ void close(int type){ if(OrdersTotal()>0){ for(i=OrdersTotal()-1;i>=0;i--){ OrderSelect(i,SELECT_BY_POS,MODE_TRADES); if(type==3 || type==OP_BUY && OrderType()==OP_BUY){ if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && (oppositecloseminloss==0 || (oppositecloseminloss>0 && (OrderClosePrice()-OrderOpenPrice())<-1*oppositecloseminloss*pt))){ RefreshRates();OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),slippage*mt); } } if(type==3 || type==OP_SELL && OrderType()==OP_SELL){ if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && (oppositecloseminloss==0 || (oppositecloseminloss>0 && (OrderOpenPrice()-OrderClosePrice())<-1*oppositecloseminloss*pt))){ RefreshRates();OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,Digits),slippage*mt); } } } } } void partialclose(int type,int mode,double lot,double takeprofit){ if(OrdersTotal()>0){ for(i=OrdersTotal()-1;i>=0;i--){ OrderSelect(i,SELECT_BY_POS,MODE_TRADES); if(type==3 || type==OP_BUY && OrderType()==OP_BUY){ if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderLots()>=lot && (mode==0 && OrderClosePrice()-OrderOpenPrice()>=takeprofit*pt) || mode==1){ RefreshRates();OrderClose(OrderTicket(),NormalizeDouble(lot,lotdigits),NormalizeDouble(Bid,Digits),slippage*mt); } } if(type==3 || type==OP_SELL && OrderType()==OP_SELL){ if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderLots()>=lot && (mode==0 && OrderOpenPrice()-OrderClosePrice()>=takeprofit*pt) || mode==1){ RefreshRates();OrderClose(OrderTicket(),NormalizeDouble(lot,lotdigits),NormalizeDouble(Ask,Digits),slippage*mt); } } } } } void hideclose(){ if(OrdersTotal()>0){ for(i=OrdersTotal()-1;i>=0;i--){ OrderSelect(i,SELECT_BY_POS,MODE_TRADES); if(OrderType()==OP_BUY){ if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && (hidesl && stoploss>0 && NormalizeDouble(OrderClosePrice()-OrderOpenPrice(),Digits)<=(-1)*stoploss*pt-MarketInfo(Symbol(),MODE_SPREAD)*pt) || (hidetp && takeprofit>0 && NormalizeDouble(OrderClosePrice()-OrderOpenPrice(),Digits)>=takeprofit*pt)){ RefreshRates();OrderClose(OrderTicket(),OrderLots(),Bid,slippage*mt); } } if(OrderType()==OP_SELL){ if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && (hidesl && stoploss>0 && NormalizeDouble(OrderOpenPrice()-OrderClosePrice(),Digits)<=(-1)*stoploss*pt-MarketInfo(Symbol(),MODE_SPREAD)*pt) || (hidetp && takeprofit>0 && NormalizeDouble(OrderOpenPrice()-OrderClosePrice(),Digits)>=takeprofit*pt)){ RefreshRates();OrderClose(OrderTicket(),OrderLots(),Ask,slippage*mt); } } } } } void closetime(int mode,double target,double timeout1,double timeout2){ tradeprofit=0; tradetime=0; if(OrdersTotal()>0){ for(i=OrdersTotal();i>=0;i--){ OrderSelect(i,SELECT_BY_POS,MODE_TRADES); if(OrderType()==OP_BUY){ if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic){ tradeprofit=NormalizeDouble(OrderClosePrice()-OrderOpenPrice(),Digits); tradetime=TimeCurrent()-OrderOpenTime(); if((mode==0 && tradeprofit>=target*pt && tradetime>timeout1*60 && tradetime<timeout2*60) || (mode==1 && tradeprofit>=target*pt && tradetime>timeout1*60)){ RefreshRates();OrderClose(OrderTicket(),OrderLots(),Bid,slippage*mt); } } } if(OrderType()==OP_SELL){ if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic){ tradeprofit=NormalizeDouble(OrderOpenPrice()-OrderClosePrice(),Digits); tradetime=TimeCurrent()-OrderOpenTime(); if((mode==0 && tradeprofit>=target*pt && tradetime>timeout1*60 && tradetime<timeout2*60) || (mode==1 && tradeprofit>=target*pt && tradetime>timeout1*60)){ RefreshRates();OrderClose(OrderTicket(),OrderLots(),Ask,slippage*mt); } } } } } } void delete(int type){ if(OrdersTotal()>0){ for(i=OrdersTotal();i>=0;i--){ OrderSelect(i,SELECT_BY_POS,MODE_TRADES); if(type!=6 && type!=7 && type!=8)if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderType()==type)OrderDelete(OrderTicket()); if(type==6)if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderType()==OP_BUYSTOP || OrderType()==OP_SELLSTOP || OrderType()==OP_BUYLIMIT || OrderType()==OP_SELLLIMIT) OrderDelete(OrderTicket()); if(type==7)if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderType()==OP_BUYSTOP || OrderType()==OP_BUYLIMIT)OrderDelete(OrderTicket()); if(type==8)if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderType()==OP_SELLSTOP || OrderType()==OP_SELLLIMIT)OrderDelete(OrderTicket()); } } } //+----------------------------------------------------------------------------+ //| Modifications functions | //+----------------------------------------------------------------------------+ void movebreakeven(double breakevengain,double breakeven){ RefreshRates(); if(OrdersTotal()>0){ for(i=OrdersTotal();i>=0;i--){ OrderSelect(i,SELECT_BY_POS,MODE_TRADES); if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==magic){ if(OrderType()==OP_BUY){ if(NormalizeDouble((Bid-OrderOpenPrice()),Digits)>=NormalizeDouble(breakevengain*pt,Digits)){ if((NormalizeDouble((OrderStopLoss()-OrderOpenPrice()),Digits)<NormalizeDouble(breakeven*pt,Digits)) || OrderStopLoss()==0){ OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()+breakeven*pt,Digits),OrderTakeProfit(),0,Blue); return(0); } } } else{ if(NormalizeDouble((OrderOpenPrice()-Ask),Digits)>=NormalizeDouble(breakevengain*pt,Digits)){ if((NormalizeDouble((OrderOpenPrice()-OrderStopLoss()),Digits)<NormalizeDouble(breakeven*pt,Digits)) || OrderStopLoss()==0){ OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()-breakeven*pt,Digits),OrderTakeProfit(),0,Red); return(0); } } } } } } } void movetrailingstop(int mode,double trailingstart,double trailingstop){ RefreshRates(); if(OrdersTotal()>0){ for(i=OrdersTotal();i>=0;i--){ OrderSelect(i,SELECT_BY_POS,MODE_TRADES); if(mode==0){ if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==magic){ if(OrderType()==OP_BUY){ if(NormalizeDouble(Ask,Digits)>NormalizeDouble(OrderOpenPrice()+trailingstart*pt,Digits) && NormalizeDouble(OrderStopLoss(),Digits)<NormalizeDouble(Bid-(trailingstop+trailingstep)*pt,Digits)){ OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-trailingstop*pt,Digits),OrderTakeProfit(),0,Blue); return(0); } } else{ if(NormalizeDouble(Bid,Digits)<NormalizeDouble(OrderOpenPrice()-trailingstart*pt,Digits) && (NormalizeDouble(OrderStopLoss(),Digits)>(NormalizeDouble(Ask+(trailingstop+trailingstep)*pt,Digits))) || (OrderStopLoss()==0)){ OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+trailingstop*pt,Digits),OrderTakeProfit(),0,Red); return(0); } } } } if(mode==1){ if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==magic){ if(OrderType()==OP_BUY && OrderStopLoss()==0){ if(NormalizeDouble(Ask,Digits)>=NormalizeDouble(OrderOpenPrice()+trailingstart*pt,Digits)){ OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask-trailingstop*pt,Digits),OrderTakeProfit(),0,Blue); return(0); } } if(OrderType()==OP_BUY && OrderStopLoss()!=0){ if(NormalizeDouble(Ask,Digits)>=NormalizeDouble(OrderOpenPrice()+trailingstart*pt,Digits) && NormalizeDouble(Ask,Digits)>=NormalizeDouble(OrderStopLoss()+trailingstart*pt,Digits)){ OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderStopLoss()+trailingstop*pt,Digits),OrderTakeProfit(),0,Blue); return(0); } } if(OrderType()==OP_SELL && OrderStopLoss()==0){ if(NormalizeDouble(Bid,Digits)<=NormalizeDouble(OrderOpenPrice()-trailingstart*pt,Digits)){ OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid+trailingstop*pt,Digits),OrderTakeProfit(),0,Red); return(0); } } if(OrderType()==OP_SELL && OrderStopLoss()!=0){ if(NormalizeDouble(Bid,Digits)<=NormalizeDouble(OrderOpenPrice()-trailingstart*pt,Digits) && NormalizeDouble(Bid,Digits)<=NormalizeDouble(OrderStopLoss()-trailingstart*pt,Digits)){ OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderStopLoss()-trailingstop*pt,Digits),OrderTakeProfit(),0,Red); return(0); } } } } } } } void movetrailingprofit(double trailingstart,double trailingprofit){ RefreshRates(); for(i=OrdersTotal();i>=0;i--){ if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)){ if(OrderSymbol()==Symbol()&& OrderMagicNumber()==magic){ if(OrderType()==OP_BUY){ if(NormalizeDouble(Bid-OrderOpenPrice(),Digits)<=NormalizeDouble((-1)*trailingstart*pt,Digits)){ if(NormalizeDouble(OrderTakeProfit(),Digits)>NormalizeDouble(Bid+(trailingprofit+trailingstep)*pt,Digits) || NormalizeDouble(OrderTakeProfit(),Digits)==0){ OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),NormalizeDouble(Bid+trailingprofit*pt,Digits),0,Blue); } } } if(OrderType()==OP_SELL){ if(NormalizeDouble(OrderOpenPrice()-Ask,Digits)<=NormalizeDouble((-1)*trailingstart*pt,Digits)){ if(NormalizeDouble(OrderTakeProfit(),Digits)<NormalizeDouble(Ask-(trailingprofit+trailingstep)*pt,Digits)){ OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),NormalizeDouble(Ask-trailingprofit*pt,Digits),0,Red); } } } } } } }
You can avoid repetition in your code (and also shorten lines) by checking ( OrderSymbol()==Symbol() && OrderMagicNumber()==magic) after the OrderSelect(). Makes the code easier to read.
You should check if the delete is successful or not.
Do not double post - I have removed your other duplicated post.
void delete_pendings(int type) { if(OrdersTotal()>0) { for(i=OrdersTotal()-1;i>=0;i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderSymbol()==Symbol() && OrderMagicNumber()==magic) { if(type!=6 && type!=7 && type!=8 && OrderType()==type) OrderDelete(OrderTicket()); if(type==6)if(OrderSymbol()==Symbol() || OrderType()==OP_SELLSTOP || OrderType()==OP_BUYLIMIT || OrderType()==OP_SELLLIMIT) OrderDelete(OrderTicket()); if(type==7 && (OrderType()==OP_BUYSTOP || OrderType()==OP_BUYLIMIT)) OrderDelete(OrderTicket()); if(type==8 && (OrderType()==OP_SELLSTOP || OrderType()==OP_SELLLIMIT)) OrderDelete(OrderTicket()); } } } }
EXCELLENT!!!! GumRai !!!
I have only to thank you for your excellent help, the expert could compile without errors / bugs.
Now I'm going to do back testing. And I'll tell if I run ok.Again thank you very much everyone (drazen64, WHRoeder, GumRai) for your support !!!
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
delete name expected
expressions are not alowed on a global scope
object pointer expected
Could you comment me how to fix ..
Thank you very much for your help