When I run this EA on one Chart with 1 Currency it works fine.
When I open 2 charts each with the same EA attached but different currencies on each chart. eg: chart1 :EURUSD , Chart2: AUDUSD.
As soon as the 2nd chart runs 1 of the trades Trailing stop ,Order Modify begins changing the Stop even though the criteria hasn't been meet for it to start.
I thought by attaching them to different charts would have allowed both curencies to run independently on their own charts, but it is affecting the Trailing Stop Order Modify.
any assistance to what I am missing would be greatful,Thanks
The EA must be able to isolate its trades from all others - Same or other EAs on the same or other charts.
The magic number is sufficient if all EAs on all charts are each using a unique one.
If you add the EA to another pair and forget to change the magic number, they'll interfere with each other. Adding the symbol over comes the human's forgetfulness.
If you add the EA to the same pair but different timeframe then again you have the same problem. I have the EA use a range of numbers to over come this.Thanks RaptorUk and WhRoeder, I have it working now and I've been looking at the range of Numbers which will be useful. Thanks
I am using this as code for my trailing Stop, I have it checking (Symb)being for Symbol () as I have An EA attched to 4 charts each with differet currencies.
There are "No Errors" that apprear in experts. The trailing stop works the majority of time but randomly doesn't start the Trailingstop when the criteria is meet. Eg. today TrailingStop doesn't triggerer on EURUSD and does on the other 3 currencies , but tomorrow it doesn't trigger on the AUDUSD, but does on the EURUSD and the other currencies. It happens randomly on either BUY or SELL trades.
Does anyone know if I am missing something in my coding ? , Is checking symbol() sufficient ? or adding Magic No.s etc.. is necesarry even though the EA is attached to 4 charts each with different currencies. Thanks
// Trailing Stop TS1 = Ask+ New_Stop(trailingstop)*Point; TS2 = Bid - New_Stop(trailingstop)*Point; RefreshRates(); for(int iPos =OrdersTotal()-1; iPos >=0 ; iPos--) if(OrderSelect(iPos,SELECT_BY_POS)) { if(trailingstop > 0) { if (OrderType() == OP_BUY) { if(OrderSymbol() == Symb) { if ((Bid - OrderOpenPrice()) > trailingstop*Point) { if(OrderStopLoss() < (Bid - trailingstop*Point)) { OrderModify(Ticket, OrderOpenPrice(),TS2,TP, 0, Blue); return(0); } } } } } } if(trailingstop>0) if (OrderType() == OP_SELL) { if(OrderSymbol() == Symb) { if ((OrderOpenPrice() - Ask) > trailingstop * Point) { if (OrderStopLoss() > (Ask + trailingstop * Point)) { OrderModify(Ticket, OrderOpenPrice(), TS1, TP, 0,Blue); return(0); } } } }
?
I am using this as code for my trailing Stop, I have it checking (Symb)being for Symbol () as I have An EA attched to 4 charts each with differet currencies.
There are "No Errors" that apprear in experts. The trailing stop works the majority of time but randomly doesn't start the Trailingstop when the criteria is meet. Eg. today TrailingStop doesn't triggerer on EURUSD and does on the other 3 currencies , but tomorrow it doesn't trigger on the AUDUSD, but does on the EURUSD and the other currencies. It happens randomly on either BUY or SELL trades.
Does anyone know if I am missing something in my coding ? , Is checking symbol() sufficient ? or adding Magic No.s etc.. is necesarry even though the EA is attached to 4 charts each with different currencies. Thanks
You can use a MagicNumber if you wish, but in this case it isn't needed as you are checking OrderSymbol(). If you had an EA on GBPUSD H and another on GBPUSD M15 then the symbol would be the same so you would need Magic Numbers in that instance.
Where does Symb get it's value from ?
Why have these 2 lines when they do exactly the same thing ?
if ((Bid - OrderOpenPrice()) > trailingstop*Point) { if (OrderStopLoss() < (Bid - trailingstop*Point))
Does your OrderModify() not get called ? or does it get called and fail ? if it fails why aren't you checking it's return value and reporting the error, the new SL the current SL, Bid, Ask ?
Read this: What are Function return values ? How do I use them ?
I am using the MQL4 EA Simple EA. Structure, strategy, algorithm. as a template. Symb is in the order Accounting section.
Your Quest: Where does Symb get it's value from ?
I am using Symb = symbol() ; , in the accounting section to get the chart symbol.
I've deleted "if (OrderStopLoss() < (Bid - trailingstop*Point))" , Yes it is duplicating, Thanks.
I have looked in the Experts Tab and there are "No Errors" occuring, 80% of the time the trailing stop is working correctly but randomly it doesn't work on 1 or 2 of the currencies. Even though the "same EA" is attached to 4 different charts each with 1 currency .eg.AUDUSD, EURUSD, USDJPY, GBPUSD.(1 on each chart).
I have attached the amended Code, would you please let me know if it looks correct and any additional things I should try and check for, Thanks.
If OrderModify() is working 80% of the time, with "No Errors" ,Is there anything you can suggest as to why OrderModify() isn't being called sometimes ?
// Declared Globally : string Symb; //-------------------------------------------------------- // Order Accounting Symb=Symbol(); // Íàçâàíèå ôèí.èíñòð. Total=0; // Êîëè÷åñòâî îðäåðîâ for(int i=1; i<=OrdersTotal(); i++) // Öèêë ïåðåáîðà îðäåð { if (OrderSelect(i-1,SELECT_BY_POS)==true) // Åñëè åñòü ñëåäóþùèé { // Àíàëèç îðäåðîâ: if (OrderSymbol()!=Symb)continue; // Íå íàø ôèí. èíñòðóì if (OrderType()>1) // Ïîïàëñÿ îòëîæåííûé { Alert("Pending order detected.EA Doesn't work."); return; // Âûõîä èç start() } Total++; // Ñ÷¸ò÷èê ðûíî÷í. îðä if (Total>1) // Íå áîëåå îäíîãî îðä { Alert("Several market orders.Ea dosen't work..."); return; // Âûõîä èç start() } Ticket=OrderTicket(); // Íîìåð âûáðàíí. îðä. Tip =OrderType(); // Òèï âûáðàííîãî îðä. Price =OrderOpenPrice(); // Öåíà âûáðàíí. îðä. SL =OrderStopLoss(); // SL âûáðàííîãî îðä. TP =OrderTakeProfit(); // TP âûáðàííîãî îðä. Lot =OrderLots(); // Êîëè÷åñòâî ëîòîâ } } //--------------------------------------------------------------------- //Trading criteria //Closing Orders //OrderValues //Openning Orders // -------------------------------------------------------------------- // Trailing Stop TS1 = Ask+ New_Stop(trailingstop)*Point; TS2 = Bid - New_Stop(trailingstop)*Point; RefreshRates(); for(int iPos =OrdersTotal()-1; iPos >=0 ; iPos--) if(OrderSelect(iPos,SELECT_BY_POS)) { if(trailingstop > 0) { if (OrderType() == OP_BUY) { if(!OrderSymbol()== Symb) //Added code { Alert("Dosent equal symbol","Symbol",Symb); } if ((Bid - OrderOpenPrice()) > trailingstop*Point) { bool checka = !OrderModify(Ticket, OrderOpenPrice(),TS2,TP, 0, Blue); //Added Code if(checka == false) //Added Code { Alert("TStop Failed",GetLastError()); //Added Code Alert("Ticket",Ticket,Digits); //Added Code } else { Alert("OrderModified"); //Added code } return(0); } } } } if(trailingstop>0) if (OrderType() == OP_SELL) { if(!OrderSymbol() == Symb) //Same code as above "added code" { Alert("Dosent equal symbol","Symbol",Symb); } if ((OrderOpenPrice() - Ask) > trailingstop * Point) { bool checkb = !OrderModify(Ticket, OrderOpenPrice(), TS1, TP, 0,Blue); if(checkb == false) { Alert("TStop Failed",GetLastError()); Alert("Ticket",Ticket,Digits); } else { Alert("OrderModified"); } return(0); } }
I am using the MQL4 EA Simple EA. Structure, strategy, algorithm. as a template. Symb is in the order Accounting section.
Your Quest: Where does Symb get it's value from ?
I am using Symb = symbol() ; , in the accounting section to get the chart symbol.
I've deleted "if (OrderStopLoss() < (Bid - trailingstop*Point))" , Yes it is duplicating, Thanks.
I have looked in the Experts Tab and there are "No Errors" occuring, 80% of the time the trailing stop is working correctly but randomly it doesn't work on 1 or 2 of the currencies. Even though the "same EA" is attached to 4 different charts each with 1 currency .eg.AUDUSD, EURUSD, USDJPY, GBPUSD.(1 on each chart).
I have attached the amended Code, would you please let me know if it looks correct and any additional things I should try and check for, Thanks.
OK, you have made some things better and others much worse ;-)
Where does the value of Ticket come from ? shouldn't you be using OrderTicket() ?
I don't think this is what you intended.
if(!OrderSymbol()== Symb) //Added code { Alert("Dosent equal symbol","Symbol",Symb); // so if the symbol doesn't match Alert . . . } if ((Bid - OrderOpenPrice()) > trailingstop*Point) // . . . and even if it doesn't match run this code anyway ? ? { bool checka = !OrderModify(Ticket, OrderOpenPrice(),TS2,TP, 0, Blue); //Added Code
Then this . . .
bool checka = !OrderModify(Ticket, OrderOpenPrice(),TS2,TP, 0, Blue);
. . . if the OrderModify() works it returns true which you then NOT ( ! ) giving false, you then check if checka = false and Alert if it is false, in other words if the OrderModify() worked.
Try this . . .
if(trailingstop > 0) { if (OrderType() == OP_BUY) { if(!OrderSymbol()== Symb) //Added code { Alert("Dosent equal symbol ", Symbol() ," ", Symb); continue; // if Symbol doesn't match --> next order } if ((Bid - OrderOpenPrice()) > trailingstop * Point) { if (! OrderModify(OrderTicket(), OrderOpenPrice(),TS2,TP, 0, Blue) ) // use OrderTicket() ! ! { Alert("TStop Failed",GetLastError()); //Added Code Alert("Ticket", OrderTicket(), Digits); // use OrderTicket() ! ! } else { Alert("OrderModified"); //Added code } // return(0); // why return here ? ? don't you want to check the other orders ? } } }
Thanks Raptoruk,. I tried to enter the code "Try this" it came up with a few errors I'll need to look at and I'll have a read of the Can price! = price. Previously the trailing stop was working 80% of the time. I haven't seen any errors in Experts when the trailing stop wasn't working. The above code you sent through has allowed me to learn that I have to use Continue; to stop it if Symbol doesn't match. The trailing stop section doesn't use "while" so I am not sure if I can use continue. I attached the full EA rather then just showing bits and pieces.
Please let me know if you think this code is appropriate still or If you can see what may be causing the issue ?
Thanks for your assistance with the code you have suggested to me I will need to study it further as well.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
When I run this EA on one Chart with 1 Currency it works fine.
When I open 2 charts each with the same EA attached but different currencies on each chart. eg: chart1 :EURUSD , Chart2: AUDUSD.
As soon as the 2nd chart runs 1 of the trades Trailing stop ,Order Modify begins changing the Stop even though the criteria hasn't been meet for it to start.
I thought by attaching them to different charts would have allowed both curencies to run independently on their own charts, but it is affecting the Trailing Stop Order Modify.
any assistance to what I am missing would be greatful,Thanks