OrderSend() slippage parameter, in points or in pips? - page 5

 
Alain Verleyen #:
Well, I will stop to ask chunk of code one by one, MT4 requires a valid price for OrderSend() even on Market execution, you could have to use RefreshRates().

Ok, I'll look into that. I've only had trouble with opening an order this one time though, would RefreshRates() be something that might be useful specifically in volatile conditions?

For what it's worth, I'm working off of WHRoeder's entry EA. I've modified it to create orders when I get a breakout at bar open and reworked the GUI, but I've left all of the price calculation, order opening, and lot size calculation stuff alone.

https://www.mql5.com/en/forum/63949/page8#comment_27751788

 
rrsch #:

Ok, I'll look into that. I've only had trouble with opening an order this one time though, would RefreshRates() be something that might be useful specifically in volatile conditions?

Possibly, yes.

 
Alain Verleyen #:

Possibly, yes.

Oh, I see that RefreshRates() has already been included:

bool  OpenOrder(){
   RefreshRates();
   int slippage   = int( (Ask - Bid) * 2.0 / _Point);
   int ticket;
   int positionsRequired = 0;
   double lotSizePerPosition = 0;
   
   for(int i = 0; sandboxLotsize/maximumLot > i; i++)
   {
      positionsRequired = i + 1;  
   }
   
   lotSizePerPosition = normalize_lots(sandboxLotsize/positionsRequired);
   
   for(int i = 0; i < positionsRequired; i++)
   {
         ticket  = OrderSend(_Symbol, orderType, lotSizePerPosition, currentPrice, slippage, slLinePrice , tpPrice, "OGT", MagicNumber, 0, clrNONE);
         if(_LastError == 0) PlaySound("news.wav");
         else
         {
            Print("Open order error: " + errortext(GetLastError()));
            PlaySound("expert.wav");
         }   
      }     
   return true;
}

Any other options would be appreciated. I'd very much like to have my orders open in the future, even with some slippage!

 
rrsch #:

Oh, I see that RefreshRates() has already been included:

This is a wrong usage of RefreshRates() !

Once again : the price used in OrderSend() must be the LAST available price for the symbol, that means it must be set (Refreshed) just before OrderSend(), specially when used within a loop.

In your code :

1. where is set currentPrice ?

2. Where is it refreshed ?

OrderSend() can take time to executed, the ask/bid can change in the meantime.

 
Alain Verleyen #:

This is a wrong usage of RefreshRates() !

Once again : the price used in OrderSend() must be the LAST available price for the symbol, that means it must be set (Refreshed) just before OrderSend(), specially when used within a loop.

In your code :

1. where is set currentPrice ?

2. Where is it refreshed ?

OrderSend() can take time to executed, the ask/bid can change in the meantime.

currentPrice is implemented in a way I'm still chasing down. Your input is having me realize I may not need it at all, or at least in the way it's built in.

I changed the function so it's grabbing bid/ask and refreshing rates within the loop. How is this looking to you?

bool  OpenOrder(){
   int ticket;   
   int positionsRequired = 0;
   double lotSizePerPosition = 0;
   
   for(int i = 0; sandboxLotsize/maximumLot > i; i++) positionsRequired = i + 1;
   
   lotSizePerPosition = normalize_lots(sandboxLotsize/positionsRequired);
   
   if(!checkMaxSL()) return(false);
   
   checkMinSL();
   
   for(int i = 0; i < positionsRequired; i++)
   {
      RefreshRates();
      double op = direction == 1 ? Ask : Bid;
      int slippage   = int( (Ask - Bid) * 5 / _Point);

      ticket  = OrderSend(_Symbol, orderType, lotSizePerPosition, op, slippage, slLinePrice , tpPrice, "OGT", MagicNumber, 0, clrNONE);
      if(_LastError == 0) PlaySound("news.wav");
      else
      {
         Alert("Open order error: " + errortext(_LastError));
         Print("Open order error: " + errortext(GetLastError()));
         PlaySound("expert.wav");
         return false;
      }
   }
   return true;
}
 
rrsch #:

currentPrice is implemented in a way I'm still chasing down. Your input is having me realize I may not need it at all, or at least in the way it's built in.

I changed the function so it's grabbing bid/ask and refreshing rates within the loop. How is this looking to you?

It looks better. Keep us posted.
 
Alain Verleyen #:
It looks better. Keep us posted.

Will do, thank you so much for the help!

Reason: