- Order Modify Error 130 Help Needed Please
- Take profits
- Stop Loss error
Angel Dickinson: I kept getting Ordersend error 130. Btw the MagicNumbers for each were different. |
|
|
In my opinion, or actually what I used to do is the following ...
1- Put the EA on each chart you want to trade ...
2- Never ever use OrdersTotal() if you want to treat pairs separately ...
So, you need to tweak the OrdersTotal() and use a custom function instead
to count total trades of each pair (Not counting all pairs together) ...
So, your code should be like the following ...
extern int MagicNumber = 12345; extern double lots = 0.10; extern int stopLoss = 1000; extern int takeProfit = 2000; void OnTick() { if (TotalNoOfOrders() > 0) { return; } double ema = iMA(NULL, 0, 400, 0, MODE_EMA, PRICE_CLOSE, 0); double ema2 = iMA(NULL, 0, 200, 0, MODE_EMA, PRICE_CLOSE, 0); double rsi = iRSI(NULL, 0, 14, PRICE_CLOSE, 0); if ((Bid > ema)&&(Bid < ema2)&&(rsi < 30) ) { if (OrderSend(Symbol(), OP_BUY, lots, Ask, 3, Ask - stopLoss * Point, Ask + takeProfit * Point, "BossPips", MagicNumber, 0, Blue)) { Print("Buy order succeeded!"); } } if ((Bid < ema)&&(Bid > ema2)&&(rsi > 70) ) { if (OrderSend(Symbol(), OP_SELL, lots, Bid, 3, Bid + stopLoss * Point, Bid - takeProfit * Point, "BossPips", MagicNumber,0, Red)) { Print("Sell order succeeded!"); } } } //--- //+------------------------------------------------------------------+ int TotalNoOfOrders(){ int cnt, total; int i = 0; total = OrdersTotal(); for(cnt=0;cnt<total; cnt++){ if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)==true) if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber) i++; } return(i); }
I wish there is no mistakes (minor) as I didn't reviewed your original code. But diffidently you need the TotalNoOfOrders() instead of OrdersTotal() ...
Good luck ...
In my opinion, or actually what I used to do is the following ...
1- Put the EA on each chart you want to trade ...
2- Never ever use OrdersTotal() if you want to treat pairs separately ...
So, you need to tweak the OrdersTotal() and use a custom function instead
to count total trades of each pair (Not counting all pairs together) ...
So, your code should be like the following ...
I wish there is no mistakes (minor) as I didn't reviewed your original code. But diffidently you need the TotalNoOfOrders() instead of OrdersTotal() ...
Good luck ...
Hey I appreciate you kind reply and hospitality as I stated above I'm new to coding and smart comments like the guys gave me above was not helpful at all. Thank you for your help now is there a way to switch TP to act as 100 (for 100 pips) on the extern handle instead of me using 1000( for 100 pips). And so I only use OrdersTotal() for one at a time activation of trades correct?
extern int MagicNumber = 12345; extern double lots = 0.10; extern int stopLoss = 1000; extern int takeProfit = 2000; void OnTick() { if (TotalNoOfOrders(Symbol()) > 0) { return; } double ema = iMA(NULL, 0, 400, 0, MODE_EMA, PRICE_CLOSE, 0); double ema2 = iMA(NULL, 0, 200, 0, MODE_EMA, PRICE_CLOSE, 0); double rsi = iRSI(NULL, 0, 14, PRICE_CLOSE, 0); if ((Bid > ema)&&(Bid < ema2)&&(rsi < 30) ) { if (OrderSend(Symbol(), OP_BUY, lots, Ask, 3, Bid - stopLoss * Point, Ask + takeProfit * Point, "BossPips", MagicNumber, 0, Blue)) { Print("Buy order succeeded!"); } } if ((Bid < ema)&&(Bid > ema2)&&(rsi > 70) ) { if (OrderSend(Symbol(), OP_SELL, lots, Bid, 3, Ask + stopLoss * Point, Bid - takeProfit * Point, "BossPips", MagicNumber,0, Red)) { Print("Sell order succeeded!"); } } } //--- //+------------------------------------------------------------------+ int TotalNoOfOrders(string symb){ int cnt, total; int i = 0; total = OrdersTotal(); for(cnt=0;cnt<total; cnt++){ if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)==true) if(OrderSymbol()==symb && OrderMagicNumber()==MagicNumber) i++; } return(i); }
I backtested it ... I even changed the TotalNoOfOrders() > 0 to different numbers and found it works.
Anyway, I see also you have a mistake in Ask and Bid for Stoploss for both Buy and Sell SendOrder function ...
I corrected everything and also added a little change which has no effect, it is sending the symbol name as an argument to TotalNoOfOrders( ) function ...
Above is the final code ... (or download the attached file) It works ... Open only one order per each currency pair at a time ...
Note: No need to change the MagicNumber ... Just use the default one for all pairs.
I backtested it ... I even changed the TotalNoOfOrders() > 0 to different numbers and found it works.
Anyway, I see also you have a mistake in Ask and Bid for Stoploss for both Buy and Sell SendOrder function ...
I corrected everything and also added a little change which has no effect, it is sending the symbol name as an argument to TotalNoOfOrders( ) function ...
Above is the final code ... (or download the attached file) It works ... Open only one order per each currency pair at a time ...
Note: No need to change the MagicNumber ... Just use the default one for all pairs.
Thank you
I backtested it ... I even changed the TotalNoOfOrders() > 0 to different numbers and found it works.
Anyway, I see also you have a mistake in Ask and Bid for Stoploss for both Buy and Sell SendOrder function ...
I corrected everything and also added a little change which has no effect, it is sending the symbol name as an argument to TotalNoOfOrders( ) function ...
Above is the final code ... (or download the attached file) It works ... Open only one order per each currency pair at a time ...
Note: No need to change the MagicNumber ... Just use the default one for all pairs.
I was playing around with the EA and would like to know if you can help me with coding a Moving average crossover for exit. I have been googling how to do this but couldn't find anything can you please help? I would really appreciate this also how to add ATR as my SL feature?

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use