vadim5435
Заблокирован
- Регистрация
- 11.07.15
- Сообщения
- 74
- Реакции
- 0
vadim5435 не предоставил никакой дополнительной информации.
declare upper;
input AlertsLabelOn = yes;
input AlertsColorOn = yes;
input tester1 = {default "Signal_1", "signal_2", "signal_3",
"signal_4"};
input AlertSound = {тАЬBellтАЭ, тАЬChimesтАЭ, default тАЬDingтАЭ, тАЬNoSoundтАЭ, тАЬRingтАЭ};
input swing_back = 1;
input swing_forward = 1;
input showswingpoints = {"Yes", default "No"};
def ssp = showswingpoints;
def hs = if ssp == 0 then 0 else 1;
def sb = swing_back;
def sf = swing_forward;
def na = Double.NaN;
#CCI Parameters
input ccilength = 14;
input overbought_line = 100;
input oversold_line = -100;
def price = close + low + high;
def linDev = LinDev(price, ccilength);
def CCI = if linDev == 0 then 0 else (price - Average(price, ccilength)) / linDev / 0.015;
#Swing point logic for CCI
def lfor = Lowest(CCI, sf)[-sf];
def lback = Lowest(CCI, sb)[1];
def swinglow = if CCI < lfor and CCI <= lback then 1 else 0;
def sl = if swinglow then CCI else na;
def hfor = Highest(CCI, sf)[-sf];
def hback = Highest(CCI, sb)[1];
def swinghigh = if CCI > hfor and CCI >= hback then 1 else 0;
def sh = if swinghigh then CCI else na;
rec lsl = if swinglow[1] then CCI[1] else lsl[1];
rec lsh = if swinghigh[1] then CCI[1] else lsh[1];
# Price/CCI Divergence
rec blPRICE = if swinglow then low else blPRICE[1];
rec brPRICE = if swinghigh then high else brPRICE[1];
##################### 1 ###################
def bulldiv1 = if blPRICE > blPRICE[1] and CCI <= lsl[1] then 1 else 0;
plot bldiv1 = if bulldiv1 and CCI < oversold_line then CCI else na;
def beardiv1 = if brPRICE < brPRICE[1] and CCI >= lsh[1] then 1 else 0;
plot brdiv1 = if beardiv1 and CCI > overbought_line then CCI else na;
bldiv1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bldiv1.SetLineWeight(5);
bldiv1.SetDefaultColor(Color.YELLOW);
Alert(bldiv1, "UP", Alert.BAR, AlertSound);
brdiv1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
brdiv1.SetLineWeight(5);
brdiv1.SetDefaultColor(Color.YELLOW);
Alert(brdiv1, "DOWN", Alert.BAR, AlertSound);
AddLabel(AlertsLabelOn and brdiv1, "╨Т╨Э╨Ш╨Ч", Color.RED);
AddLabel(AlertsLabelOn and bldiv1, "╨Т╨Т╨Х╨а╨е", Color.GREEN);
############### 2 #################
def bulldiv2 = if blPRICE < blPRICE[1] and CCI >= lsl[1] then 1 else 0;
plot bldiv2 = if bulldiv2 and CCI < oversold_line then CCI else na;
def beardiv2 = if brPRICE > brPRICE[1] and CCI <= lsh[1] then 1 else 0;
plot brdiv2 = if beardiv2 and CCI > overbought_line then CCI else na;
bldiv2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bldiv2.SetLineWeight(5);
bldiv2.SetDefaultColor(Color.YELLOW);
Alert(bldiv2, "UP", Alert.BAR, AlertSound);
brdiv2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
brdiv2.SetLineWeight(5);
brdiv2.SetDefaultColor(Color.YELLOW);
Alert(brdiv2, "DOWN", Alert.BAR, AlertSound);
AddLabel(AlertsLabelOn and brdiv2, "╨Т╨Э╨Ш╨Ч", Color.RED);
AddLabel(AlertsLabelOn and bldiv2, "╨Т╨Т╨Х╨а╨е", Color.GREEN);
############## 3 ##################
def bulldiv3 = if blPRICE < blPRICE[1] and CCI <= lsl[1] then 1 else 0;
plot bldiv3 = if bulldiv3 and CCI < oversold_line then CCI else na;
def beardiv3 = if brPRICE > brPRICE[1] and CCI >= lsh[1] then 1 else 0;
plot brdiv3 = if beardiv3 and CCI > overbought_line then CCI else na;
bldiv3.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bldiv3.SetLineWeight(5);
bldiv3.SetDefaultColor(Color.YELLOW);
Alert(bldiv3, "UP", Alert.BAR, AlertSound);
brdiv3.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
brdiv3.SetLineWeight(5);
brdiv3.SetDefaultColor(Color.YELLOW);
Alert(brdiv3, "DOWN", Alert.BAR, AlertSound);
AddLabel(AlertsLabelOn and brdiv3, "╨Т╨Э╨Ш╨Ч", Color.RED);
AddLabel(AlertsLabelOn and bldiv3, "╨Т╨Т╨Х╨а╨е", Color.GREEN);
############### 4 ###############
def bulldiv4 = if blPRICE > blPRICE[1] and CCI >= lsl[1] then 1 else 0;
plot bldiv4 = if bulldiv4 and CCI < oversold_line then CCI else na;
def beardiv4 = if brPRICE < brPRICE[1] and CCI <= lsh[1] then 1 else 0;
plot brdiv4 = if beardiv4 and CCI > overbought_line then CCI else na;
bldiv4.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bldiv4.SetLineWeight(5);
bldiv4.SetDefaultColor(Color.YELLOW);
Alert(bldiv4, "UP", Alert.BAR, AlertSound);
brdiv4.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
brdiv4.SetLineWeight(5);
brdiv4.SetDefaultColor(Color.YELLOW);
Alert(brdiv4, "DOWN", Alert.BAR, AlertSound);
AddLabel(AlertsLabelOn and brdiv4, "╨Т╨Э╨Ш╨Ч", Color.RED);
AddLabel(AlertsLabelOn and bldiv4, "╨Т╨Т╨Х╨а╨е", Color.GREEN);
def OverBought = overbought_line;
def OverSold = oversold_line;
def ZeroLine = 0;
def up;
def down;
switch (tester1)
{
case Signal_1:
up = if IsNaN(bldiv1) then 0 else bldiv1 != 0;
down = if IsNaN(brdiv1) then 0 else brdiv1 != 0;
case signal_2:
up = if IsNaN(bldiv2) then 0 else bldiv2 != 0;
down = if IsNaN(brdiv2) then 0 else brdiv2 != 0;
case signal_3:
up = if IsNaN(bldiv3) then 0 else bldiv3 != 0;
down = if IsNaN(brdiv3) then 0 else brdiv3 != 0;
case signal_4:
up = if IsNaN(bldiv4) then 0 else bldiv4 != 0;
down = if IsNaN(brdiv4) then 0 else brdiv4 != 0;
}
##########---------------------------TEST OPTIONS---------------------------------------------
#hint timetest: Test according to timeperiods
#hint expiry: Numbers of candles after signal (1 = next candle after signal, 2 = second candle)
#hint secondcandle: Use only if candleexpiry = 1. Adding signals taking second candle after loss
#hint moneycount: display labels with profit/loss in $
#hint invest: amount of investment per trade
#hint RPI: Return Per Investment (payout)
input expiry = 1;
input secondcandle = no;
input moneycount = no;
input invest = 25;
input RPI = 0.80;
input timetest = no;
########-------------------------------------------TIME FILTER-----------------------------------------------
#hint TradingOpen1: EST NY TIME
input TradingOpen1 = 330;
input TradingClose1 = 530;
input TradingOpen2 = 0930;
input TradingClose2 = 1130;
#hint input AsiaOpenTime1 = 2000;
#hint input AsiaCloseTime1 = 2359;
#hint input AsiaOpenTime2 = 0000;
#hint input AsiaCloseTime2 = 0200;
#hint input EUOpenTime = 330;
#hint input EUCloseTime = 530;
#hint input USOpenTime = 0930;
#hint input USCloseTime = 1130;
# Set below to 'True' to allow for DST difference adjustment if you are setting
# windows up for a european instrument like the euro.
input EnableDSTAutoAdjust = {default "Yes", "No"};
input DSTOffsetHours = 1;
#==========================================================================
# Figure out DST adjustment for diffence between USA and europe
#==========================================================================
#basically, if we are after the 2nd Sunday in March and before
#the last Sunday in March, we need to offset the Trading Windows by 1hr forward
#if we are after the last Sunday in Oct, until the 1st Sunday in Nov
# we need to offset the trading windows by 1hr backward...
def CurrentYear = GetYear();
def CurrentMonth = GetMonth();
def CurrentDOM = GetDayOfMonth(GetYYYYMMDD());
#What is the first day of the week for the 1st of this month?
def Day1DOW1 = GetDayOfWeek(CurrentYear * 10000 + CurrentMonth * 100 + 1);
def FirstSundayDOM1 = if Day1DOW1 < 7
then 7 - Day1DOW1 + 1
else 1;
def SecondSundayOfMonth = FirstSundayDOM1 + 7;
def isMarch = If (CurrentMonth == 3, 1, 0);
def SpringDSTShiftStart = If (isMarch and (SecondSundayOfMonth <= CurrentDOM), 1, 0);
#last sunday in march...
def SpringDSTShiftStop = If (isMarch and ((SecondSundayOfMonth + 14) > CurrentDOM), 1, 0);
def DoSpringShift = If (SpringDSTShiftStart and SpringDSTShiftStop and EnableDSTAutoAdjust, 1, 0);
def isOctober = If (CurrentMonth == 10, 1, 0);
def isNovember = If (CurrentMonth == 11, 1, 0);
def FallDSTShiftStart = If (isOctober and ((SecondSundayOfMonth + 14) <= CurrentDOM), 1, 0);
def FallDSTShiftStop = If (isNovember and FirstSundayDOM1 > CurrentDOM, 1, 0);
def DoFallShift = If (FallDSTShiftStart or FallDSTShiftStop and EnableDSTAutoAdjust, 1, 0);
def isToday = If(GetDay() == GetLastDay(), 1, 0);
#PITA. SecondsTillTime only takes constants... Need to manually adjust for DST if it's enabled.
def DSTAdjust = If (DoSpringShift, DSTOffsetHours * 3600, If (DoFallShift, -DSTOffsetHours * 3600, 0));
def TradingOpenTime1 = If((SecondsTillTime(TradingOpen1) + DSTAdjust > 0), 0, 1);
def TradingCloseTime1 = If((SecondsTillTime(TradingClose1) + DSTAdjust > 0), 0, 1);
def TradingWindow1 = If(TradingOpenTime1 and !TradingCloseTime1, 1, 0);
def TradingOpenTime2 = If((SecondsTillTime(TradingOpen2) + DSTAdjust > 0), 0, 1);
def TradingCloseTime2 = If((SecondsTillTime(TradingClose2) + DSTAdjust > 0), 0, 1);
def TradingWindow2 = If(TradingOpenTime2 and !TradingCloseTime2, 1, 0);
AddVerticalLine(TradingWindow1 and TradingWindow1[1] == 0 and timetest, "TradingOpen 1" , Color.GREEN, Curve.SHORT_DASH);
AddVerticalLine(TradingWindow1 == 0 and TradingWindow1[1] and timetest, "TradingClose 1" , Color.RED, Curve.SHORT_DASH);
AddVerticalLine(TradingWindow2 and TradingWindow2[1] == 0 and timetest, "TradingOpen 2" , Color.GREEN, Curve.SHORT_DASH);
AddVerticalLine(TradingWindow2 == 0 and TradingWindow2[1] and timetest, "TradingClose 2" , Color.RED, Curve.SHORT_DASH);
#####-------------------------------------TESTER-----------------------------------------------------
def ITM = if timetest and TradingWindow1 == 0 and TradingWindow2 == 0 then 0 else if (up[expiry] and close[0] > close[expiry]) or (down[expiry] and close[0] < close[expiry]) or (secondcandle and up[2] and close[1] < close[2] and close > close[1]) or (secondcandle and down[2] and close[1] > close[2] and close < close[1]) then 1 else 0;
def itmsum = TotalSum(ITM);
def OTM = if timetest and TradingWindow1 == 0 and TradingWindow2 == 0 then 0 else if (up[expiry] and close[0] < close[expiry]) or (down[expiry] and close[0] > close[expiry]) or (secondcandle and up[2] and close[1] < close[2] and close < close[1]) or (secondcandle and down[2] and close[1] > close[2] and close > close[1]) then 1 else 0;
def otmsum = TotalSum(OTM);
def itmrate = RoundUp((itmsum / (itmsum + otmsum) * 100), 2);
def label = 1;
AddLabel(label, Concat("ITM = ", itmsum), Color.GREEN);
AddLabel(label, Concat("OTM = ", otmsum), Color.RED);
AddLabel(label, Concat("ITM RATE = %", itmrate), Color.WHITE);
#####---------Moneycount--------------------------------------------
def PL = invest * itmsum * RPI - invest * otmsum;
def PLColor = if PL > 0 then 6 else 5;
AddLabel(moneycount, Concat("PROFIT/LOSS = $", PL), GetColor(PLColor));
input AlertsLabelOn = yes;
input AlertsColorOn = yes;
input tester1 = {default "Signal_1", "signal_2", "signal_3",
"signal_4"};
input AlertSound = {тАЬBellтАЭ, тАЬChimesтАЭ, default тАЬDingтАЭ, тАЬNoSoundтАЭ, тАЬRingтАЭ};
input swing_back = 1;
input swing_forward = 1;
input showswingpoints = {"Yes", default "No"};
def ssp = showswingpoints;
def hs = if ssp == 0 then 0 else 1;
def sb = swing_back;
def sf = swing_forward;
def na = Double.NaN;
#CCI Parameters
input ccilength = 14;
input overbought_line = 100;
input oversold_line = -100;
def price = close + low + high;
def linDev = LinDev(price, ccilength);
def CCI = if linDev == 0 then 0 else (price - Average(price, ccilength)) / linDev / 0.015;
#Swing point logic for CCI
def lfor = Lowest(CCI, sf)[-sf];
def lback = Lowest(CCI, sb)[1];
def swinglow = if CCI < lfor and CCI <= lback then 1 else 0;
def sl = if swinglow then CCI else na;
def hfor = Highest(CCI, sf)[-sf];
def hback = Highest(CCI, sb)[1];
def swinghigh = if CCI > hfor and CCI >= hback then 1 else 0;
def sh = if swinghigh then CCI else na;
rec lsl = if swinglow[1] then CCI[1] else lsl[1];
rec lsh = if swinghigh[1] then CCI[1] else lsh[1];
# Price/CCI Divergence
rec blPRICE = if swinglow then low else blPRICE[1];
rec brPRICE = if swinghigh then high else brPRICE[1];
##################### 1 ###################
def bulldiv1 = if blPRICE > blPRICE[1] and CCI <= lsl[1] then 1 else 0;
plot bldiv1 = if bulldiv1 and CCI < oversold_line then CCI else na;
def beardiv1 = if brPRICE < brPRICE[1] and CCI >= lsh[1] then 1 else 0;
plot brdiv1 = if beardiv1 and CCI > overbought_line then CCI else na;
bldiv1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bldiv1.SetLineWeight(5);
bldiv1.SetDefaultColor(Color.YELLOW);
Alert(bldiv1, "UP", Alert.BAR, AlertSound);
brdiv1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
brdiv1.SetLineWeight(5);
brdiv1.SetDefaultColor(Color.YELLOW);
Alert(brdiv1, "DOWN", Alert.BAR, AlertSound);
AddLabel(AlertsLabelOn and brdiv1, "╨Т╨Э╨Ш╨Ч", Color.RED);
AddLabel(AlertsLabelOn and bldiv1, "╨Т╨Т╨Х╨а╨е", Color.GREEN);
############### 2 #################
def bulldiv2 = if blPRICE < blPRICE[1] and CCI >= lsl[1] then 1 else 0;
plot bldiv2 = if bulldiv2 and CCI < oversold_line then CCI else na;
def beardiv2 = if brPRICE > brPRICE[1] and CCI <= lsh[1] then 1 else 0;
plot brdiv2 = if beardiv2 and CCI > overbought_line then CCI else na;
bldiv2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bldiv2.SetLineWeight(5);
bldiv2.SetDefaultColor(Color.YELLOW);
Alert(bldiv2, "UP", Alert.BAR, AlertSound);
brdiv2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
brdiv2.SetLineWeight(5);
brdiv2.SetDefaultColor(Color.YELLOW);
Alert(brdiv2, "DOWN", Alert.BAR, AlertSound);
AddLabel(AlertsLabelOn and brdiv2, "╨Т╨Э╨Ш╨Ч", Color.RED);
AddLabel(AlertsLabelOn and bldiv2, "╨Т╨Т╨Х╨а╨е", Color.GREEN);
############## 3 ##################
def bulldiv3 = if blPRICE < blPRICE[1] and CCI <= lsl[1] then 1 else 0;
plot bldiv3 = if bulldiv3 and CCI < oversold_line then CCI else na;
def beardiv3 = if brPRICE > brPRICE[1] and CCI >= lsh[1] then 1 else 0;
plot brdiv3 = if beardiv3 and CCI > overbought_line then CCI else na;
bldiv3.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bldiv3.SetLineWeight(5);
bldiv3.SetDefaultColor(Color.YELLOW);
Alert(bldiv3, "UP", Alert.BAR, AlertSound);
brdiv3.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
brdiv3.SetLineWeight(5);
brdiv3.SetDefaultColor(Color.YELLOW);
Alert(brdiv3, "DOWN", Alert.BAR, AlertSound);
AddLabel(AlertsLabelOn and brdiv3, "╨Т╨Э╨Ш╨Ч", Color.RED);
AddLabel(AlertsLabelOn and bldiv3, "╨Т╨Т╨Х╨а╨е", Color.GREEN);
############### 4 ###############
def bulldiv4 = if blPRICE > blPRICE[1] and CCI >= lsl[1] then 1 else 0;
plot bldiv4 = if bulldiv4 and CCI < oversold_line then CCI else na;
def beardiv4 = if brPRICE < brPRICE[1] and CCI <= lsh[1] then 1 else 0;
plot brdiv4 = if beardiv4 and CCI > overbought_line then CCI else na;
bldiv4.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bldiv4.SetLineWeight(5);
bldiv4.SetDefaultColor(Color.YELLOW);
Alert(bldiv4, "UP", Alert.BAR, AlertSound);
brdiv4.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
brdiv4.SetLineWeight(5);
brdiv4.SetDefaultColor(Color.YELLOW);
Alert(brdiv4, "DOWN", Alert.BAR, AlertSound);
AddLabel(AlertsLabelOn and brdiv4, "╨Т╨Э╨Ш╨Ч", Color.RED);
AddLabel(AlertsLabelOn and bldiv4, "╨Т╨Т╨Х╨а╨е", Color.GREEN);
def OverBought = overbought_line;
def OverSold = oversold_line;
def ZeroLine = 0;
def up;
def down;
switch (tester1)
{
case Signal_1:
up = if IsNaN(bldiv1) then 0 else bldiv1 != 0;
down = if IsNaN(brdiv1) then 0 else brdiv1 != 0;
case signal_2:
up = if IsNaN(bldiv2) then 0 else bldiv2 != 0;
down = if IsNaN(brdiv2) then 0 else brdiv2 != 0;
case signal_3:
up = if IsNaN(bldiv3) then 0 else bldiv3 != 0;
down = if IsNaN(brdiv3) then 0 else brdiv3 != 0;
case signal_4:
up = if IsNaN(bldiv4) then 0 else bldiv4 != 0;
down = if IsNaN(brdiv4) then 0 else brdiv4 != 0;
}
##########---------------------------TEST OPTIONS---------------------------------------------
#hint timetest: Test according to timeperiods
#hint expiry: Numbers of candles after signal (1 = next candle after signal, 2 = second candle)
#hint secondcandle: Use only if candleexpiry = 1. Adding signals taking second candle after loss
#hint moneycount: display labels with profit/loss in $
#hint invest: amount of investment per trade
#hint RPI: Return Per Investment (payout)
input expiry = 1;
input secondcandle = no;
input moneycount = no;
input invest = 25;
input RPI = 0.80;
input timetest = no;
########-------------------------------------------TIME FILTER-----------------------------------------------
#hint TradingOpen1: EST NY TIME
input TradingOpen1 = 330;
input TradingClose1 = 530;
input TradingOpen2 = 0930;
input TradingClose2 = 1130;
#hint input AsiaOpenTime1 = 2000;
#hint input AsiaCloseTime1 = 2359;
#hint input AsiaOpenTime2 = 0000;
#hint input AsiaCloseTime2 = 0200;
#hint input EUOpenTime = 330;
#hint input EUCloseTime = 530;
#hint input USOpenTime = 0930;
#hint input USCloseTime = 1130;
# Set below to 'True' to allow for DST difference adjustment if you are setting
# windows up for a european instrument like the euro.
input EnableDSTAutoAdjust = {default "Yes", "No"};
input DSTOffsetHours = 1;
#==========================================================================
# Figure out DST adjustment for diffence between USA and europe
#==========================================================================
#basically, if we are after the 2nd Sunday in March and before
#the last Sunday in March, we need to offset the Trading Windows by 1hr forward
#if we are after the last Sunday in Oct, until the 1st Sunday in Nov
# we need to offset the trading windows by 1hr backward...
def CurrentYear = GetYear();
def CurrentMonth = GetMonth();
def CurrentDOM = GetDayOfMonth(GetYYYYMMDD());
#What is the first day of the week for the 1st of this month?
def Day1DOW1 = GetDayOfWeek(CurrentYear * 10000 + CurrentMonth * 100 + 1);
def FirstSundayDOM1 = if Day1DOW1 < 7
then 7 - Day1DOW1 + 1
else 1;
def SecondSundayOfMonth = FirstSundayDOM1 + 7;
def isMarch = If (CurrentMonth == 3, 1, 0);
def SpringDSTShiftStart = If (isMarch and (SecondSundayOfMonth <= CurrentDOM), 1, 0);
#last sunday in march...
def SpringDSTShiftStop = If (isMarch and ((SecondSundayOfMonth + 14) > CurrentDOM), 1, 0);
def DoSpringShift = If (SpringDSTShiftStart and SpringDSTShiftStop and EnableDSTAutoAdjust, 1, 0);
def isOctober = If (CurrentMonth == 10, 1, 0);
def isNovember = If (CurrentMonth == 11, 1, 0);
def FallDSTShiftStart = If (isOctober and ((SecondSundayOfMonth + 14) <= CurrentDOM), 1, 0);
def FallDSTShiftStop = If (isNovember and FirstSundayDOM1 > CurrentDOM, 1, 0);
def DoFallShift = If (FallDSTShiftStart or FallDSTShiftStop and EnableDSTAutoAdjust, 1, 0);
def isToday = If(GetDay() == GetLastDay(), 1, 0);
#PITA. SecondsTillTime only takes constants... Need to manually adjust for DST if it's enabled.
def DSTAdjust = If (DoSpringShift, DSTOffsetHours * 3600, If (DoFallShift, -DSTOffsetHours * 3600, 0));
def TradingOpenTime1 = If((SecondsTillTime(TradingOpen1) + DSTAdjust > 0), 0, 1);
def TradingCloseTime1 = If((SecondsTillTime(TradingClose1) + DSTAdjust > 0), 0, 1);
def TradingWindow1 = If(TradingOpenTime1 and !TradingCloseTime1, 1, 0);
def TradingOpenTime2 = If((SecondsTillTime(TradingOpen2) + DSTAdjust > 0), 0, 1);
def TradingCloseTime2 = If((SecondsTillTime(TradingClose2) + DSTAdjust > 0), 0, 1);
def TradingWindow2 = If(TradingOpenTime2 and !TradingCloseTime2, 1, 0);
AddVerticalLine(TradingWindow1 and TradingWindow1[1] == 0 and timetest, "TradingOpen 1" , Color.GREEN, Curve.SHORT_DASH);
AddVerticalLine(TradingWindow1 == 0 and TradingWindow1[1] and timetest, "TradingClose 1" , Color.RED, Curve.SHORT_DASH);
AddVerticalLine(TradingWindow2 and TradingWindow2[1] == 0 and timetest, "TradingOpen 2" , Color.GREEN, Curve.SHORT_DASH);
AddVerticalLine(TradingWindow2 == 0 and TradingWindow2[1] and timetest, "TradingClose 2" , Color.RED, Curve.SHORT_DASH);
#####-------------------------------------TESTER-----------------------------------------------------
def ITM = if timetest and TradingWindow1 == 0 and TradingWindow2 == 0 then 0 else if (up[expiry] and close[0] > close[expiry]) or (down[expiry] and close[0] < close[expiry]) or (secondcandle and up[2] and close[1] < close[2] and close > close[1]) or (secondcandle and down[2] and close[1] > close[2] and close < close[1]) then 1 else 0;
def itmsum = TotalSum(ITM);
def OTM = if timetest and TradingWindow1 == 0 and TradingWindow2 == 0 then 0 else if (up[expiry] and close[0] < close[expiry]) or (down[expiry] and close[0] > close[expiry]) or (secondcandle and up[2] and close[1] < close[2] and close < close[1]) or (secondcandle and down[2] and close[1] > close[2] and close > close[1]) then 1 else 0;
def otmsum = TotalSum(OTM);
def itmrate = RoundUp((itmsum / (itmsum + otmsum) * 100), 2);
def label = 1;
AddLabel(label, Concat("ITM = ", itmsum), Color.GREEN);
AddLabel(label, Concat("OTM = ", otmsum), Color.RED);
AddLabel(label, Concat("ITM RATE = %", itmrate), Color.WHITE);
#####---------Moneycount--------------------------------------------
def PL = invest * itmsum * RPI - invest * otmsum;
def PLColor = if PL > 0 then 6 else 5;
AddLabel(moneycount, Concat("PROFIT/LOSS = $", PL), GetColor(PLColor));