I’m working on a code that should only buy when the condition occurs for the second or more times. Unfortunately, I’m facing an issue where the counter doesn’t seem to increase and remains at 1, causing the “IF counter>x” condition to always return the same result, regardless of x.
Oncecounter=0// counter must have an initial value.
If you don’t do this, counter will have an undefined value which probably is a huge negative number. So it will add up, but only when a new day has started, it will reset to 0 for the first time.
Maybe what fifi added helps too ( I don’t readily see why he does it) and possibly it is so that both amendments are required to get it going.
You can let your code end with
Then you can see what values these variables receive.
Trading on leveraged financial instruments may expose you to risk of loss greater than your deposits and is only suitable for experienced clients with the financial means to bear such risk. Trading on foreign exchange instruments (Forex) and contracts for difference (CFDs) is highly speculative and particularly complex and comes with a high level of risk due to leverage. You must ensure that you understand how these instruments work and that you can afford to take the high risk of losing your money. No information on this site is investment advice or a solicitation to buy or sell any financial instruments.