simple buy or sell script

 

Have successfully used the script below for 'simply sell' (& similarly 'simple buy') some time ago.

Tried it again but keep getting 'error # 130' and no success

What may have changed? How does the code need to be updated?

Any support much appreciated, many thanks

dolphin44 

int start()
{
int StopLoss = 400; // in point units
int TakeProfit = StopLoss*2;
double LotSize = 0.01;
int Slippage = 2;
   //Opening SELL
   int Ticket;
   Ticket=OrderSend(Symbol(),OP_SELL,LotSize,Bid,Slippage,Ask+StopLoss*Point,Ask-TakeProfit*Point);
   
   if(Ticket>0)
      {
        Print("OrderSend OK");
        return(0);        
      }
      Print("OrderSend failed with error #",GetLastError());   
   return(0);
}
 
dolphin44:

Have successfully used the script below for 'simply sell' (& similarly 'simple buy') some time ago.

Tried it again now but keep getting 'error # 150' and no success

What may have changed? How does the code need to be updated?

Any support much appreciated, many thanks

dolphin44 

<CODE REMOVED>

Please edit your post . . .    please use the   SRC   button to post code: How to use the   SRC   button.
 
dolphin44:

Have successfully used the script below for 'simply sell' (& similarly 'simple buy') some time ago.

Tried it again now but keep getting 'error # 150' and no success


Error 150 or error 130 ?  150 is a FIFO issue to do with closing orders not opening them  . . .

If it's error 130 then your Broker is probably an ECN type Broker. 

 

150 is a FIFO issue - the TP/SL must be equal or larger/smaller then the oldest open order so the oldest will close first.

130 is a ECN issue - open first and then set stops.

Always open first and then set stops and you'll isolate the problem.

Some US brokers implemented FIFO directly - thus breaking the mql4 model. Others (like IBFX) implemented it in the back office accounting (individual trades in accounting statements differ from mql4 statements.)

 
WHRoeder:

150 is a FIFO issue - the TP/SL must be equal or larger/smaller then the oldest open order so the oldest will close first.

130 is a ECN issue - open first and then set stops.

Always open first and then set stops and you'll isolate the problem.

Some US brokers implemented FIFO directly - thus breaking the mql4 model. Others (like IBFX) implemented it in the back office accounting (individual trades in accounting statements differ from mql4 statements.)

many thanks for helpful advice!
 
RaptorUK:
Please edit your post . . .    please use the   SRC   button to post code: How to use the   SRC   button.

thanks for instructions, will use next time
Reason: