Hello
@wayum999 and welcome to the MW-forums
I had a look at the code you posted and noticed you did indeed use the standard MW-TradeManager as a basis, but you also removed a lot of lines.
My technique for getting coding issues like this resolved is adding 'debug' lines at strategic points in the code, and then add some more and finally add even more debug-lines
I literally retrace all steps of the logic to be able to see what it is exactly my study does, when it does it and what is the result.
Specifically for your case I would open up a chart, use the replay mode to set a starting point somewhere right before a 'BUY' signal and start debugging (by opening up the Study Log window in the View - Display menu)
I am looking at lines 305 to 309 of your code to start:
Java:
// Get Position type LONG or SHORT
switch (getSettings().getPositionType()) {
// If Position is LONG
case LONG: // Only Long Positions are allowed.
if (position == 0 && signal == Signals.BUY) {
I would make it look like this:
Java:
// Get Position type LONG or SHORT
switch (getSettings().getPositionType())
debug ("getPositionType = " + getSettings().getPositionType());
{
// If Position is LONG
case LONG: // Only Long Positions are allowed.
debug ("position = " + position + " signal " + signal);
if (position == 0 && signal == Signals.BUY) {
I would then closely inspect the output in the study log as I step forward through the bars in Replay Mode, and try to spot inconsistencies. (i.e.: do you get a BUY signal when your study fires one ?)
If that section looks ok, comment out these debuglines and move on to next. If you do this meticulously, you will eventually hit the right spot and figure out what needs to be corrected.
Good luck !
PS: during debugging you might notice that some values can't be printed in debug statements, so you may need to turn them into strings: String printableValue = String.valueOf(unprintableValue);
PPS: This might also help