
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
Looking into the journal, when I do a backtest, there are no errors concerning OrderClose().
I make a note of this for troubleshooting
Hello RaptorUK, I did not know you were making a reply so soon
I'll look into your message for what to do and not.
Hello RaptorUK, I did not know you were making a reply so soon
Thank you for your comments and time.
Hi RaptorUK, and all
Attached is the newest version.
The latest problem was that the code would BUY, but would not liquidate. By inserting the iGProfit and iGLoss with correct settings the code will now Liquidate. So that problem has been corrected.
But the code will BUY many times inbetween liquidation and liquidation continues until BUYING signals crop up again. Therefore, in the time span of 5 days, there were over 10,000 trades, until the account was dried out.
What I was attempting for the code to do, was for it to trade only once per bar. e.g. That if there was a BUY signal and a SELL signal on the same bar, no other trade signals would be generated from that bar. No trades until the next bar, etc.
From an old code (one that is public) I inserted portions that I thought would help. They did not. I have left them inserted, but with /* */. Otherwise, code is intact. If anyone could have a look and give advise or critic, I would be grateful.
Cheers
What I was attempting for the code to do, was for it to trade only once per bar. e.g. That if there was a BUY signal and a SELL signal on the same bar, no other trade signals would be generated from that bar. No trades until the next bar, etc.
OK, here is what I would do (without looking at your code so bear in mind I might be a little off . . .):
Set a variable to true on the first tick of the new bar, maybe NewBar_AllowTrade = true; test that variable when your code wants to trade, if ( . . . . && NewBar_AllowTrade == true && . . . . . ) then when the trade has been placed successfully set it to false . . . NewBar_AllowTrade = false;
if you want to allow 1 BUY and 1 SELL per new bar you can do something similar but you will have to use an int rather than a bool, on the first tick of a new bar set it to 0, NewBar_AllowTrade = 0; . . and modify the int once when the BUY is placed, NewBar_AllowTrade |= 1; and again when the SELL is placed NewBar_AllowTrade |= 2; to test if a BUY can be placed: NewBar_AllowTrade & 1 == 1 to test if a SELL can be placed: NewBar_AllowTrade & 2 == 2