Script wont work with little price movement! HELP

 

Hi guys.

Im not a programer but i managed to do this script from several other scripts, so excuse me if something looks weird or nonesense.

I thought I had finally nailed to program a quick and helpful script for a hedging strategy. Although its not very trustworthy. When i go ahead and drag it into the mt4 chart sometimes it does work, mostly when prices are very still. But when they get a little movement i can only get the sell trade to open up but the buy trade wont succeed. I thought it was something related to slippage but even if I give it a value of 0 or 1000 it will still happen sometimes.

Do you know how on earth can i fix this? How can i have a trustful script out of this knowing that every time that I use it it will open up both trades as stablished?

Here I leave the script:

<SRC by Moderator>

#property show_inputs
 #include 
 #include 
 #property show_inputs

 // Script: 0-1-Buy 

 // Default Inputs: Start
 extern double Buy_Lots = 0.01;
 extern int Buy_Slippage = 10;
 extern double Sell_Lots = 0.01;
 extern int Sell_Slippage = 10;
 extern int StopLoss = 0100;
 extern int Take_Profit = 0200;
 // Default Inputs: Start


 int start() 
 { 
 OrderSend(Symbol(),OP_SELL,Sell_Lots,Bid,Sell_Slippage,Bid+StopLoss*Point,Bid-Take_Profit*Point); 
 OrderSend(Symbol(),OP_BUY,Buy_Lots,Ask,Buy_Slippage,Ask-StopLoss*Point,Ask+Take_Profit*Point);
 return(0); 
 }
 //--------------------------------------------------------------------
 
Lls29: Im not a programer but i managed to do this script from several other scripts, so excuse me if something looks weird or nonesense.

If you're not a programmer then try looking in the code-base or Internet for a script which does what you're looking for.

 
When the markets are moving fast 10 points slippage ( usually equates to 1 pip) is not enough
 
It doea what i want to. But not every time, mostly when the price is volatile. I use this in M1 charts. Here once more: #include #include #property show_inputs // Script: 0-1-Buy // Default Inputs: Start extern double Buy_Lots = 0.01; extern int Buy_Slippage = 10; extern double Sell_Lots = 0.01; extern int Sell_Slippage = 10; extern int StopLoss = 0100; extern int Take_Profit = 0200; // Default Inputs: Start int start() { OrderSend(Symbol(),OP_SELL,Sell_Lots,Bid,Sell_Slippage,Bid+StopLoss*Point,Bid-Take_Profit*Point); OrderSend(Symbol(),OP_BUY,Buy_Lots,Ask,Buy_Slippage,Ask-StopLoss*Point,Ask+Take_Profit*Point); return(0); } //--------------------------------------------------------------------
 
Lls29:

Hi guys.

Im not a programer but i managed to do this script from several other scripts, so excuse me if something looks weird or nonesense.

I thought I had finally nailed to program a quick and helpful script for a hedging strategy. Although its not very trustworthy. When i go ahead and drag it into the mt4 chart sometimes it does work, mostly when prices are very still. But when they get a little movement i can only get the sell trade to open up but the buy trade wont succeed. I thought it was something related to slippage but even if I give it a value of 0 or 1000 it will still happen sometimes.

Do you know how on earth can i fix this? How can i have a trustful script out of this knowing that every time that I use it it will open up both trades as stablished?

Here I leave the script:

<SRC by Moderator>



Hi Lls29

My suggestion is look up

double  NormalizeDouble(
   double  value,      // normalized number
   int     digits      // number of digits after decimal point
   );
 

My guess is that your code may work better like this :

#property show_inputs
#include
#include
#property show_inputs

// Script: 0-1-Buy 

// Default Inputs: Start
extern double Buy_Lots=0.01;
extern int Buy_Slippage = 10;
extern double Sell_Lots = 0.01;
extern int Sell_Slippage= 10;
extern int StopLoss=0100;
extern int Take_Profit=0200;
// Default Inputs: Start

int start()
  {
   double slBuy=NormalizeDouble(Ask-StopLoss*Point,Digits);
   double tpBuy=NormalizeDouble(Ask+Take_Profit*Point,Digits);
   double slSell=NormalizeDouble(Bid+StopLoss*Point,Digits);
   double tpSell=NormalizeDouble(Bid-Take_Profit*Point,Digits);
   OrderSend(Symbol(),OP_SELL,Sell_Lots,Bid,Sell_Slippage,slSell,tpSell,"My order",0,0,Green);
   OrderSend(Symbol(),OP_BUY,Buy_Lots,Ask,Buy_Slippage,slBuy,tpBuy,"My order",0,0,Green);
   return(0);
  }

If you highlight the NormalizeDouble (after you include it in your code) and press F1, read the MQL reference that pops up for it and you'll understand my point.

 

How to handle trading errors - mql4

If you don't check with using GetlastError() and some Print() outputs

then you never know what happens... and what you can do

without knowing result OrderSend OP_SELL

OrderSend OP_BUY is send...

ubzen:

If you're not a programmer then try looking in the code-base or Internet for a script which does what you're looking for.