Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #============= DMI CODE =================
- input DMI_LENGTH = 14;
- def averageType = AverageType.WILDERS;
- def hiDiff = high - high[1];
- def loDiff = low[1] - low;
- def plusDM = if hiDiff > loDiff and hiDiff > 0 then hiDiff else 0;
- def minusDM = if loDiff > hiDiff and loDiff > 0 then loDiff else 0;
- def ATR = MovingAverage(averageType, TrueRange(high, close, low), DMI_LENGTH);
- def DMI_PLUS = 100 * MovingAverage(averageType, plusDM, DMI_LENGTH) / ATR;
- def DMI_MINUS = 100 * MovingAverage(averageType, minusDM, DMI_LENGTH) / ATR;
- def DX = if (DMI_PLUS + DMI_MINUS > 0) then 100 * AbsValue(DMI_PLUS - DMI_MINUS) / (DMI_PLUS + DMI_MINUS) else 0;
- def ADX = MovingAverage(averageType, DX, DMI_LENGTH);
- #========== END DMI CODE =====================
- #========= VWAP CODE =============
- def numDevDn = -2.0;
- def numDevUp = 2.0;
- input VWAPtimeFrame = {default DAY, WEEK, MONTH};
- def cap = getAggregationPeriod();
- def errorInAggregation =
- VWAPtimeFrame == VWAPtimeFrame and cap >= AggregationPeriod.WEEK or
- VWAPtimeFrame == VWAPtimeFrame and cap >= AggregationPeriod.MONTH;
- assert(!errorInAggregation, "timeFrame should be not less than current chart aggregation period");
- def yyyyMmDd = getYyyyMmDd();
- def periodIndx;
- switch (VWAPtimeFrame) {
- case DAY:
- periodIndx = yyyyMmDd;
- case WEEK:
- periodIndx = Floor((daysFromDate(first(yyyyMmDd)) + getDayOfWeek(first(yyyyMmDd))) / 7);
- case MONTH:
- periodIndx = roundDown(yyyyMmDd / 100, 0);
- }
- def isPeriodRolled = compoundValue(1, periodIndx != periodIndx[1], yes);
- def volumeSum;
- def volumeVwapSum;
- def volumeVwap2Sum;
- if (isPeriodRolled) {
- volumeSum = volume;
- volumeVwapSum = volume * vwap;
- volumeVwap2Sum = volume * Sqr(vwap);
- } else {
- volumeSum = compoundValue(1, volumeSum[1] + volume, volume);
- volumeVwapSum = compoundValue(1, volumeVwapSum[1] + volume * vwap, volume * vwap);
- volumeVwap2Sum = compoundValue(1, volumeVwap2Sum[1] + volume * Sqr(vwap), volume * Sqr(vwap));
- }
- def price = volumeVwapSum / volumeSum;
- def deviation = Sqrt(Max(volumeVwap2Sum / volumeSum - Sqr(price), 0));
- def MiddleBand = price;
- def UpperBand = price + numDevUp * deviation;
- def LowerBand = price + numDevDn * deviation;
- #=========== END VWAP CODE =====================
- input RSI_BUY_LIMIT = 50;
- input EMA_LENGTH = 13;
- input CCILengthForSell = 5;
- def rising = close > close from 1 bars ago and low > low from 1 bars ago;
- def closeAboveEMA = close from 1 bars ago > MovAvgExponential(EMA_LENGTH);
- def isAboveMiddleVWAP = close > MiddleBand;
- def withinTradingDay = SecondsFromTime(21.0) > 32900 and SecondsFromTime(21.0) < 55000;
- def adxLowerLows = ADX from 1 bars ago > ADX;
- def adxHigherHighs = ADX from 1 bars ago < ADX;
- def dmiMinusLowerLows = DMI_MINUS from 1 bars ago > DMI_MINUS;
- def dmiPlusHigherHighs = DMI_PLUS from 1 bars ago < DMI_PLUS;
- def dmiBuySignal = (dmiPlusHigherHighs and adxLowerLows and dmiMinusLowerLows) or (dmiPlusHigherHighs and adxHigherHighs);
- def topTail = ((high - close) / high) * 100;
- def higherHighs = high from 2 bars ago > high from 1 bars ago and high from 1 bars ago > high;
- def buy = RSI() > RSI_BUY_LIMIT and rising and closeAboveEMA and isAboveMiddleVWAP and withinTradingDay and CCI(22) > 13 and CCI(22) < 100 and dmiBuySignal;
- def sell = close < MovAvgExponential(EMA_LENGTH) or topTail > 0.3 or SecondsFromTime(21.0) > 55000 or CCI(5) < 0;
- AddOrder(OrderType.BUY_TO_OPEN, buy, open[-1], 50, Color.GREEN, Color.GREEN, name = "CALL");
- AddOrder(OrderType.SELL_TO_CLOSE, sell, close[-1], 50, Color.RED, Color.RED, name = "CLOSE CALL");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement