
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
Hmm... that seems unnecessary, unless I misread your words again (LOL).
This algorithm (same as what I described earlier) should suffice:
Only slight tweaking, in future, if you decided to open more than one trade at one time...
I have edited the code, it runs but it isn't taking any position.
Check out the OnTradeTransaction and CheckforOpen functions. Those are the ones I edited. I have included the MACDstop but something must not be working.
What do you think?
I have edited the code, it runs but it isn't taking any position.
Check out the OnTradeTransaction and CheckforOpen functions. Those are the ones I edited. I have included the MACDstop but something must not be working.
What do you think?
(1) It doesn't take any position because of the bug here:
should have been:
(2) Now, once it starts to open positions, I noticed further bugs:
should have been:
so that it matches the reverse of the conditions for long trade.
And
should be uncommented. I did not do further checks, due to (3) below.
(3) Looking at the changes you made in OnTradeTransaction and CheckForOpen functions, and your persistent mentioning of the need to check closing price of the last trade, you seem to want to allow opening more than one position when a trade is already on-going. Because your changes only take care of blocking new open attempts when an existing position is stoplossed. This is in contradiction to your first post where you mentioned "Only have one trade at all times".
Now, assuming this is the logic you wanted (in lieu of your first post), then I think the code will run and you'll be able to carry on your testing with the above changes.
On the other hand, if you still want to stick to your first post's conditions, then you can relook at my algorithm above, which does not differentiate between positions closed by stoploss or takeprofit, and will prevent multiple positions to be opened, without using the OnTradeTransaction function (which, frankly, is not a robust way for setting flags like MACDStop, because you have to consider possible system down-time which essentially will skip that function).
(1) It doesn't take any position because of the bug here:
should have been:
(2) Now, once it starts to open positions, I noticed further bugs:
should have been:
so that it matches the reverse of the conditions for long trade.
And
should be uncommented. I did not do further checks, due to (3) below.
(3) Looking at the changes you made in OnTradeTransaction and CheckForOpen functions, and your persistent mentioning of the need to check closing price of the last trade, you seem to want to allow opening more than one position when a trade is already on-going. Because your changes only take care of blocking new open attempts when an existing position is stoplossed. This is in contradiction to your first post where you mentioned "Only have one trade at all times".
Now, assuming this is the logic you wanted (in lieu of your first post), then I think the code will run and you'll be able to carry on your testing with the above changes.
On the other hand, if you still want to stick to your first post's conditions, then you can relook at my algorithm above, which does not differentiate between positions closed by stoploss or takeprofit, and will prevent multiple positions to be opened, without using the OnTradeTransaction function (which, frankly, is not a robust way for setting flags like MACDStop, because you have to consider possible system down-time which essentially will skip that function).
Aaah that's why it wasn't taking trades! Thanks for pointing that out.
Sorry for the confusion, let me clarify:
1. I want to only have one trade at all times.
2. Once a trade is lost, the system wouldn't open any other trades until MACD crosses the 0 level.
For some reason, it still opens more than one position. to do so, I went through the following code which makes complete sense but it isn't working when I implement it.
Is this the best way to only have one trade at a time?
Aaah that's why it wasn't taking trades! Thanks for pointing that out.
Sorry for the confusion, let me clarify:
1. I want to only have one trade at all times.
2. Once a trade is lost, the system wouldn't open any other trades until MACD crosses the 0 level.
For some reason, it still opens more than one position. to do so, I went through the following code which makes complete sense but it isn't working when I implement it.
Is this the best way to only have one trade at a time?
Ok, for one trade at a time, there is a much easier way, without using the tradecount function (which looks complicated), and OnTradeTransaction function, as follows:
Another way is to call PositionsTotal() which will return 0 if there is no existing trade.
Then, in the OpenPosition() function, I added one line:
After making these two changes, there won't be more than 1 trade at any one time.