Coding an exit at Middle BB in MQL4

 

Hi guys,

I'm relatively new to building my own EA's and would appreciate some assistance coding a customized exit.

I would like to close both long and short positions at the middle BB.

Thanks in advance for your help!!

 
What have you tried ? Please show your attempt(s).
 
Alain Verleyen:
What have you tried ? Please show your attempt(s).


Hi Alain,

I have declared "tp" in the order entry section of my code and inserted it into the order modify line.

In the tester, it places the takeprofit at the middle bb value on the entry bar.


I want positions to exit when price >= middle BB (buy), inverse for sell.


This is what I have coded so far:


double tp=iBands(NULL,0,BollingerPeriod,BollingerDeviation,0,0,MODE_MAIN,1);


   int buyticket = OrderSend(Symbol(),OP_BUY,LotSize,Ask,3,0,0,NULL,MagicNumber,0,Green);

            if(buyticket>0)OrderModify(buyticket,OrderOpenPrice(),Ask-StopLoss,tp,0,CLR_NONE);


Cheers, Tim

 
timothysmith78: I want positions to exit...
int buyticket = OrderSend(Symbol(), OP_BUY, LotSize, Ask, 3, 0, 0, NULL, MagicNumber, 0, Green);
if(buyticket>0)
   OrderModify(buyticket, OrderOpenPrice(), Ask-StopLoss, tp, 0, CLR_NONE);
  1. Help you with what? You haven't stated a problem.

  2. Check your return codes for errors and report them. What are Function return values ? How do I use them ? - MQL4 forum
    Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles

  3. You can not use any Trade Functions until you select an order.

  4. Are you adjusting (SL, TP, and slippage; for 4/5 digit brokers and for JPY pairs?) points == pips? - Trading Systems - MQL5 programming forum - Page 5

 
whroeder1:
  1. Help you with what? You haven't stated a problem.

  2. Check your return codes for errors and report them. What are Function return values ? How do I use them ? - MQL4 forum
    Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles

  3. You can not use any Trade Functions until you select an order.

  4. Are you adjusting (SL, TP, and slippage; for 4/5 digit brokers and for JPY pairs?) points == pips? - Trading Systems - MQL5 programming forum - Page 5

Hi whroeder,

Thanks for the info, I simply want my open orders to exit when the Ask price is greater than the middle BB. How can I code this into an EA.

Sorry, I'm feeling a little lost. Can you please provide me with some code to help get me started.


Cheers, Tim 

Reason: