Close condition

 

Hi, I need help with to close an order by 2 condition in addition to SL,TP, TS.

int doWhat = _doNothing;
      double hull_trend_current  = iCustom(NULL,0,"StepMA pdf 4_6",PERIOD_CURRENT,"",PdfmaLength,SensivityFactor,ConstantStepSize,PdfmaVariance,PdfmaMean,PriceToUse,PdfmaFilter,9,BarToUse);
      double hull_trend_previous = iCustom(NULL,0,"StepMA pdf 4_6",PERIOD_CURRENT,"",PdfmaLength,SensivityFactor,ConstantStepSize,PdfmaVariance,PdfmaMean,PriceToUse,PdfmaFilter,9,BarToUse+1);
      double rsicurrent=iRSI(NULL,0,rsiu,PRICE_CLOSE,0);
      double rsiprevious=iRSI(NULL,0,rsiu,PRICE_CLOSE,1);
      
         if (hull_trend_current==1 && rsiprevious<lowerband&&rsicurrent>=lowerband)
               doWhat = _doBuy;
         
         if (hull_trend_current==-1 && rsiprevious>upperband&&rsicurrent<=upperband)
               doWhat = _doSell;
         
         if (doWhat==_doNothing && !DisplayInfo) return(0);
extern int rsiu = 14; // RSI period
extern int lowerband = 30; // RSI lowerband
extern int upperband = 70; // RSI upperband

 And the conditions should be:

If a buy order is open and StepMA PDF changes from up to down, the buy order should be closed.
If a buy order is open and RSI reaches 70 (upperband), the buy order should be closed.

And the opposite for sell:
If a sell order is open and StepMA PDF changes from down to up, the sell order should be closed.
If a sell order is open and RSI reaches 30 (lowerband), the sell order should be closed. 

How can I do that? I don't know so much about coding yet.
Please help. Thanks in advice!
All the best!
Simon 

 

Yoy can consider this section:  https://www.mql5.com/en/job  Regards.

Freelance service at MQL5.com
Freelance service at MQL5.com
  • www.mql5.com
Orders for the development of automated trading programs
Reason: