Reset Variable

Questions about MultiCharts and user contributed studies.
wgmh_
Posts: 1
Joined: 11 Mar 2014
Has thanked: 1 time

Reset Variable

Postby wgmh_ » 11 Mar 2014

Hi,

I'm having some trouble resetting variables to 0. I have noticed the following pieces of code have different results but I don't understand why.

This code results in variable1 always being 0 even when MP = 1 or -1 and Condition = True:

Code: Select all

IF marketposition = 1 AND Condition = True THEN

variable1 = 1

ELSE
variable1 = 0 ;


IF marketposition = -1 AND Condition = True THEN

variable1 = -1

ELSE
variable1 = 0 ;
Whereas this code results in variable1 = 1 when MP =1 and variable1 = 0 when MP = 0 (i.e. what is intended):

Code: Select all

IF marketposition = 1 AND Condition = True THEN

variable1 = 1

ELSE IF marketposition = -1 AND Condition = True THEN

variable1 = -1

ELSE
variable1 = 0 ;
Why does the first block of code not result in variable1 = 1 when MP = 1 and variable1 = -1 when MP = -1?

Thankyou for your help.

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 559 times

Re: Reset Variable

Postby Andrew MultiCharts » 12 Mar 2014

Hello wgmh_,
Let's focus on the first block of code:

Code: Select all

IF marketposition = 1 AND Condition = True THEN

variable1 = 1

ELSE
variable1 = 0 ;


IF marketposition = -1 AND Condition = True THEN

variable1 = -1

ELSE
variable1 = 0 ;
Let's assume marketposition = 1 and Condition = True, the the variable1 is set to 1. ELSE variable1 = 0 ; part is not true. The calculation of the code doesn't stop at this point, it continues: it checks if marketposition = -1 and Condition = True. Marketposition <> -1, marketposition = 1. It means variable1 is not set to -1. ELSE variable1 = 0 is true. The resulting variable1 is 0.


Return to “MultiCharts”