Close an Open Position if Hit certain price

 

i'd like to make my EA to close a position if any of these conditions were met :

   -profit on the position is 100 points 

   -price hit RSI 30 OR 70 depending if it's a Sell or buy 

Here's my code but for some reason it doesn't work !! 

Also i'm not quite sure whether "PositionGetDouble " return profit value in points or dollar value ?!

 double tp = PositionGetDouble (POSITION_PROFIT);       

        // rsi_0 is the RSI value for the current candle


    if ( (trade.RequestType() == ORDER_TYPE_BUY) && ((rsi_0  >70 ) || (tp > 100) )  )

     trade.PositionClose(_Symbol);



    if ( (trade.RequestType() == ORDER_TYPE_SELL) && (( rsi_0 < 30) || (tp > 100) ) )

     trade.PositionClose(_Symbol);

 
 
andrw11: i'd like to make …

  1. You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your problem.
              No free help 2017.04.21
  2. When the market exceeds your 100 points, close the order. Or set the TP to 100 points above the open price and it will close itself.
  3. RSI is an indicator. Price can not hit an indicator. If the RSI goes below 30 or above 70, then you close the order.
  4. Your posted code has nothing to do with your wants.
 
William Roeder:
  1. You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your problem.
              No free help 2017.04.21
  2. When the market exceeds your 100 points, close the order. Or set the TP to 100 points above the open price and it will close itself.
  3. RSI is an indicator. Price can not hit an indicator. If the RSI goes below 30 or above 70, then you close the order.
  4. Your posted code has nothing to do with your wants.

Thanks for your comment , and sorry the attached code was misleading , i have updated it 

the problem is that code isn't doing what it supposes to do 

i don't want to just close order once hit 100 points , it should look if EITHER of conditions were met , whichever happens first , then close it .

 
Any help !
 

Perhaps you should read the manual.
How To Ask Questions The Smart Way. 2004
     How To Interpret Answers.
          RTFM and STFW: How To Tell You've Seriously Screwed Up.

You keep saying 100 points. That is not what POSITION_PROFIT returns.

You keep using rsi_0 but never show the definition and the update. There are no mind readers here.

You use PositionGetDouble but never show where you select a position. There are no mind readers here. Post all relevant code.

 
William Roeder:

Perhaps you should read the manual.
How To Ask Questions The Smart Way. 2004
     How To Interpret Answers.
          RTFM and STFW: How To Tell You've Seriously Screwed Up.

You keep saying 100 points. That is not what POSITION_PROFIT returns.

You keep using rsi_0 but never show the definition and the update. There are no mind readers here.

You use PositionGetDouble but never show where you select a position. There are no mind readers here. Post all relevant code.

i don't know if POSITION_PROFIT return profit in points or dollar value !! that's why i asked that above . it's not clear in the documentation

i have commented in code above also that rsi_0 is the RSI value of the current candle (candle 0 ) !!

maybe i'm using the function the wrong way but code complies fine , so please correct me the function or the way i should use it .

 
andrw11:

i'd like to make my EA to close a position if any of these conditions were met :

   -profit on the position is 100 points 

   -price hit RSI 30 OR 70 depending if it's a Sell or buy 

Here's my code but for some reason it doesn't work !! 

Also i'm not quite sure whether "PositionGetDouble " return profit value in points or dollar value ?!

Hi andrw11,


Have you managed to find out what the solution is to close an open position at a specific RSI value?

I also tried writing code, however, it doesn't read the RSI value after it has placed a trade.