Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 412
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
Hello. Faced with an unpleasant situation. Help me out here.
I have an Expert Advisor. It works fine in the Strategy Tester, I have no claims. When I run it on a demo, the Expert Advisor cannot place stops on certain orders. There is an error that appears not always, but sometimes. I am desperate to find it on my own and hope to get your help. It should be noted the EA works flawlessly in all other aspects, just like in the tester, no complaints, except that the problem is that stops are not always set. The error appears at different brokers on different accounts. Here is the part of the code responsible for trade operations
Here is the code of the Error(int er) function
So, when the EA fails to set stops, a message appears showing information about the error and parameters of the order it tried to modify. What he writes is the real mystery to me. As you can see from the pictures below, it constantly writes that the volume is wrong. This is strange. I should add that all order parameters are calculated correctly before modification, it can be seen in the messages. Otherwise the error would be different. The program was tested with a higher spread than the one in the demo.
Hello. Faced with an unpleasant situation. Help me out here.
I have an Expert Advisor. It works fine in the Strategy Tester, I have no claims. However, when I run it on a demo, I see that the EA cannot place stops on certain orders. There is an error that appears not always, but sometimes. I am desperate to find it on my own and hope to get your help. It should be noted the EA works flawlessly in all other aspects, just like in the tester, no complaints, except that the problem is that stops are not always set. The error appears at different brokers on different accounts. Here is the part of the code responsible for trade operations
Here is the code of the Error(int er) function
So, when the EA fails to set stops, a message appears showing information about the error and parameters of the order it tried to modify. What he writes is the real mystery to me. As you can see from the pictures below, it constantly writes that the volume is wrong. This is strange. I should add that all order parameters are calculated correctly before modification, it can be seen in the messages. Otherwise the error would be different. The program was tested with a higher spread than the one in the demo.
You should be very careful with values of your global variables. I may suggest that ord_ticket is a global variable and therefore it may store the previous value. And before calling GetLastError() to catch the error, you should reset the previous value by calling it at the beginning of the code.
ord_ticket is declared at local level. And then even if it is declared globally in the first line
its value will certainly change. It will be either order number in case of successful transaction, or -1 otherwise. So, if the order is not opened, we don't get to the block of setting stops.
It should also be noted that the OrderSend() function always changes the value of the last error(according to the documentation and logic), so resetting the previous reading in this case is not necessary and would result in a simple waste of time. That is, error 131 appears after entering the stop setting block and before the error message is displayed. Since the stops are not really placed, the OrderModify() function must be the last function to be called, which, as well as the previous one, always changes the value of the last error. But I cannot understand why it does not change the value of the last error. Where does it come from? Once again I will say that there were no problems in the tester.
I had an idea that the broker was cheating because the server would send error numbers to the terminal and the latter in its turn would send them to the Expert Advisor. I have abandoned this idea because only orders of one EA have errors, other EAs working in parallel do not have such errors.
ord_ticket is declared at local level. And then even if it is declared globally in the first line
value is sure to change. It will be either order number in case of successful transaction, or -1 otherwise. So, if the order is not opened, we don't get to the block of setting stops.
It should also be noted that the OrderSend() function always changes the value of the last error (according to the documentation and logic), so resetting the previous reading in this case is not necessary and would result in a simple waste of time. That is, error 131 appears after entering the stop setting block and before the error message is displayed. Since the stops are not really placed, the OrderModify() function must be the last function to be called, which, as well as the previous one, always changes the value of the last error. But I cannot understand why it does not change the value of the last error. Where does it come from? Once again I will say that there were no problems in the tester.
I had an idea that the broker was cheating because the server would send error numbers to the terminal and the latter in its turn would send them to the Expert Advisor. I have quickly abandoned this idea because only orders of one EA have errors, other EAs working in parallel do not have such errors.
I'll add. The code of the parallel working EA is exactly the same, it is responsible for setting stops. This EA has never had a situation when stops were not set for orders.
It appears that there is an error in calculation of parameters somewhere above but if only one parameter is wrong, another error should appear. For example, the well-known 130
ord_ticket is declared at local level. And then even if it is declared globally in the first line
value is sure to change. It will be either order number in case of successful transaction, or -1 otherwise. So, if the order is not opened, we don't get to the block of setting stops.
It should also be noted that the OrderSend() function always changes the value of the last error (according to the documentation and logic), so resetting the previous reading in this case is not necessary and would result in a simple waste of time. That is, error 131 appears after entering the stop setting block and before the error message is displayed. Since the stops are not really placed, the OrderModify() function must be the last function to be called, which, as well as the previous one, always changes the value of the last error. But I cannot understand why it does not change the value of the last error. Where does it come from? Once again I will say that there were no problems in the tester.
I had an idea that the broker was cheating because the server would send error numbers to the terminal and the latter in its turn would send them to the Expert Advisor. I have quickly abandoned this idea because only orders of one EA have errors, other EAs working in parallel do not have such errors.
You wrote a three-point response. In the first one you made a mistake (my entry is quite correct), in the second one you also made a mistake (although this message leveled it out :) The third point sounded as if you suggested to move the cursor to the end after the entry, not before it (which was taken as a mistake again). In the face of such a picture, I preferred to make a clarification to the answering multi-skilled moderator.
Nevertheless, thank you indeed for your response. And happy New Year! :)
:D ok, happy new year to you too :)
Going back to what was written on page 411 ... does anyone have an idea how to combine that code and entry/exit conditions for crossing two MAs? or are pending orders the only option?
After opening a deal on a mooving signal, start to monitor the number of orders or this order specifically, if the number of orders to decrease or as the second option is closed specifically this order, then find out how it was closed, if a stop, then opens just the opposite order at the current price, that's all
After opening a deal on a moving signals start to monitor the number of orders or this order specifically, if the number of orders to decrease or as the second option is closed specifically this order, then find out how it is closed, if the stop, then just open the opposite order at the current price, that's all
I understand that, but I can't write it down. The Expert Advisor either trades only on muwings signals and does not open a reverse position in case of a loss, or simply crashes the terminal when testing starts. So I wrote something that cannot be processed at all. I am not very good at writing. I need help in the form of written code.
If OrderProfit()<0, it will open opposite order.But it does not work together with signals from moving aids. Can you write a single code to provide both muwings signals and conditions for opening an opposite position?
I understand that, but I can't write it down. The Expert Advisor either trades only on muwings signals and does not open a reverse position in case of a loss, or simply crashes the terminal when testing starts. So I wrote something that cannot be processed at all. I am not very good at writing. I need help in the form of written code.
If OrderProfit()<0, it will open opposite order.But it does not work together with signals from moving aids. Can you write a single code that contains both muwings signals and conditions for opening an opposite position?
I have no time and possibility to write you a ready code, as I am at work)).
You do not search by history, but by current positions, here is a logical chain, on the basis of which you can try to write the code:
[block of working with muwings and placing an order]
1 remember the ticket and the magic number of the placed order
2 monitor the number of orders and if there are no orders in the market (it means that our order has been closed), then go to point3 or monitor this specific order until its close time is more than zero, in which case we exclude points 3 and 4
3 find our order
4 find out if it is closed
5 find out how it was closed
6 if it was closed through a stop, set another order different from it in the direction