Looking at your code... no idea what it is doing simply due to no documentation and [for me at least] not understood presets and use of constants.
#define is a great item to use: gives meaningful id to constant and allows single point of change no matter how large source is...
You will easily solve your no sell issue by simply: documenting your code.
Having to write meaningful comments with the why's of a code block and/or variable usage will instantly clarify [to you] what is going on.
Additionally, I see no relevant Print() statements placed at areas of interest for informing you what's going on...
Print() used as a trace tool is VIP medicine and if so desired can preface each trace statement/block with an extern flag so can toggle on/off...
Anyway, nice to see readable code - is obvious that you have made effort regards source format - many do not...
Sorry about that, i had print statements at every level but i removed them before posting the code, as it printed several lines at every tick, thought it would just irritate people, as it was irritating me.
Essentially i work with ESignal, so have had to convert everything over, mainly in the way that ESignal lets u choose the option to only calculate on the close of bars, not every tick, which is why i've had to add extra functions to ensure certain variables are only calculated once per bar.
Here's a full run down of the code:
I wait for the MACD to cross, ie, the previous bar MACD to be above 0 and the bar before that has a MACD below 0, or vice versa. We use the NewBar function to make sure it's the beginning of the bar and then change the variable to 1 if this occurs. We only check trade conditions if the MACD has crossed. We check whether the bars have opened above/below the bollingers, depending on whether it's a buy or sell signal. We ensure that we only get one sell at a time, that is, as soon asthe conditions are checked, whether met or not, we change the alert variable so we can't get the same signal. This ensures that if we take a trade and close straightaway, we won't get another buy on the same bar, next tick, as essentially the condtions will still be met. If the conditions are met we change the crossing variable to 0, to ensure we're not looking for signals anymore, then set a buy or sell variable 0, to say we have a signal and to start looking for a trade. We check that the bar is within the setuplength, defined by the user, then check whether price action has broken, if so, we take a trade. If we don't meet the criteria, but within the range, we increment the bar counter by one per bar, again, using the NewBar function to ensure it only happens once a bar, not each tick. If the bar count is outside the range, it's changed to 100 to make sure it's way over the range. When a trade is closed, we make the crossing variable 0 to ensure that if the MACD crossed during a trade it doesn't open a new order as soon as we close a trade.
Lines of code are printed at each tick, stating the crossing variable, alert variable, sell and buy counters. Essentially if nothing is happening it should say that both variables are 0 and counts are 100. When the MACD crosses crossing should be 1 and last alert should be 0. If we meet the criteria for a trade, that count should be 0, last alert equal to 1 or 2 depending on the trade and crossing is 0. Sell/Buy signal should also be printed. Then the count should change if the criteria isn't met, if it is, the count will be set back to 100, "enter trade" will be printed, trade will be executed, then "trade entered" is printed. Until the order is closed, the counts will remain 100, the crossing variable and alert can change as the MACD crosses, but will have no effect. Order closed will be printed when an order is closed, with the counts put to 100 and the variables set to 0.
The new code with all the comments and print statements is attached now. It seems to give buy and sell signals as the chart runs, but will not give sell signals in the backtester, which is a problem as i can't logically find a reason why it shouldn't take any. It seems to print enter trade and trade entered, meaning it's completing that chunk of code, but doesn;t open a trade, as if it's skipping that line of code for no apparent reason.
Thanks in advance for any insight you can provide,