Hello to all
Well once again I must turn to you gurus out there. I posted a problem earlier. The original code worked. Not just compiled. I attempted to add an additional stop. I can get the code to compile, but the second stop is not acknowledged. I will post the code once agaian. The SRC is not visible at this moment.
- A short code to add expiration date and time for expert
- Volume Question
- Fractal breakout EA. Need help with each fractal to be used only once?
The old post was named as 'Looking to close with 50 profit, help please.' I would repost the code but the SRC is not visible. Is there a problem at the MQL4 forum or is it my end.
OK Here is the old code which I was originally posted. Check the area that has the ?????????.
That is the problem.
void CheckForClose() { double ma0; ma0=iMA(NULL,0,8,0,MODE_SMA,PRICE_CLOSE,0); double ma1; ma1=iMA(NULL,0,10,0,MODE_SMA,PRICE_CLOSE,0); double LowerBB; LowerBB=iBands(NULL,0,30,1,0,PRICE_WEIGHTED,MODE_LOWER,0); double UpperBB; UpperBB=iBands(NULL,0,30,1,0,PRICE_WEIGHTED,MODE_UPPER,0); double TakeProfitBuy = OrderProfit (); TakeProfitBuy = 50; for(int i=0; i<OrdersTotal();i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break; if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue; //---- check order type if(OrderType()==OP_BUY) { // --------- The attempted code below is the problem. //?????????????????????????????????? if (OrderSelect(TakeProfitBuy,SELECT_BY_POS)==true) //?????????????????????????????????? OrderClose(OrderTicket(),OrderLots(),Bid,3,Red); //?????????????????????????????????? else // -------- The code below will work. But will NOT work if I add the code above. if (ma0 < ma1 && Close [0] < LowerBB && ma1 > LowerBB) OrderClose(OrderTicket(),OrderLots(), Bid,3,Red); break; } if(OrderType()==OP_SELL) { /* if (Close [0] < LowerBB)//( ma0 > ma1 && Close [0] > UpperBB && ma1 < UpperBB) OrderClose(OrderTicket(),OrderLots(),Ask,3,Blue); else*/ if (ma0>ma1 && Close [0] > UpperBB && ma1 < UpperBB) OrderClose(OrderTicket(),OrderLots(),Ask,3,Blue); break; } } //---- }
If the price of the buy order that is open increases 50 pips, I want the order to liquidate. And vice-versa with a sell order. I did attempt to use
if (OrderSelect (50,SELECT_BY_POS) == true). This additional condition was not acknowledged. Any help out there.
Thank you in advance.
void CheckForClose() { double ma0; ma0=iMA(NULL,0,8,0,MODE_SMA,PRICE_CLOSE,0); double ma1; ma1=iMA(NULL,0,10,0,MODE_SMA,PRICE_CLOSE,0); double LowerBB; LowerBB=iBands(NULL,0,30,1,0,PRICE_WEIGHTED,MODE_LOWER,0); double UpperBB; UpperBB=iBands(NULL,0,30,1,0,PRICE_WEIGHTED,MODE_UPPER,0); double TakeProfitBuy = OrderProfit (); //???? TakeProfitBuy = 50; for(int i=0; i<OrdersTotal();i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break; if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue; //---- check order type if(OrderType()==OP_BUY) { // --------- The attempted code below is the problem. //?????????????????????????????????? if (OrderSelect(TakeProfitBuy,SELECT_BY_POS)==true) //???could be if(OrderProfit()>TakeProfitBuy) OrderClose(OrderTicket(),OrderLots(),Bid,3,Red); //?????????????????????????????????? else // -------- The code below will work. But will NOT work if I add the code above. if (ma0 < ma1 && Close [0] < LowerBB && ma1 > LowerBB) OrderClose(OrderTicket(),OrderLots(), Bid,3,Red); break; } if(OrderType()==OP_SELL) { /* if (Close [0] < LowerBB)//( ma0 > ma1 && Close [0] > UpperBB && ma1 < UpperBB) OrderClose(OrderTicket(),OrderLots(),Ask,3,Blue); else*/ if (ma0>ma1 && Close [0] > UpperBB && ma1 < UpperBB) OrderClose(OrderTicket(),OrderLots(),Ask,3,Blue); break; } } //---- }
void CheckForClose() { int Profit = 50; if (Digits == 3 || Digits == 5) Profit = Profit*10; for(int i=0; i<OrdersTotal();i++) { OrderSelect(i,SELECT_BY_POS,MODE_TRADES); if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue; //---- check order type if(OrderType()==OP_BUY) { if(NormalizeDouble(OrderClosePrice() - OrderOpenPrice(),5) >= Profit*Point) { OrderClose(OrderTicket(),OrderLots(),Bid,3,Red); } } if(OrderType()==OP_SELL) { if(NormalizeDouble(OrderOpenPrice() - OrderClosePrice(),5) >= Profit*Point) { OrderClose(OrderTicket(),OrderLots(),Ask,3,Blue); } } } }
double UpperBB; UpperBB=iBands(NULL,0,30,1,0,PRICE_WEIGHTED,MODE_UPPER,0); double TakeProfitBuy = OrderProfit (); TakeProfitBuy = 50; for(int i=0; i<OrdersTotal();i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break; if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue; //---- check order type if(OrderType()==OP_BUY) { // --------- The attempted code below is the problem. //?????????????????????????????????? if (OrderSelect(TakeProfitBuy,SELECT_BY_POS)==true) //?????????????????????????????????? OrderClose(OrderTicket(),OrderLots(),Bid,3,Red); //??????????????????????????????????
- Simplify the code were ever possible
double UpperBB = iBands(NULL,0,30,1,0,PRICE_WEIGHTED,MODE_UPPER,0);
- You must order select BEFORE using OrderProfit
- You must count down when closeing or deleteing or in the presence of other EA - modifying
- You already selected the order Select(i... You can't select by profit
double TakeProfitBuy = 50; for(int i=OrdersTotal()-1; i>= 0; i--) if( OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderMagicNumber()==MAGICMA && OrderSymbol() -=Symbol()){ //---- check order type if(OrderType()==OP_BUY) { if (Bid-OrderOpenPrice() > TakeProfitBuy*pips2dbl) OrderClose(OrderTicket(),OrderLots(),Bid,3,Red); //?????????????????????????????????? ... } //++++ These are adjusted for 5 digit brokers. double pips2points, // slippage 3 pips 3=points 30=points pips2dbl; // Stoploss 15 pips 0.0015 0.00150 int Digits.pips; // DoubleToStr(dbl/pips2dbl, Digits.pips) int init(){ if (Digits == 5 || Digits == 3){ // Adjust for five (5) digit brokers. pips2dbl = Point*10; pips2points = 10; Digits.pips = 1; } else { pips2dbl = Point; pips2points = 1; Digits.pips = 0; } // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl

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