If you want to define a global variable, why don't you always assign a value to the function that's behind it?

Author: dahan, Created: 2018-11-13 17:27:58, Updated: 2018-11-14 09:11:29

var STATE_IDLE = 0;
var STATE_LONG = 1;
var STATE_SHORT = 2;
var State = STATE_IDLE;

function Trade(currentState, nextState) {

    if (currentState === STATE_IDLE) {
        if (nextState === STATE_LONG) {
            exchange.SetDirection("buy");
            AmountOP = InitAccount.Stocks * 10 / 2;
            exchange.Buy(_C(exchange.GetTicker).Sell, AmountOP);
            State = STATE_LONG;
        }

There are other conditions behind the execution that change the value of the state, but why is it always 0 and not changing?


More

The little kittyIf you want to see if the code is complete, so you can't locate the problem, you can output the value after the change and see if you can locate the problem under normal debugging.

The Little DreamThis looks very much like a Dual Thrust futures strategy, where the State does not change the logic that should not trigger the revaluation of the State.