EA opens SELL orders but no BUY orders

Back to topics list To post a new topic, please log in or register
avatar
3
onefai 2016.05.29 03:40
 

Hello everybody,

I've been trying to make my very first self-made EA, but I've been failing to get it to open BUY orders. It seems to open SELL orders just without a problem, and since the code for both OrderSend() are identical, I can't grasp what is going wrong.

This is the relevant part of my code:

      total=OrdersTotal();
      
      
      if(total<1)
        {
        //--- no opened orders identified
        
        //--- check for long position (BUY) possibility
         if(Ask>senkouspan_a_one && Ask>senkouspan_b_one && Ask>senkouspan_a_two && Ask>senkouspan_b_two && Ask>PSAR_five && Ask>PSAR_fifteen && stochmain_five>stochsignal_five)
            {
            if((Time[0]-ordertime)>somelimit*60)  
               {
                 //execute my OrderSend function
                 ticket=OrderSend(Symbol(),OP_BUY,Lots,Bid,3,0,0," ",0,0,Green);
                  if(ticket>0)
                    {
                    if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
                     Print("BUY order opened : ",OrderOpenPrice());
                    }
                  else
                     Print("Error opening BUY order : ",GetLastError());
               ordertime = Time[0];
               }
            }
        //--- check for short position (SELL) possibility
         if(Ask<senkouspan_a_one && Ask<senkouspan_b_one && Ask<senkouspan_a_two && Ask<senkouspan_b_two && Ask<PSAR_five && Ask<PSAR_fifteen && stochmain_five<stochsignal_five)
           {
            if((Time[0]-ordertime)>somelimit*60)  
               {
                 //execute my OrderSend function
                 ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0," ",0,0,Red);
                  if(ticket>0)
                    {
                    if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
                     Print("SELL order opened : ",OrderOpenPrice());
                    }
                  else
                     Print("Error opening SELL order : ",GetLastError());
               ordertime = Time[0];
               }
           }
         //--- exit from block
         return;
        
        }

 

You can see that both if(...) have the same content, but switched relational operators... What am I doing wrong?

 

Thank you for taking your time to read all of this.

Regards,
onefai 

avatar
Moderator
3418
GumRai 2016.05.29 03:48 #
 

You don't tell us whether the EA tries to place orders and fails or whether no attempts to buy are made.

What does getlasterror() return?

A buy order is opened at Ask, not bid.

avatar
3
onefai 2016.05.29 03:56 #
 
GumRai:

You don't tell us whether the EA tries to place orders and fails or whether no attempts to buy are made.

What does getlasterror() return?

A buy order is opened at Ask, not bid.

Oh, sorry, I really didn't know about that haha. My code is basically snippets of other EAs and indicators.

getlasterror() returns:

2016.05.29 03:53:24.731 2016.05.27 22:50  IchiCloudScalp DAX30,M1: Error opening BUY order : 138

2016.05.29 03:53:24.731 2016.05.27 22:50  IchiCloudScalp DAX30,M1: OrderSend error 138

 

Thanks for the hint, I switched out those Asks and Bids simply for iOpen(NULL,0,0) now.


avatar
3
onefai 2016.05.29 03:59 #
 

Oh my goodness.. nevermind, now I understand what you meant. I just switched out the Bid in OrderSend with Ask, and it opened a BUY position. It works fine now.

Thank you! 

Back to topics list  

To add comments, please log in or register