Jump to content

Sell/Buy scripts issue


haliban

Recommended Posts

Hello Guys,

 

I would like to have buyer and seller script that runs with predifined SL and TP.

 

I researched a little bit and found these two scripts in MQL codebase that are for the same thing.

 


#include <stdlib.mqh>
#include <WinUser32.mqh>
extern double Lots = 0.01; // change this number to change the lotsize
extern double stoploss = 100;  // change this number to change the stoploss
extern double takeprofit = 50; // change this number to change the takeprofit


int start()
 {
OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Bid-stoploss*Point,Bid+takeprofit*Point,"comment",0,0,CLR_NONE);
int ticket=OrderSend(Symbol(),OP_BUY,1.0,Ask,3,,0,"expert comment",255,0,CLR_NONE);
  if(ticket<1)
    {
     int error=GetLastError();


}

 


Seller one

#include <stdlib.mqh>
#include <WinUser32.mqh>

extern double Lots = 0.01; // change this number to change the lotsize
extern double stoploss = 100;  // change this number to change the stoploss
extern double takeprofit = 5; // change this number to change the takeprofit

int start()
 {
OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Ask+stoploss*Point,Ask-takeprofit*Point,"comment",0,0,CLR_NONE);
int ticket=OrderSend(Symbol(),

}

 

The issue I have is that both scripts are not working when I try to execute them.

 

If I replace

OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Ask+stoploss*Point,Ask-takeprofit*Point,"comment",0,0,CLR_NONE);

wiht

OrderSend(Symbol(),OP_BUY,0.1,Ask,3,0,0);

it works fine but

SL and TP are not defined!

 

I would appriciate if somebody with better mql understanding can give me a hand on this issue.

 

Thanks in advance,

H@liban

Kudus is what gives me power....
Link to comment
Share on other sites

Re: Sell/Buy scripts issue

 

Your problem is that those scripts were not designed for an ECN/STP broker.

 

In order to adapt them, you have to send 0 for SL & TP with OrderSend(), check & record the ticket returned and send an OrderModify() for that ticket number, setting the correct SL & TP. Alternatively, you can include the OrderReliable library (which would probably be safer anyway, google to find it) and use the OrderSendReliable2Step() function.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...