Download MetaTrader 5
To add comments, please log in or register
No time to learn MQL5? The source code library is at your service!
Rene Noteborn
216
Rene Noteborn 2014.07.29 16:41 

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 

whroeder1
13644
whroeder1 2014.07.29 17:45  
renen: Could somebody thell me what i am doing wrong? 
What are Function return values ? How do I use them ? - MQL4 forum
Daniel Petrovai
440
Daniel Petrovai 2014.08.01 02:40  
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 

Ian Venner
2583
Ian Venner 2014.08.01 06:37  
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.

/
To add comments, please log in or register