Open Trade on New Bar
I want to open a buy trade if on a new bar current price is higher than open price and a sell if the opposite happens
this is my code
my new candle code works but i get order error 130 trying to check and open trade
I think your code opening the first order with no error 130 (invalid stops)
thanks i fixed it using
if (Ask<iOpen(Symbol(),0,1)){ //open sell; OrderSend(Symbol(),OP_SELL,lotsize,Bid,slip,Bid+stop_loss,(Bid-take_profit),NULL,Magic,0,clrRed); } if (Ask>iOpen(Symbol(),0,1)){ //open buy; OrderSend(Symbol(),OP_BUY,lotsize,Ask,slip,Ask-stop_loss,(Ask+take_profit),NULL,Magic,0,clrBlue); }
To make things easier for both of us, I think the following is clear ...
Please refer to the following code to assign SL and TP for Buy and Sell orders ...
double GetStopLossBuy() {return (Bid-SL*Point);} double GetStopLossSell() {return(Ask+SL*Point);} double GetTakeProfitBuy() {return(Ask+TP*Point);} double GetTakeProfitSell() {return(Bid-TP*Point);}
So, you need to use Ask in the Stop loss for the Sell order (You used Bid !!!).
you need to use Bid in the Stop loss for the Buy order (You used Ask !!!).
I assume, the code will be as follows ...
if (Ask<iOpen(Symbol(),0,1)){ //open sell; OrderSend(Symbol(),OP_SELL,lotsize,Bid,slip,Ask+stop_loss,(Bid-take_profit),NULL,Magic,0,clrRed); } if (Ask>iOpen(Symbol(),0,1)){ //open buy; OrderSend(Symbol(),OP_BUY,lotsize,Ask,slip,Bid-stop_loss,(Ask+take_profit),NULL,Magic,0,clrBlue); }
Considering there are no other mistake(s) ...
Please let me know if it works for you ...
I want to open a buy trade if on a new bar current price is higher than open price and a sell if the opposite happens
this is my code
my new candle code works but i get order error 130 trying to check and open trade