
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
If you need a compare (A > B) use (A - B) *DIR> 0 to reverse the comparison for a sell.
Seems like you have the idea.
Modify and post your code and I or someone else will comment on it
Hey GumRai,
It's been a while since I posted an update here, but I have been working away at the code and finally finished it--painful when working 10 hr days. I have two main issues however. 1) No matter what I do, it generates an error code: "Unknown ticket XYZ for OrderCloseFunction" and 2) I did a save-as of the file, (Called one USDCAD, another EURUSD), with different magicnumbers etc, yet it still takes only a trade at a time--and doesn't treat the pairs independently. In fact, it then creates an "invalid ticket for OrderCloseFunction" error as well.
I tried googling this but to no avail. Would really appreciate if you could guide me in the right direction with this. What am I doing wrong?
Many thanks in advance!
Never use OrdersTotal()==0 as a condition to enter trades
It means that if a trade has been open manually or by another EA or the same EA attached to another chart symbol, only 1 trade can be opened.
You have Global variable BuyTicket, initialise it to -1
Don't loop through orders before closing, it is unnecessary
Now, when using globally declared variables for ticket numbers there can be problems if the terminal is shut down and restarted for some reason
So declare a new global scope variable
I've typed this quickly, so I may have made errors, but is enough to give you the idea
Thanks a ton for this! The reason I'd put the loop in there was because what I noticed was that when it closed the sell, it would not trigger the buy for some reason.
I've gone ahead and made the necessary changes...but something still seems amiss. It's not taking any long trades now, and generates error code of invalid ticket, and OrderClose error 4051. Any suggestions on what is still wrong here?
The strange part is, that both in the previous code, and the current one (for the sell only), it took the trades reasonably okay (if I only implemented it on one chart).
I didn't think this would've been so hard haha! I suppose I was mistaken when I thought it was a very simple and straightforward thing...buy when candle crosses and opens above MA, close and sell when candle crosses and goes below MA.
I'm sorry, but I really don't know what you are trying to do
Doesn't select any order. Does the code even compile?
Here the else applies if( OrderCloseTime()==0) is false
Here it applies if the OrderSelect fails, which it certainly does
I'm sorry, but I really don't know what you are trying to do
Doesn't select any order. Does the code even compile?
Here the else applies if( OrderCloseTime()==0) is false
Here it applies if the OrderSelect fails, which it certainly does
Sorry, totally my fault. I didn't read/apply your suggestions correctly; thanks a lot for pointing them out. I've done so correctly here. No errors generated at all in the report. The only thing is that now, it's entering multiple sell and buy orders at times, which prevents it from closing trades at the right times.
Edit: To be precise, it is only exiting at the SL and TP, not when the price crosses the other side of the MA. Does this have something to do with the bool?
This does not select a trade, please follow the example that I gave you and do it correctly
I feel...really stupid. lol. Thanks for finding that!!
1) Two things left...it now creates an error code of OrderClose 4108. Shall I post the code again? It's the same as above with the correction you'd stated. It enters and exits as per rules though.
2) And it doesn't enter short immediately as soon as it closes the long position as shown in the pic. The green down arrow shows where it should've gone short. It took a buy, and closed that at a loss once it closed below the yellow MA. Here, it should've gone short. How can I loop this?
Thanks a lot GumRai. I honestly wouldn't have reached anywhere this close without your help.
Small change as it was checking to close an order when there wasn't one.
According to the code there is no reason for a sell to be opened immediately a buy closes.
The condition to exit a buy is not the same as the conditions to open a sell .
Remember that as you are only checking on the candle open, Close[0] will be the bid value of the first tick received for the candle.
Small change as it was checking to close an order when there wasn't one.
According to the code there is no reason for a sell to be opened immediately a buy closes.
The condition to exit a buy is not the same as the conditions to open a sell .
Remember that as you are only checking on the candle open, Close[0] will be the bid value of the first tick received for the candle.
Holy! You did it! Thanks again and again GumRai. You're the best.
Can't forward test now, but once markets open, I think I should be able to use this then, with the other pairs as long as I have different magic#s on the demo.