-
Why did you post your MT4
question in the
Root / MT5 EA section instead of the MQL4 section,
(bottom of the
Root page?)
General rules and best pratices of the Forum. - General - MQL5 programming forum
Next time post in the correct place. The moderators will likely move this thread there soon. -
OrderSend(Symbol(),OP_SELL, Lot,Bid,10,0,0,0,0,0,Red); OrderSend(Symbol(),OP_BUY, Lot,Ask,10, 0, 0, 0, 0, 0,Green); OrderSelect(i,SELECT_BY_POS,MODE_TRADES); OrderModify(OrderTicket(),OrderOpenPrice(),sl,tp,0,0); OrderModify(OrderTicket(),OrderOpenPrice(),sl,tp,0,0);
Check your return codes for errors, and report them including GLE/LE and your variable values. Don't look at GLE/LE unless you have an error. Don't just silence the compiler, it is trying to help you.
What are Function return values ? How do I use them ? - MQL4 programming forum
Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles - Use the debugger or print out your variables, including _LastError and find out why. Do you really expect us to debug your
code for you?
farzin:
i wrote an EA but this simple EA cannot take the position Please help me.
THANKS
Improved code....
//+------------------------------------------------------------------+ //| ProjectName | //| Copyright 2018, CompanyName | //| http://www.companyname.net | //+------------------------------------------------------------------+ #property copyright "Copyright 2018, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict extern double Lot = 0.01; extern int Stoploss = 10; extern int Takeprofit = 10; int NumBuy, NumSell,NumPenBuyStop, NumBuyLimit, NumSellStop, NumSellLimit,NumPenBuyLimit; double totalProfit, totalSellProfit, totalBuyProfit; datetime lastBuyTime, lastSellTime; double pt; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- pt= Point; if(Digits==3 || Digits==5) { pt=10*pt; } //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- Comment(""); //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- count(); bool OrdrSend=false; double rsi=0; tpsl(); rsi = iRSI(Symbol(), 0,14, PRICE_CLOSE,0); //--- if(NumBuy==0&&NumSell==0) { if(rsi >70) { OrdrSend=OrderSend(Symbol(),OP_SELL, Lot,Bid,10,0,0,"",0,0,Red); } if(rsi < 30) { OrdrSend=OrderSend(Symbol(),OP_BUY, Lot,Ask,10, 0, 0, "", 0, 0,Green); } } //--- string print = "\n\n\n\n\n "+ "\nnum buy: " + IntegerToString(NumBuy) + "\nnum Sell: " + IntegerToString(NumSell) + "\n total order profit: " + DoubleToStr(totalProfit,2) + "\n total buy profit :" +DoubleToStr(totalBuyProfit,2) + "\n total buy profit :" +DoubleToStr(totalSellProfit,2) + "\n RSI Price: " + DoubleToStr(rsi,2); Comment(print); } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void count() { NumBuy= 0; NumSell= 0; NumPenBuyLimit= 0; NumPenBuyStop= 0; NumSellLimit= 0; NumSellStop= 0; totalBuyProfit= 0; totalProfit= 0; totalSellProfit= 0; for(int i= OrdersTotal()-1; i>=0; i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) { if(OrderSymbol()==Symbol()) { if(OrderType()== OP_BUY) { NumBuy++; totalBuyProfit += OrderProfit()+ OrderSwap()+ OrderCommission(); } else if(OrderType()==OP_SELL) { NumSell++; totalSellProfit += OrderProfit()+ OrderSwap()+ OrderCommission(); } else if(OrderType()==OP_BUYSTOP) { NumPenBuyStop++; } else if(OrderType()==OP_BUYLIMIT) { NumPenBuyLimit++; } else if(OrderType()==OP_SELLSTOP) { NumSellStop++; } else if(OrderType()==OP_SELLLIMIT) { NumSellLimit++; } } } } totalProfit = totalBuyProfit+totalSellProfit; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void tpsl() { double tp=0; double sl=0; bool OrdrModify=false; for(int i=0; i<OrdersTotal(); i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) { if(OrderType() == OP_BUY) { tp=Ask+Takeprofit*pt; sl=Bid-Stoploss*pt; if(OrderStopLoss()==0 || OrderTakeProfit()==0) OrdrModify=OrderModify(OrderTicket(),OrderOpenPrice(),sl,tp,0,0); } if(OrderType() == OP_SELL) { tp=Bid-Takeprofit*pt; sl=Ask+Stoploss*pt; if(OrderStopLoss()==0 || OrderTakeProfit()==0) OrdrModify=OrderModify(OrderTicket(),OrderOpenPrice(),sl,tp,0,0); } } } } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
i wrote an EA but this simple EA cannot take the position Please help me.
THANKS