AssignValueColor error when writing my script?

S

sumihiko

New member
Dear everyone, I'm stuck with coloring.
Something goes wrong with my script as follows

def MB = MidBand;
MB.DefineColor("Up", CreateColor(0, 0, 204)); #The color is Blue-ish
MB.DefineColor("Down", CreateColor(255, 0, 0)); #The color is Orange-ish

MB.AssignValueColor( if MB > MB [1] and MB == MB[Z] then MB.Color("Up") else if MB < MB[Z] and MB ==MB[Z] then MB.Color("Down") else double.nan);

I want MB=MB[1] to stay Blue after MB > MB[1] until it hits MB < MB[1]
I want MB=MB[1] to say Orange after MB < MB[1] until it hits MB > MB[1]

MB.AssingValueColor → it's got errors.
Can anyone please help me? Thanks in advance!!!
 
BenTen

BenTen

Administrative
Staff
VIP
Looking at the your script, I think it has something to do with MB[Z].
 
S

sumihiko

New member
Looking at the your script, I think it has something to do with MB[Z].
@BenTen

Thanks for replying,

MB > MB[1] → current MB bar value is greater than the last 1-bar of MB, how could that be wrong?
 
BenTen

BenTen

Administrative
Staff
VIP
@sumihiko I don't think you can put a letter inside []. It has to be a numerical value, or did you put that letter there just as an example?
 
T

tomsk

Well-known member
VIP
@sumihiko Let's start over - please articulate your conditions for the AssignValueColor - your description as posted above is unclear. On top of that do post your complete code rather than fragments so that @BenTen or anyone else responding to this would have prior context.
 
S

sumihiko

New member
@tomsk
Sorry, type error, it should be like this ↓
MB.DefineColor("Up", CreateColor(0, 0, 204)); #The color is Blue-ish
MB.DefineColor("Down", CreateColor(255, 0, 0)); #The color is Orange-ish

MB.AssignValueColor( if MB > MB [1] and MB == MB[1] then MB.Color("Up") else if MB < MB[1] and MB ==MB[1] then MB.Color("Down") else double.nan);

I want MB=MB[1] to stay Blue after MB > MB[1] until it hits MB < MB[1]
I want MB=MB[1] to say Orange after MB < MB[1] until it hits MB > MB[1]

MB.AssingValueColor → it's got errors.
Can anyone please help me? Thanks in advance!!!
 
T

tomsk

Well-known member
VIP
@sumihiko it appears that contrary to my earlier post, you still have not defined your complete code. The variable MB as yet is undefined and you're attempting to reference that. Unfortunately despite several attempts to do so, your condition for the AssignValueColor seems to be overly complex. One typical way most people define multi conditions using the example of an EMA is as follows:

Code:
plot EMA = ExpAverage(close,21);
EMA.AssignValueColor(if EMA > EMA[1] then Color.GREEN else if EMA < EMA[1] then Color.RED else Color.YELLOW);
Presumably something similar to this is what you might be seeking. In my example here there are exactly 3 conditions:

EMA > EMA[1]
EMA < EMA[1]
EMA == EMA [1]
 
S

sumihiko

New member
@sumihiko it appears that contrary to my earlier post, you still have not defined your complete code. The variable MB as yet is undefined and you're attempting to reference that. Unfortunately despite several attempts to do so, your condition for the AssignValueColor seems to be overly complex. One typical way most people define multi conditions using the example of an EMA is as follows:

Code:
plot EMA = ExpAverage(close,21);
EMA.AssignValueColor(if EMA > EMA[1] then Color.GREEN else if EMA < EMA[1] then Color.RED else Color.YELLOW);
Presumably something similar to this is what you might be seeking. In my example here there are exactly 3 conditions:

EMA > EMA[1]
EMA < EMA[1]
EMA == EMA [1]
@tomsk

Thanks, but could:

EMA crosses above EMA[1]
EMA crosses below EMA[1]

the above script work? cuz I want EMA to stay GREEN once it's greater than or crosses above EMA[1]
vice-versa EMA to stay RED once it's lesser than or crosses below EMA[1]?
 
T

tomsk

Well-known member
VIP
@sumihiko Think you might be confused between an event and a state. Consider the following two conditions

EMA crosses above EMA[1]
EMA greater than EMA[1]

The first statement is an event while the second statement is a state. You won't be able to simultaneously test both as it defies logic.
You wrote above that "EMA to stay GREEN once it's greater than or crosses above EMA[1]"
Well, if EMA is already greater than EMA[1], it will never cross above EMA[1], and so that condition will never be true
A similar logic would apply to your second condition in your post above. This is where you're running into issues

Now I can see why the past few posts have been confusing. At this point my suggestion to you is to rethink/restructure your logic.
Hope that helps
 
Last edited:
S

sumihiko

New member
@sumihiko Think you might be confused between an event and a state. Consider the following two conditions

EMA crosses above EMA[1]
EMA greater than EMA[1]

The first statement is an event while the second statement is a state. You won't be able to simultaneously test both as it defies logic.
You wrote above that "EMA to stay GREEN once it's greater than or crosses above EMA[1]"
Well, if EMA is already greater than EMA[1], it will never cross above EMA[1], and so that condition will never be true
A similar logic would apply to your second condition in your post above. This is where you're running into issues

Now I can see why the past few posts have been confusing. At this point my suggestion to you is to rethink/restructure your logic.
Hope that helps
@tomsk
Thanks for the reply.
I'll stay with EMA > EMA[1] and EMA < EMA[1].

But, I also want to make it EMA >=EMA[1] and EMA <=EMA[1].

I mean EMA is greater or equals to EMA[1] (and EMA is lesser or equals to EMA[1]). The logic is as follows:

value
EMA[1] 10
EMA 11 --->therefore EMA > EMA[1], color changes to GREEN and shows breaking signal "UP"

EMA 11
EMA[-1] 12 --->therefore EMA[-1] > EMA, color stays GREEN and no breaking signal is shown

EMA[-1] 12
EMA[-2] 12 ---->therefore EMA[-2]=EMA[-1], color stays GREEN and no breaking signal is shown

EMA[-2] 12
EMA[-3] 11 ---->therefore EMA[-3]<EMA[-2], color changes to RED and shows breaking signal "DOWN"

EMA[-3] 11
EMA[-4] 10 --->therefore EMA[-4] < EMA[-3], color stays RED and no breaking signal is shown

EMA[-4] 10
EMA[-5] 10 --->therefore EMA[-5] = EMA[-4], color stays RED and no breaking signal is shown




↑ In the above case, I come up with the following script ↓ but something's wrong:
1st wrong → if statement, can you help me fix this issue?
2nd wrong → there are too many "UPs" and "Downs" signals all the way → I just want to have the very first UP and DOWN signal, can you help how to fix the excess signals? Thanks a million!

### EMA >= EMA[1] turn to (Green) and EMA <=EMA[1] turn to red ###

def Cond = EMA > EMA[1];
def Cond2 =EMA < EMA[1];
MB.AssignValueColor(if cond then Color.GREEN else if cond2 then Color.RED else double.nan);

### Breaking out Signals ###

plot UpSignal = EMA > EMA[1];
plot DownSignal = EMA < EMA[1];

UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);

UpSignal.Color.GREEN;
UpSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
DownSignal.Color.RED;
DownSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
UpSignal.SetLineWeight(5);
DownSignal.SetLineWeight(5);
 
Last edited:
S

sumihiko

New member
Dear everyone, I'm stuck with coloring.
Something goes wrong with my script as follows

plot MB = MidBand;
MB.DefineColor("Up", CreateColor(0, 0, 204)); #The color is Blue-ish
MB.DefineColor("Down", CreateColor(255, 0, 0)); #The color is Orange-ish

MB.AssignValueColor( if MB >= MB [1] then MB.Color("Up") else if MB <= MB[1] then MB.Color("Down") else double.nan);

I want MB=MB[1] to stay Blue after MB > MB[1] until it hits MB < MB[1]
I want MB=MB[1] to say Orange after MB < MB[1] until it hits MB > MB[1]


↑↑↑ The above thinkscript is based on the following logic: ↓↓↓

value
MB[1] 10
MB[0] 11 --->therefore MB[0] > MB[1], color changes to GREEN and shows breaking signal "UP"

MB[0] 11
MB[-1] 12 --->therefore MB[-1] > MB[0], color stays GREEN and no breaking signal is shown

MB[-1] 12
MB[-2] 12 ---->therefore MB[-2]=MB[-1], color stays GREEN and no breaking signal is shown

MB[-2] 12
MB[-3] 11 ---->therefore MB[-3]<MB[-2], color changes to RED and shows breaking signal "DOWN"

MB[-3] 11
MB[-4] 10 --->therefore MB[-4] < MB[-3], color stays RED and no breaking signal is shown

MB[-4] 10
MB[-5] 10 --->therefore MB[-5] = MB[-4], color stays RED and no breaking signal is shown


↑↑↑ In the above case, I come up with the following script ↓ ↓↓but something's wrong:
1st wrong → if statement, can anytone help me fix this issue?
2nd wrong → there are too many "UPs" and "Downs" signals all the way → I just want to have the very first UP and DOWN signal, can anyone help me how to fix the excess signals? Thanks a million!

### MB >= MB[1] turn to (Green) and MB <=MB[1] turn to red ###

def Cond = MB > MB[1];
def Cond2 = MB < MB[1];
MB.AssignValueColor(if cond then Color.GREEN else if cond2 then Color.RED else double.nan);

### Breaking out Signals ###

plot UpSignal = MB > MB[1];
plot DownSignal = MB < MB[1];

UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);

UpSignal.Color.GREEN;
UpSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
DownSignal.Color.RED;
DownSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
UpSignal.SetLineWeight(5);
DownSignal.SetLineWeight(5);

Check here for the plot Excessiv Signals
 

Similar threads

Top