PSR as exit

 

How to code this think I am trying this for last one month I am not expert level I am on learning
If the PSAR trend is changed to positive to negative my Open buy positions will close and just opposite in case of sell

Do I need to use switch case or just I can do with if function 

 
Thank you in advance

 
The moment you try to code it, you will know the answer. Show us your attempt (using the CODE button) and state the nature of your problem.
          No free help 2017.04.21
 
algo_28:

How to code this think I am trying this for last one month I am not expert level I am on learning
If the PSAR trend is changed to positive to negative my Open buy positions will close and just opposite in case of sell

Do I need to use switch case or just I can do with if function 

 
Thank you in advance

Hi there...

well this is quite a simple task if you want your adviser to use signal to close positions and open new orders and you need to code your adviser to manage this together with the existing PSAR signal,it's like when you have one open buy position and a sell signal present, adviser needs to close the open buy and open up a new sell order.

How do you expect any help from us forum members on this if you don't post the relevant code and your own attempt to create this?

Post code using Alt+S

post_code

 
Kenneth Parling:

Hi there...

well this is quite a simple task if you want your adviser to use signal to close positions and open new orders and you need to code your adviser to manage this together with the existing PSAR signal,it's like when you have one open buy position and a sell signal present, adviser needs to close the open buy and open up a new sell order.

How do you expect any help from us forum members on this if you don't post the relevant code and your own attempt to create this?

Post code using Alt+S


    double Psr= iSAR(_Symbol,_Period,0.02,0.2,0);

         

         if(Psr<Bid)

         {

          Trend= "Bull";

         }  

         if(Psr>Ask)

         {

           Trend= "Bear";

         }  

// Take Profit 

  double TakeProfit_Buy = (Psr>Ask);

  double TakeProfit_Sell= (Psr<Bid);

      

   //Buy order

   

   if(signal=="Buy")

   OrderSend(_Symbol,OP_BUY,Lots,Ask,5,Low[2],TakeProft_Buy,NULL,0,0,Green);

   

   // Sell order

   if(signal=="Sell")

   OrderSend(_Symbol,OP_SELL,Lots,Bid,5,High[2],TakeProfit_Sell,NULL,0,0,Red); 

No such error in the code but profit booking not working as per Parabolic SAR all I am trying to do if I have buy open 
positions using PsAR trend and when pasr trend is change it need to close my buy position or booked profit 
 
  1. Why did you post your MT4 question in the Root / MT5 General 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.

  2.   double TakeProfit_Buy = (Psr>Ask);
    
    You assign a boolean to a double; bogus. TP/SL are prices.
  3. You would know why, if you had checked your return codes for errors, and reported them including GLE/LE, your variable values and the market.
              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
Reason: