Question EA

 

Hallo,

Im trying to write an EA based on PSAR and MACD. if the PSAR gives a Sell Signal and the MACD is less than its signal line i want to place a Sell order.

When backtesting the EA doesnt open a Sell if the trade logic includes:

if(openorders==true)
if(PSAR_BAR1 < CLOSE_BAR1 && PSAR_BAR0 > CLOSE_BAR0 && MACD_BAR0 < MACDS_BAR0)
OrderSend(Symbol(),OP_SELL,0.1,Bid,3,1.5,0,"order",99,Green);

 

 But it does open a sell if the trade logic is:

if(openorders==true)
if(PSAR_BAR1 < CLOSE_BAR1 && PSAR_BAR0 > CLOSE_BAR0)
OrderSend(Symbol(),OP_SELL,0.1,Bid,3,1.5,0,"order",99,Green);

 

How is this possable. Could somebody thell me what i am doing wrong? I also tried to split the PSAR Signal and MACD Criteria with no result.

 

Please help 

 
renen: Could somebody thell me what i am doing wrong? 
What are Function return values ? How do I use them ? - MQL4 forum
 
renen:


Hi, apart from the way you write your code, are you sure the conditions are true and the order isn't sent ? (Assuming that the stop loss parameter " 1.5" is a typo) 

If you're a newbie , maybe it would help to organize a bit better or maybe monitor your conditions until sure all works ok.

What I mean is this :

bool cond1=false;
bool cond2=false;
bool cond3=false;


if(openorders==true)
   {
   cond1=PSAR_BAR1 < CLOSE_BAR1;
   cond2=PSAR_BAR0 > CLOSE_BAR0;
   cond3=MACD_BAR0 < MACDS_BAR0;
   if(cond1&&cond2&&cond3)
      {
      int ticket=OrderSend(Symbol(),OP_SELL,0.1,Bid,3,0,0,"order",99,Green);
      if(ticket<0)
         {
         Print("OrderSend()failed with error :  "+(string)GetLastError());
         }
      }
   }

 

Now, if you want to monitor the conditions, you will have to have those conditions as global not local variables, then you can use 

Comment("\n"+
        "Sell condition_1 is :  "+(string)cond1+"\n"+
        "Sell condition_2 is :  "+(string)cond2+"\n"+
        "Sell condition_3 is :  "+(string)cond3
        );

 or add to you existing comment.

Also , about trying to send the order with a " 1.5 " value for stop loss, You need to workout the stoploss and take profit properly.

Hope it makes sense.

Cheers 

 
renen:

Hallo,

How is this possable. Could somebody thell me what i am doing wrong? I also tried to split the PSAR Signal and MACD Criteria with no result.

Please help 

 
if(openorders==true)
if(PSAR_BAR1 < CLOSE_BAR1 && PSAR_BAR0 > CLOSE_BAR0 && MACD_BAR0 < MACDS_BAR0)
OrderSend(Symbol(),OP_SELL,0.1,Bid,3,1.5,0,"order",99,Green);

The highlighted part of condition is false when the rest of it is true.