Last active
June 7, 2025 13:57
-
-
Save 18182324/2a333baa95c9807399848a43f3e1a0b1 to your computer and use it in GitHub Desktop.
ACD Level Calculation EasyLangauge Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// === INPUTS === | |
Inputs: | |
ORStart(0930), | |
OREnd(0950), | |
ARangeTicks(8), | |
CRangeTicks(8), | |
ConfirmBars(3), | |
MaxBarsLookback(30); | |
// === VARIABLES === | |
Vars: | |
ORHigh(0), ORLow(999999), | |
AUp(0), ADown(0), CUp(0), CDown(0), | |
AConfirmed(false), DConfirmed(false), | |
CUpConfirmed(false), CDownConfirmed(false), | |
BarCount(0), DailyValue(0), | |
NumberLine , NumLineSum(0), | |
LongBias(false), ShortBias(false); | |
// === RESET EACH DAY === | |
If Date <> Date[1] then begin | |
ORHigh = 0; | |
ORLow = 999999; | |
AConfirmed = false; | |
DConfirmed = false; | |
CUpConfirmed = false; | |
CDownConfirmed = false; | |
BarCount = 0; | |
DailyValue = 0; | |
end; | |
// === OPENING RANGE === | |
If Time >= ORStart and Time <= OREnd then begin | |
ORHigh = MaxList(High, ORHigh); | |
ORLow = MinList(Low, ORLow); | |
end; | |
If Time = OREnd then begin | |
AUp = ORHigh + MinMove * ARangeTicks / PriceScale; | |
ADown = ORLow - MinMove * ARangeTicks / PriceScale; | |
CUp = AUp + MinMove * CRangeTicks / PriceScale; | |
CDown = ADown - MinMove * CRangeTicks / PriceScale; | |
end; | |
// === A UP === | |
If AConfirmed = false and High >= AUp then begin | |
BarCount += 1; | |
If BarCount >= ConfirmBars then begin | |
AConfirmed = true; | |
BarCount = 0; | |
end; | |
end else if AConfirmed = false then | |
BarCount = 0; | |
// === A DOWN === | |
If DConfirmed = false and Low <= ADown then begin | |
BarCount += 1; | |
If BarCount >= ConfirmBars then begin | |
DConfirmed = true; | |
BarCount = 0; | |
end; | |
end else if DConfirmed = false then | |
BarCount = 0; | |
// === C UP / C DOWN === | |
If AConfirmed and High >= CUp then | |
CUpConfirmed = true; | |
If DConfirmed and Low <= CDown then | |
CDownConfirmed = true; | |
// === NUMBER LINE DAILY VALUE (END OF SESSION) === | |
If LastBarOnChart and Time >= 1545 then begin | |
If AConfirmed and Close > ORHigh then | |
DailyValue = +2; | |
If DConfirmed and Close < ORLow then | |
DailyValue = -2; | |
If CUpConfirmed and Close > CUp then | |
DailyValue = +4; | |
If CDownConfirmed and Close < CDown then | |
DailyValue = -4; | |
// Rollover 30-day number line | |
for value = MaxBarsLookback - 1 downto 1 begin | |
NumberLine[value] = NumberLine[value - 1]; | |
end; | |
NumberLine[0] = DailyValue; | |
// Calculate Sum | |
NumLineSum = 0; | |
for value = 0 to MaxBarsLookback - 1 begin | |
NumLineSum += NumberLine[value]; | |
end; | |
// Define Bias | |
If NumberLine[0] >= 9 and NumberLine[1] >= 9 then | |
LongBias = true | |
else | |
LongBias = false; | |
If NumberLine[0] <= -9 and NumberLine[1] <= -9 then | |
ShortBias = true | |
else | |
ShortBias = false; | |
end; | |
// === STRATEGY EXECUTION === | |
If MarketPosition = 0 then begin | |
If LongBias and AConfirmed then | |
Buy("ACD_Long") next bar at market; | |
If ShortBias and DConfirmed then | |
SellShort("ACD_Short") next bar at market; | |
end; | |
If MarketPosition = 1 and CDownConfirmed then | |
Sell("Exit_Long_CDown") next bar at market; | |
If MarketPosition = -1 and CUpConfirmed then | |
BuyToCover("Exit_Short_CUp") next bar at market; | |
// === OPTIONAL EXIT ON SYSTEM FAILURE === | |
If LongBias and AConfirmed and BarsSinceEntry > 3 and Close < ORHigh then | |
Sell("Fail_Long") next bar at market; | |
If ShortBias and DConfirmed and BarsSinceEntry > 3 and Close > ORLow then | |
BuyToCover("Fail_Short") next bar at market; | |
// === PLOTS === | |
Plot1(AUp, "A Up"); | |
Plot2(ADown, "A Down"); | |
Plot3(CUp, "C Up"); | |
Plot4(CDown, "C Down"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
If NumberLineVal >= 9 and NumberLineVal[1] >= 9 then | |
Alert("Two consecutive +9 days: Bullish trend signal"); | |
If NumberLineVal <= -9 and NumberLineVal[1] <= -9 then | |
Alert("Two consecutive -9 days: Bearish trend signal"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Inputs: | |
ORStartTime(0930), | |
OREndTime(0950), | |
ARangeTicks(8), // Set according to the asset (e.g., 8 ticks for Crude Oil) | |
CRangeTicks(8), | |
ConfirmBars(3); // Number of bars needed to confirm breakout | |
Vars: | |
ORHigh(0), | |
ORLow(0), | |
AUp(0), | |
ADown(0), | |
CUp(0), | |
CDown(0), | |
AConfirmed(False), | |
DConfirmed(False), | |
CUpConfirmed(False), | |
CDownConfirmed(False), | |
AUpBar(0), | |
ADownBar(0), | |
CUpBar(0), | |
CDownBar(0), | |
BarCount(0); | |
// Reset at new session | |
If Date <> Date[1] then begin | |
ORHigh = 0; | |
ORLow = 999999; | |
AConfirmed = False; | |
DConfirmed = False; | |
CUpConfirmed = False; | |
CDownConfirmed = False; | |
BarCount = 0; | |
end; | |
// Capture Opening Range | |
If Time >= ORStartTime and Time <= OREndTime then begin | |
ORHigh = MaxList(High, ORHigh); | |
ORLow = MinList(Low, ORLow); | |
end; | |
// Set A/CD levels after Opening Range is complete | |
If Time = OREndTime then begin | |
AUp = ORHigh + MinMove * ARangeTicks / PriceScale; | |
ADown = ORLow - MinMove * ARangeTicks / PriceScale; | |
CUp = AUp + MinMove * CRangeTicks / PriceScale; | |
CDown = ADown - MinMove * CRangeTicks / PriceScale; | |
end; | |
// Check for A UP confirmation | |
If AConfirmed = False and High >= AUp then begin | |
BarCount = BarCount + 1; | |
If BarCount >= ConfirmBars then begin | |
AConfirmed = True; | |
AUpBar = CurrentBar; | |
BarCount = 0; | |
end; | |
end else if AConfirmed = False then begin | |
BarCount = 0; | |
end; | |
// Check for A DOWN confirmation | |
If DConfirmed = False and Low <= ADown then begin | |
BarCount = BarCount + 1; | |
If BarCount >= ConfirmBars then begin | |
DConfirmed = True; | |
ADownBar = CurrentBar; | |
BarCount = 0; | |
end; | |
end else if DConfirmed = False then begin | |
BarCount = 0; | |
end; | |
// C Up and C Down logic | |
If AConfirmed and High >= CUp then begin | |
CUpConfirmed = True; | |
CUpBar = CurrentBar; | |
end; | |
If DConfirmed and Low <= CDown then begin | |
CDownConfirmed = True; | |
CDownBar = CurrentBar; | |
end; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Vars: | |
DailyValue(0), | |
NumberLineVal(0), | |
ValueArray , | |
Sum30(0), | |
Index(0); | |
// Daily reset logic | |
If Date <> Date[1] then begin | |
DailyValue = 0; | |
// --- Intraday logic simplified for demonstration --- | |
If AConfirmed and Close > AUp and Close > ORHigh then | |
DailyValue = +2; | |
If DConfirmed and Close < ADown and Close < ORLow then | |
DailyValue = -2; | |
// Add C Up / Down conditions | |
If CUpConfirmed and Close > CUp then | |
DailyValue = +4; | |
If CDownConfirmed and Close < CDown then | |
DailyValue = -4; | |
// Fallbacks: Crossover but failed confirmation | |
If AConfirmed = False and DConfirmed = False then | |
DailyValue = 0; | |
// Update rolling 30-day number line | |
Index = CurrentBar mod 30; | |
ValueArray[Index] = DailyValue; | |
Sum30 = 0; | |
For Value = 0 to 29 begin | |
Sum30 = Sum30 + ValueArray[Value]; | |
end; | |
NumberLineVal = Sum30; | |
end; | |
// Plotting number line value | |
Plot1(NumberLineVal, "NumLine"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment