Covert iff from v4 to Pinescript v5 - type-conversion

I'm trying my best to understand how to convert code form v4 to v5 and I have some successful attempts on some easy scripts, but I don't have any code skills, I'm trying to learn by myself the thing I need, but and I miss the basic to understand well what I'm doing really.
So I'm asking you if you can help me with this, so I can learn from this too.
Thank you
///....
xATRTrailingStop = 0.0
xATRTrailingStop := iff(src > nz(xATRTrailingStop[1], 0) and src[1] > nz(xATRTrailingStop[1], 0), max(nz(xATRTrailingStop[1]), src - nLoss),
iff(src < nz(xATRTrailingStop[1], 0) and src[1] < nz(xATRTrailingStop[1], 0), min(nz(xATRTrailingStop[1]), src + nLoss),
iff(src > nz(xATRTrailingStop[1], 0), src - nLoss, src + nLoss)))
pos = 0
pos := iff(src[1] < nz(xATRTrailingStop[1], 0) and src > nz(xATRTrailingStop[1], 0), 1,
iff(src[1] > nz(xATRTrailingStop[1], 0) and src < nz(xATRTrailingStop[1], 0), -1, nz(pos[1], 0)))
///...
I tried to convert "iff" to a ternary operator, I'm sorry if that's a mess :/
xATRTrailingStop = 0.0
xATRTrailingStop := (src > nz(xATRTrailingStop[1]) and src[1] > nz(xATRTrailingStop[1]) ? math.max(nz(xATRTrailingStop[1]), src - nLoss) :
(src < nz(xATRTrailingStop[1], 0) and src[1] < nz(xATRTrailingStop[1], 0) ? min(nz(xATRTrailingStop[1]), src + nLoss) :
(src > nz(xATRTrailingStop[1], 0), src - nLoss, src + nLoss))

You can convert to v5 by clicking on the left of the pinescript editor :
The code of the v5 will be like this :
xATRTrailingStop = 0.0
iff_1 = src > nz(xATRTrailingStop[1], 0) ? src - nLoss : src + nLoss
iff_2 = src < nz(xATRTrailingStop[1], 0) and src[1] < nz(xATRTrailingStop[1], 0) ? math.min(nz(xATRTrailingStop[1]), src + nLoss) : iff_1
xATRTrailingStop := src > nz(xATRTrailingStop[1], 0) and src[1] > nz(xATRTrailingStop[1], 0) ? math.max(nz(xATRTrailingStop[1]), src - nLoss) : iff_2
pos = 0
iff_3 = src[1] > nz(xATRTrailingStop[1], 0) and src < nz(xATRTrailingStop[1], 0) ? -1 : nz(pos[1], 0)
pos := src[1] < nz(xATRTrailingStop[1], 0) and src > nz(xATRTrailingStop[1], 0) ? 1 : iff_3

Related

Pine script issues on checking alert conditions when breaching a Fibonacchi line

I am trying to set an alert when two conditions are met. For the UP case, I want to check first for the price to break above a certain level (UPLabel is true), then I want to set off the alarm when the price is breaching the Fib line (BreachUpFiboAlert is true). Somehow, the code is not working properly after I tried to check the conditions. I am quite new to the Pine Script so, any pointers will be greatly appreciated.
if barstate.isconfirmed and nySession == false and nyaSession == false and nyeSession == false
HHcheck = high[LastBar-1]
LLcheck = low[LastBar-1]
HHidrcheck = close[LastBar-1]
LLidrcheck = open[LastBar-1]
HfiboVal = HHidrcheck
LfiboVal = LLidrcheck
if useDRforFibo
HfiboVal := HHcheck
LfiboVal := LLcheck
if close[LastBar-1] > open[LastBar-1]
HHidrcheck := close[LastBar-1]
LLidrcheck := open[LastBar-1]
else
HHidrcheck := open[LastBar-1]
LLidrcheck := close[LastBar-1]
for i = 0 to FirstBar-LastBar
if high[LastBar+i] > HHcheck
HHcheck := high[LastBar+i]
if low[LastBar+i] < LLcheck
LLcheck := low[LastBar+i]
if close[LastBar+i] > open[LastBar+i] and close[LastBar+i] > HHidrcheck
HHidrcheck := close[LastBar+i]
if close[LastBar+i] < open[LastBar+i] and open[LastBar+i] > HHidrcheck
HHidrcheck := open[LastBar+i]
if close[LastBar+i] > open[LastBar+i] and open[LastBar+i] < LLidrcheck
LLidrcheck := open[LastBar+i]
if close[LastBar+i] < open[LastBar+i] and close[LastBar+i] < LLidrcheck
LLidrcheck := close[LastBar+i]
if UseWick
if high > (HHcheck + ((HHcheck/100)*BreachThreshold)) and high[1] <= HHcheck
if not UPLabel and not DOWNLabel
UPLabel := true
BreachesUP := BreachesUP+1
if low < (LLcheck - ((LLcheck/100)*BreachThreshold)) and low[1] >= LLcheck
if not UPLabel and not DOWNLabel
DOWNLabel := true
BreachesDown := BreachesDown+1
else
if close > (HHcheck + ((HHcheck/100)*BreachThreshold)) and close[1] <= HHcheck
if not UPLabel and not DOWNLabel
UPLabel := true
BreachesUP := BreachesUP+1
if close < (LLcheck - ((LLcheck/100)*BreachThreshold)) and close[1] >= LLcheck
if not UPLabel and not DOWNLabel
DOWNLabel := true
BreachesDown := BreachesDown+1
for i = 0 to LastBar
if UseWick
if high[i] > (HHcheck + ((HHcheck/100)*BreachThreshold)) and high[i+1] <= HHcheck
BreachesUP := BreachesUP+1
if low[i] < (LLcheck - ((LLcheck/100)*BreachThreshold)) and low[i+1] >= LLcheck
BreachesDown := BreachesDown+1
// add check if the wick is breaching the fiboAlertLevels
if high[i] > LfiboVal + ((HfiboVal-LfiboVal)*fiboDownAlertLevel) and high[i+1] <= LfiboVal + ((HfiboVal-LfiboVal)*fiboDownAlertLevel)
BreachesDownFiboAlert := BreachesDownFiboAlert+1
BreachDownFiboAlert := true
if low[i] < LfiboVal + ((HfiboVal-LfiboVal)*fiboUpAlertLevel) and low[i+1] >= LfiboVal + ((HfiboVal-LfiboVal)*fiboUpAlertLevel)
BreachesUpFiboAlert := BreachesUpFiboAlert+1
BreachUpFiboAlert := true
else
if close[i] > (HHcheck + ((HHcheck/100)*BreachThreshold)) and close[i+1] <= HHcheck
BreachesUP := BreachesUP+1
if close[i] < (LLcheck - ((LLcheck/100)*BreachThreshold)) and close[i+1] >= LLcheck
BreachesDown := BreachesDown+1
// add check if the price close is breaching the fiboAlertLevels
if DOWNLabel
if close[i] > LfiboVal + ((HfiboVal-LfiboVal)*fiboDownAlertLevel) and close[i+1] <= LfiboVal + ((HfiboVal-LfiboVal)*fiboDownAlertLevel)
BreachesDownFiboAlert := BreachesDownFiboAlert+1
BreachDownFiboAlert := true
if UPLabel
if close[i] < LfiboVal + ((HfiboVal-LfiboVal)*fiboUpAlertLevel) and close[i+1] >= LfiboVal + ((HfiboVal-LfiboVal)*fiboUpAlertLevel)
BreachesUpFiboAlert := BreachesUpFiboAlert+1
BreachUpFiboAlert := true
I attached a screenshot describing what I want to do. I also tried to plotshape per the code below on the graph to visualise it. Unfortunately, the plot showed that the condition, BreachUp&Down, check doesn't work.
plotshape(BreachUpFiboAlert, title="Breach Fib Up Alert", text="", style=shape.triangleup, location=location.belowbar, color=color.rgb(8, 73, 253), textcolor=color.white) plotshape(BreachDownFiboAlert, title="Breach Fib Down Alert", text="", style=shape.triangledown, location=location.abovebar, color=color.rgb(255, 1, 213), textcolor=color.white)
I'm suspecting that the for loop causing me this problem but I am not quite sure how to fix this. Note that you can look at the entire code here. https://www.tradingview.com/script/K2NPoa5y-Lukenum-TheMas7er-V-4-5min-promuckaj/

How do I plot a buy alert on an array anytime a bar reaches 100 upon close of that bar? I am using the "Supertrend Oscillator" in pinescript

I've been at this for hours and I just can't figure it out. I've tried searching all over and watching videos. Here's code to the script I am working with. it's called Supertrend Oscillator by LuxAlgo on tradingview.
atr = ta.atr(osclength) * mult
up = hl2 + atr
dn = hl2 - atr
upper := src[1] < upper[1] ? math.min(up, upper[1]) : up
lower := src[1] > lower[1] ? math.max(dn, lower[1]) : dn
trend := src > upper[1] ? 1 : src < lower[1] ? 0 : trend[1]
Spt = trend * lower + (1 - trend) * upper
//----
ama = 0.
osc = math.max(math.min((src - Spt) / (upper - lower), 1), -1)
alpha = math.pow(osc, 2) / osclength
ama := nz(ama[1] + alpha * (osc - ama[1]), osc)
hist = ta.ema(osc - ama, smooth)
//----
fix_css = osc > 0 ? #0cb51a : #ff1100
var_css = osc > 0 ? array.get(up_col, math.round(osc * 99)) : array.get(dn_col, math.round(osc * -1 * 99))
sig_css = ama > 0 ? #2157f3 : #673ab7
plot(fixed ? osc * 100 : na, 'Main Fixed', fix_css, 1, plot.style_area)
plot(fixed ? na : osc * 100, 'Main Transp', var_css, 1, plot.style_columns, editable=false)
plot(hist * 100, 'Histogram', color.new(#808080, 40), 1, plot.style_area)
plot(ama * 100, 'Signal', sig_css)
//----
a = hline(80)
b = hline(-80)
fill(a, b, color.new(#2157f3, 90))
//----
css = osc > 0 ? #ff1100 : #0cb51a
sig = ta.change(math.sign(osc)) ? osc * -100 : na
plot(show_ln ? sig : na, color=css)
//----
n = bar_index
cross = ta.cross(src, Spt)
x2 = ta.valuewhen(cross, n, 0)
//----
false_buy = ta.valuewhen(ta.crossunder(src, Spt), src, 0) < ta.valuewhen(ta.crossover(src, Spt), src, 0)
false_sell = ta.valuewhen(ta.crossover(src, Spt), src, 0) > ta.valuewhen(ta.crossunder(src, Spt), src, 0)
num = ta.cum(cross and (false_buy or false_sell) ? 1 : 0)
den = ta.cum(cross ? 1 : 0)
per = num / den * 100
//----
if barstate.islast and show_ln
line.delete(line.new(x2, math.sign(osc) * -100, n, osc * 100, color=osc < 0 ? #ff1100 : #0cb51a)[1])
if show_lb
if ta.crossover(src, Spt)
txt = false_sell ? '❌' : '✔️'
label.new(x2,-80,txt,color=#00000000,style=label.style_label_up,textcolor=color.gray,textalign=text.align_center)
if ta.crossunder(src, Spt)
txt = false_buy ? '❌' : '✔️'
label.new(x2,80,txt,color=#00000000,style=label.style_label_down,textcolor=color.gray,textalign=text.align_center)
if barstate.islast and show_per
txt = '❌' + str.tostring(per, '#.##') + '%'
label.delete(label.new(n, osc, txt, color=#00000000, style=label.style_label_left, textcolor=color.gray, textalign=text.align_left)[1])
How do I make it so a "buy" alert displays on the chart anytime a bar closes with an oscillator value reaching 100 or more?

Programming on the Nintendo DS - issue with collisions

Sorry if this question has already been asked, but I have not managed to find any advice on the internet for my issue. I am currently trying to program a little game on the Nintendo DS, in which the player has to move a sprite (currently a square) until it reaches the exit. For this, I use a sprite I have included using a grit file, and also a background enabled in tiled mode. However, I am having a problem when it comes to checking if the sprite is going to collide with a wall. Here is the code I have both for the background configuration (where I declare the tiles and the map) and also for the sprite movements (I didn't add the condition for all cases yet, as it didn't work well) :
void configureMaze_Sub() {
int row, col;
for (row = 0; row < 24; row ++) {
for (col = 0; col < 32; col ++) {
BG_MAP_RAM_SUB(3)[row * 32 + col] = 1;
if (col == 15 && (row != 12 && row !=4 && row != 19)) {
BG_MAP_RAM_SUB(3)[row * 32 + col] = 0;
}
if ((row == 1 || row == 22) && (col > 2 && col < 29)) {
BG_MAP_RAM_SUB(3)[row * 32 + col] = 0;
}
if ((col == 3 || col == 28) && (row > 1 && row < 22 && row != 12)) {
BG_MAP_RAM_SUB(3)[row * 32 + col] = 0;
}
if ((row == 3 || row == 20) && (col > 4 && col < 27)) {
BG_MAP_RAM_SUB(3)[row * 32 + col] = 0;
}
if ((col == 5 || col == 26) && (row != 9 && row != 15 && row > 3 && row < 20)) {
BG_MAP_RAM_SUB(3)[row * 32 + col] = 0;
}
if (row == 8 && (col > 5 && col < 15)) {
BG_MAP_RAM_SUB(3)[row * 32 + col] = 0;
}
if (row == 16 && (col > 15 && col < 26)) {
BG_MAP_RAM_SUB(3)[row * 32 + col] = 0;
}
if ((row == 12) && (col > 5 && col < 26)) {
BG_MAP_RAM_SUB(3)[row * 32 + col] = 0;
}
}
}
}
void gameplayMaze() {
int x = 103, y = 41, keys;
int maze_success = 0;
while (maze_success == 0) {
scanKeys();
keys = keysHeld();
int xmod = x / 8;
int ymod = x / 8;
if ((keys & KEY_RIGHT) && BG_MAP_RAM_SUB(3)[xmod + 32 * ymod] == 1) {
x++;
printf("%d \n", x);
}
if ((keys & KEY_LEFT) && BG_MAP_RAM_SUB(3)[xmod + 32 * ymod] == 1) {
x--;
}
if (keys & KEY_UP) {
y--;
}
if (keys & KEY_DOWN) {
y++;
}
oamSet(&oamSub,
0,
x, y,
0,
0,
SpriteSize_8x8,
SpriteColorFormat_256Color,
gfxSub,
-1,
false,
false,
false, false,
false
);
swiWaitForVBlank();
oamUpdate(&oamSub);
}
The main problem I have is to try to change from the coordinates of the tiles (which are 8x8) to the ones of the map, as for the coordinates of the sprite (256x192). If any of you have any hint to help me, I would be very grateful! I am still new to programming on the NDS, so I am still struggling to get the hang of it.

Button should set the text in the webpage. What to do?

I am having problem in using button with function. I know only about java application and I am trying to learn HTML and JavaScript. I want the button to set the text present in conditional statement on to the webpage and conditions are based on select box.
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<HTML>
<HEAD>
<TITLE>P-Block Chemical Reactions</TITLE>
</HEAD>
<BODY>
<CENTER><FONT FACE="TIMES NEW ROMAN" COLOR="GREEN" size="50"><b><u>P-Block Chemical Reactions</u></b></font>
<br><br><br><h2>Structure of P-Block</h2><br>
<img src="http://2.bp.blogspot.com/-HNGbTyDrWso/UAGMqI2uY6I/AAAAAAAAAC0/mSWX5ZivvDk/s1600/Use%252Bnowwwww-723799.jpg">
<br></center>
<br>
<form>
<select id="Groups" name="Groups" >
<option value="1">Group 13</option>
<option value="2">Group 14</option>
<option value="3">Group 15</option>
<option value="4">Group 16</option>
<option value="5">Group 17</option>
<option value="6">Group 18</option></select>
<button onClick="gr();">See</button></form>
<script type="text/javascript">
function gr()
{
var s = document.getElementById('Groups');
var g = s.options[s.selectedIndex].value;
if (g === 1)
{
document.write("<b><h3>Chemical Reactions for GROUP 13 :</h3></b><br>
< ul type = "disc" >
< li > Reaction with O < sub > 2 < /sub> <br>
Boron is unreactive in crystalline form.Aluminium forms a very thin oxide layer on the surface which protects the metal from further attack. < br > < br >
2E(s) + 3O < sub > 2 < /sub>(g) → 2E<sub>2</sub > O < sub > 3 < /sub>(s)
(E = element) < br > < br >
< li > Reaction with N < sub > 2 < /sub><br>
With dinitrogen at high temperature these elements form nitrides. < br > < br >
2E(s) + N < sub > 2 < /sub>(g) → 2EN(s)
(E = element) < br > < br >
< li > Reaction with acids and alkalies < br >
Boron does not react with acids and alkalies even at moderate temperature, but aluminium dissolves in mineral acids and aqueous alkalies and thus shows amphoteric character. < br > Aluminium dissolves in dilute HCl and liberates dihydrogen. < br > < br >
2Al(s) + 6HCl(aq) → 2Al < sup > 3 + < /sup>(aq) + 6Cl<sup>-</sup > (aq) < br > < br >
However, concentrated nitric acid renders aluminium passive by forming a protective oxide layer on the surface. < br > < br >
Aluminium also reacts with aqueous alkali and liberates dihydrogen. < br > < br >
2Al(s) + 2NaOH(aq) + 6H < sub > 2 < /sub>O(l) → 2Na<sup>+</sup > [Al(OH) < sub > 4 < /sub>]<sup>-</sup > (aq) + 3H < sub > 2 < /sub>(g) <br><br>
< li > Reaction with halogens < br >
These elements react with halogens to form trihalides (except TlI < sub > 3 < /sub>).<br><br>
2E(s) + 3X < sub > 2 < /sub>(g) → 2EX<sub>3</sub > (s) & nbsp; & nbsp; & nbsp; & nbsp; (X = F, Cl, Br, I)
< /ul>");
}
else if (item === 2)
{
document.write("<b><h3>Chemical Reactions for GROUP 14 :</h3></b><br>
< ul type = "disc" >
< li > Reaction with O < sub > 2 < /sub> <br>
All members when heated in oxygen form oxides.There are mainly two types of oxides, i.e., monoxide and dioxide of formula MO and MO < sub > 2 < /sub> respectively. SiO only exists at high temperature. Oxides in higher Oxidation states of elements are generally more acidic than those in lower oxidation states.<br><br> The dioxides : CO<sub>2</sub > , SiO < sub > 2 < /sub> and GeO<sub>2</sub > are acidic, whereas SnO < sub > 2 < /sub> and PbO<sub>2</sub > are amphoteric in nature.Among monoxides, CO is neutral, GeO is distinctly acidic whereas SnO and PbO are amphoteric. < br > < br >
< li > Reaction with water < br >
Carbon, silicon and germanium are not affected by water.Tin decomposes steam to form dioxide and dihydrogen gas. < br > < br >
Sn + 2H < sub > 2 < /sub>O → SnO<sub>2</sub > + 2H < sub > 2 < /sub> <br><br>
Lead is unaffected by water, probably because of a protective oxide film formation. < br > < br >
< li > Reaction with halogen < br >
These elements can form halides of formula MX < sub > 2 < /sub> and MX<sub>4</sub > (where X = F, Cl, Br, I).Except carbon, all other members react directly with halogen under suitable condition to make halides.Most of the MX < sub > 4 < /sub> are covalent in nature. The central metal atom in these halides undergoes sp<sup>3</sup > hybridisation and the molecule is tetrahedral in shape.Exceptions are SnF < sub > 4 < /sub> and PbF<sub>4</sub > , which are ionic in nature. < br > PbI < sub > 4 < /sub> does not exist because Pb-I bond initially formed during the reaction does not release enough energy to unpair 6s<sub>2</sub > electrons and excite one of them to higher orbital to have four unpaired electrons around lead atom.Heavier members Ge to Pb are able to make halides of formula MX < sub > 2 < /sub>. Stability of dihalides increases down the group. Considering the thermal and chemical stability, GeX<sub>4</sub > is more stable than GeX < sub > 2 < /sub>, whereas PbX<sub>2</sub > is more than PbX < sub > 4 < /sub>. Except CCl<sub>4</sub > , other tetrachlorides are easily hydrolysed by water because the central atom can accomodate the lone pair of electrons from oxygen atom of water in d orbital.
< /ul><br><br>");
}
else if (item === 3)
{
document.write("<b><h3>Chemical Reactions for GROUP 15 :</h3></b><br>
< ul type = "disc" >
< li > Reaction with Hydrogen < br >
All the elements of Group 15 form hydrides of the type EH < sub > 3 < /sub> where E = N, P, As, Sb or Bi.<br> The stability of hidrides decreases from NH<sub>3</sub > to BiH < sub > 3 < /sub> which can be observed from their bond dissociation enthalpy. Consequently,the reducing character of the hydrides increases. Ammonia is only a mild reducing agent while BiH<sub>3</sub > is the strongest reducing agent amongst all the hydrides.Basicity also decreases in the order NH < sub > 3 < /sub> > PH<sub>3</sub > & gt; AsH < sub > 3 < /sub> > SbH<sub>3</sub > & ge; BiH < sub > 3 < /sub>.<br><br>
< li > Reaction with Oxygen < br >
All these elements form two types of oxides: E < sub > 2 < /sub>O<sub>3</sub > and E < sub > 2 < /sub>O<sub>5</sub > .The oxide in the higher oxidation state of the element is more acidic than that of lower oxidation state.Their acidic character decreases down the group.The oxides of the type E < sub > 2 < /sub>O<sub>3</sub > of nitrogen and phosphorus are purely acidic, that of arsenic and antimony amphoteric and those of bismuth is predominantaly basic. < br > < br >
< li > Reaction with Halogen < br >
These elements react to form two series of halides: EX < sub > 3 < /sub> and EX<sub>5</sub > .Nitrogen does not form pentahalide due to non - availability of the d - orbitals in its valence shell.Pentahalides are more covalent than trihalides.All the trihalides of these elements except those of nitrogen are stable.In case of nitrogen, only NF < sub > 3 < /sub> is known to be stable. Trihalides except BiF<sub>3</sub > are predominantly covalent in nature. < br > < br >
< li > Reaction with Metal < br >
All these elements react with metals to form their binary compounds exhibiting - 3 oxidation state, such as, Ca < sub > 3 < /sub>N<sub>2</sub > (Calcium nitride), Ca < sub > 3 < /sub>P<sub>2</sub > (Calcium phosphide), Na < sub > 3 < /sub>As<sub>2</sub > (Sodium arsenide), Zn < sub > 3 < /sub>Sb<sub>2</sub > (Zinc antimonide) and Mg < sub > 3 < /sub>Bi<sub>2</sub > (Magnesium bismuthide). < br > < br >
< /ul>");
}
else if (item === 4)
{
document.write("<b><h3>Chemical Reactions for GROUP 16 :</h3></b><br>
< ul type = "disc" >
< li > Reaction with Hydrogen < br >
All the elements of Group 16 form hydrides of the type H < sub > 2 < /sub>E (E = S, Se, Te, Po). Their acidic character increases from H<sub>2</sub > O to H < sub > 2 < /sub>Te. The increse in acidic character can be explained in terms of decrease in bond (H-E) dissociation enthalpy down the group. Owing to the decrease in bond (H-E) dissociation enthalpy down the group, the thermal stability of hydrides also decreases from H<sub>2</sub > O to H < sub > 2 < /sub>Po. All the hydrides except water possess reducing property and this character increases from H<sub>2</sub > S to H < sub > 2 < /sub>Te.<br><br>
< li > Reaction with Oxygen < br >
All these elements form oxides of the EO < sub > 2 < /sub> and EO<sub>3</sub > types where E = S, Se, Te or Po.Ozone (O < sub > 3 < /sub>) and sulphur dioxide (SO<sub>2</sub > ) are gases while selenium dioxide (SeO < sub > 2 < /sub>) is solid. Reducing property of dioxide decreases from SO<sub>2</sub > to TeO < sub > 2 < /sub>. SO<sub>2</sub > is reducing while TeO < sub > 2 < /sub> is an oxidising agent. Besides EO<sub>2</sub > type, sulphur, selenium and tellurium also form EO < sub > 3 < /sub> type oxides (SO<sub>3</sub > , SeO < sub > 3 < /sub>, TeO<sub>3</sub > ).Both types of oxides are acidic in nature. < br > < br >
< li > Reaction with Halogen < br >
Elements of Group 16 form a large number of halides of the type, EX < sub > 6 < /sub>, EX<sub>4</sub > and EX < sub > 2 < /sub> where E is an element of the group and X is a halogen. The stability of the halides decreases in the order F<sup>-</sup > & gt; Cl < sup > - < /sup> > Br<sup>-</sup > & gt; I < sup > - < /sup>. Amongst hexahalides, hexafluorides are the only stable halides. All hexafluorides are in gaseous nature. They have octahedral structure. Sulphur hexafluoride, SF<sub>6</sub > is exceptionally stable for steric reasons. < br >
Amongst tetrafluorides, SF < sub > 4 < /sub> is a gas, SeF<sub>4</sub > a liquid and TeF < sub > 4 < /sub> a solid. These fluorides have sp<sup>3</sup > d hybridisation and thus, have trigonal bipyramidal structures in which one of the equatorial positions is occupied by a lone pair of electrons.This geometry is also regarded as see - saw geometry. < br >
All elements except selenium form dichlorides and dibromides.These dihalides are formed by sp < sup > 3 < /sup> hybridisation and thus, have tetrahedral structure. The well known monohalides are dimeric in nature. Examples are S<sub>2</sub > F < sub > 2 < /sub>, S<sub>2</sub > Cl < sub > 2 < /sub>, S<sub>2</sub > Br < sub > 2 < /sub>, Se<sub>2</sub > Cl < sub > 2 < /sub> and Se<sub>2</sub > Br < sub > 2 < /sub>. These dimeric halides undergo disproportionation as given below: <br><br>
2Se < sub > 2 < /sub>Cl<sub>2</sub > → SeCl < sub > 4 < /sub> + 3Se <br><br>
< /ul>");
}
else if (item === 5)
{
document.write("<li><b><h3>Chemical Reactions for GROUP 17 :</h3></b><br>
< ul type = "disc" >
< li > Reaction with Hydrogen < br >
They all react with hydrogen to give hydrogen halides but affinity for hydrogen decreases from fluorine to iodine.They dissolve in water to form hydrohali acids.The acidic strength of these acids varies in the order: HF & lt; HCl & lt; HBr & lt; HI.The stability of these halides decreases down the group due to decrease in bond (H - X) dissociation enthalpy in the order: H - F & gt; H - Cl & gt; H - Br & gt; H - I. < br > < br >
< li > Reaction with Oxygen < br >
Halogens form many oxides with oxygen but most of them are unstable.Fluorine forms two oxides OF < sub > 2 < /sub>, O<sub>2</sub > F < sub > 2 < /sub>. However, only OF<sub>2</sub > is thermally stable at 298 K.These oxides are essentially oxygen fluorides because of the higher electronegativity of fluorine than oxygen.Both are strong fluorinating agents.O < sub > 2 < /sub>F<sub>2</sub > oxidises plutonium to PuF < sub > 6 < /sub> and the reaction is used in removing plutonium as PuF<sub>6</sub > from spent nuclear fuel. < br >
Chlorine, bromine and iodineChlorine, bromine and iodine form oxides in which the oxidation
states of these halogens range from + 1 to + 7. A combination of kinetic and thermodynamic factors lead to the generally decreasing order of stability of oxides formed by halogens, I & gt; Cl & gt; Br.The higher oxides of halogens tend to be more stable than the lower ones. < br >
Chlorine oxides, Cl < sub > 2 < /sub>O, ClO<sub>2</sub > , Cl < sub > 2 < /sub>O<sub>6</sub > and Cl < sub > 2 < /sub>O<sub>7</sub > are highly reactive oxidising agents and tend to explode.ClO < sub > 2 < /sub> is used as a bleaching agent for paper pulp and textiles and in water treatment.<br>
The bromine oxides, Br < sub > 2 < /sub>O, BrO<sub>2</sub > , BrO < sub > 3 < /sub> are the least stable halogen oxides (middle row anomally) and exist only at low temperatures. They are very powerful oxidising agents. The iodine oxides, I<sub>2</sub > O < sub > 4 < /sub>, I<sub>2</sub > O < sub > 5 < /sub>, I<sub>2</sub > O < sub > 7 < /sub> are insoluble solids and
decompose on heating.I < sub > 2 < /sub>O<sub>5</sub > is a very good oxidising agent and is
used in the estimation of carbon monoxide. < br > < br >
< li > Reaction with Metals < br >
Halogens react with metals to form metal halides.For example, bromine reacts with magnesium to give magnesium bromide. < br > < br >
Mg(s) + Br < sub > 2 < /sub>(l) → MgBr<sub>2</sub > (s) < br > < br >
The ionic character of the halides decreases in the order MF & gt;
MCl & gt; MBr & gt; MI where M is a monovalent metal.If a metal exhibits
more than one oxidation state, the halides in higher oxidation
state will be more covalent than the one in lower oxidation state.
For example, SnCl < sub > 4 < /sub>, PbCl<sub>4</sub >
, SbCl < sub > 5 < /sub> and UF<sub>6</sub >
are more covalent than SnCl < sub > 2 < /sub>
, PbCl < sub > 2 < /sub>, SbCl<sub>3</sub >
and UF < sub > 4 < /sub> respectively.<br><br>
< li > Reaction with Halogens < br >
Halogens combine amongst themselves to form number of compounds known as interhalogens of the types XX < sup > ` < /sup>, XX<sup>`</sup > < sub > 3 < /sub>, XX<sup></sup > < sub > 5 < /sub> and XX<sup>`</sup > < sub > 7 < /sub> where X is a larger size halogen and X<sup>`</sup > is a smaller size halogen. < br > For example: & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; I < sub > 2 < /sub> + Cl<sub>2</sub > & nbsp; → 2ICl < br > & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; (equimolar) < br > < br >
< /ul>");
}
}
</script>
</body>
</html>
Pastebin code
Problems I had to fix;
< br > turns in to plain text: < br > . Use this instead for ALL the HTML tags: <br> without the spaces.
if (item === 2) ???? Item was not defined, had to change it to if (g === "2") ; Please note that "2" is not the same as 2
Applied a classname group to every div; to Hide them whenever the gr() is called.
Goodluck, Jeroen
The problem is in the document.write
You can't do: document.write("")
The javascript thinks website.html is a variable
In your code:
document.write("<b><h3>Chemical Reactions for GROUP 13 :</h3></b><br>
< ul type = "disc" >
It expects "disc" to be a variable
You either can encode all of the " symbols, or put the text in divs and show them when you select an option.
Also; with document.write you can't use [enter] to prettify your code.
Your best bet is placing the text in separate divs and showing/hiding them whenever you hit the see button !
Jeroen

Nyquist criterion - undefined variable in algorithm

I write an algorithm that checks the stability of the closed system of the Nyquist criterion (http://en.wikipedia.org/wiki/Nyquist_stability_criterion)
function answear=stability(re,im)
%% Function check stability of system
%re is real part of transmitation
%im is imagine part of transmitation
%% Check number of vectors elements
re(end +1:5) = 0;
im(end +1:5) = 0;
if( length(re) > length(im))
root = length(re);
else
root = length(im);
end
for w=1:root
tran(w) = re(1) + re(2)*w.^1 + re(3)*w.^2 + re(4)*w.^3 + re(5)*w.^4 +1i*(...
im(1) + im(2)*w.^1 + im(3)*w.^2 + im(4)*w.^3 +im(5)*w.^4);
end
%% Algorithm
switch root
case 0
exist('Write nonzero numbers', 'var')
case 1
for w=1:length(w)
if( real(tran(w)) > 0 && imag(tran(w)) > 0)
answear=1;
else
answear=0;
end
end
case 2
for w=1:length(w)
if( real(tran(w)) > 0 && imag(tran(w)) > 0)
if( real(tran(w)) < 0 && imag(tran(w)) > 0)
answear=1;
else
answear=0;
end
end
end
case 3
for w=1:length(w)
if( real(tran(w)) > 0 && imag(tran(w)) > 0)
if( real(tran(w)) < 0 && imag(tran(w)) > 0)
if( real(tran(w)) < 0 && imag(tran(w)) < 0)
answear=1;
else
answear=0;
end
end
end
end
case 4
for w=1:length(w)
if( real(tran(w)) > 0 && imag(tran(w)) > 0)
if( real(tran(w)) < 0 && imag(tran(w)) > 0)
if( real(tran(w)) < 0 && imag(tran(w)) < 0)
if( real(tran(w)) > 0 && imag(tran(w)) < 0)
answear=1;
else
answear=0;
end
end
end
end
end
end
%% Answear
if answear==1
disp('System unstable')
else
disp('System stable')
end
plot(real(tran),imag(tran))
grid on
end
Function returns
Undefined function or variable "answear".
Error in stability (line 87) if answear==1
So the algorithm is badly written?
Your code could use a lot of cleanup:
Instead of an if-statement such as this one:
if( real(tran(w)) > 0 && imag(tran(w)) > 0)
answear=1;
else
answear=0;
end
you could write a boolean assignment:
answear = real(tran(w)) > 0 & imag(tran(w)) > 0);
Why do you have three (almost) identical nested if-statements at all?
if( real(tran(w)) > 0 && imag(tran(w)) > 0)
if( real(tran(w)) < 0 && imag(tran(w)) > 0)
if( real(tran(w)) < 0 && imag(tran(w)) < 0)
First of all, you could replace everything with one if-statement. But what are you actually testing with this? It seems that those nested if statements are never executed. For instance, real(tran(w)) cannot be both positive and negative at the same time (unless it is a vector you are working on, in which case you shouldn't be using the operator &&).
Also, this is probably your code triggers the error regarding variable answear. Accessing it is impossible since it hasn't been assigned a value (none of the if-statements have been executed).
What is tran, and what is w? Are they global variables? If they are, pass them as input parameters. Your function is probably poorly designed if it relies on external states and variables.
I haven't actually run your code, but these suggestions should make it easier for you to debug it.
P.S:
Please fix the annoying spelling error (it is "answer" and not "answear") :)