Nurudeen Amedu:
I think your code opening the first order with no error 130 (invalid stops)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
But the errror is starting from the second positiin and so on....
Right?
----
I think that you need to reset the variables (stop_loss) and (take_profit) to again be equal to 0
So, you sould add another code lines that initiate them again in the top of your code:
---
void checkBar(){
RefreshRates();
stop_loss =0;
take_profit =0;
.
.
.
.
}
//That's All
Mohammad Soubra:
I think your code opening the first order with no error 130 (invalid stops)
I think your code opening the first order with no error 130 (invalid stops)
But the errror is starting from the second positiin and so on....
Right?
----
I think that you need to reset the variables (stop_loss) and (take_profit) to again be equal to 0
So, you sould add another code lines that initiate them again in the top of your code:
---
void checkBar(){
RefreshRates();
stop_loss =0;
take_profit =0;
.
.
.
.
}
//That's All
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 ...
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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