Can I send an order for a Stop order, as soon as I close a previous order at the stop loss value ?

 

I have tried this code, but I dont know what to do to get it to work

void killTrade(int pips, int ticket)

{

double price = NormalizeDouble(OrderOpenPrice(),Digits);

bool reopen = 0;

if(OrderSelect(ticket, SELECT_BY_TICKET)==true)

{

if(pips <= -1*getMaxLoss())

{

if(OrderType()==1)

{

OrderClose(ticket,OrderLots(),Ask,3,Red);

OrderSend(Symbol(),4,4,price+30*Point,3,Bid-50*Point,Ask+50*Point,"AUTO_BUY_STOP",11111,0,DarkBlue);

Alert(GetLastError()) ;

// or use the original SL and TP values taken from the original trade

// but try this first to get it working

// NormalizeDouble(ord,Digits)

}

if(OrderType()==0)

{

OrderClose(ticket,OrderLots(),Bid,3,Red);

OrderSend(Symbol(),5,4,price-30*Point,3,Ask+50*Point,Bid-50*Point,"AUTO_SELL_STOP",11111,0,Red);

Alert(GetLastError()) ;

}

}

}

}

It has actually worked once but I can not tell why, or why the rest of the time it doesnt.

thanks

 

Some thoughts that won't necessarily fix the problem, but may help someone to work out what's needed

A) check the return code/flag from the OrderXXXX functions; you then only need Alert when function fails/issues a -1 ticket number

B) In your alerts, display more than just GetLastError(). e.g

Alert("OrderSend 5 failed - ", GetLastError());

C) For 3/5 digit pricing, your TP could be very close to Entry price (20*Point away)

D) use SRC button to display code

E) It seems strange to me to be creating a trade in a function called "killTrade"

 
brewmanz:

Some thoughts that won't necessarily fix the problem, but may help someone to work out what's needed

A) check the return code/flag from the OrderXXXX functions; you then only need Alert when function fails/issues a -1 ticket number

B) In your alerts, display more than just GetLastError(). e.g

C) For 3/5 digit pricing, your TP could be very close to Entry price (20*Point away)

D) use SRC button to display code

E) It seems strange to me to be creating a trade in a function called "killTrade"


thanks for that.

I intend to develop the GetLastError. I was trying to keep the code as simple as I could so I could find why it wasn't working.

I have a problem also just now that my demo account wont let me place a Stop Order unless it is a minimum of 20 points from the price, I would like that to be tighter.

the reason it is called killtrade is because I have taken a function from another EA and hacked it to try and make this work. I thought "killtrade" was a bit hard myself :-)

Basically, what I want to do is, in the scenario where a trade is opened, and the price retreats back on me, is to cut my losses as soon as possible and send an order to reopen if the price goes to my entry point again.

thanks again