Advertisement
Guest User

Untitled

a guest
Nov 18th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. #============= DMI CODE =================
  2.  
  3. input DMI_LENGTH = 14;
  4. def averageType = AverageType.WILDERS;
  5.  
  6. def hiDiff = high - high[1];
  7. def loDiff = low[1] - low;
  8.  
  9. def plusDM = if hiDiff > loDiff and hiDiff > 0 then hiDiff else 0;
  10. def minusDM = if loDiff > hiDiff and loDiff > 0 then loDiff else 0;
  11.  
  12. def ATR = MovingAverage(averageType, TrueRange(high, close, low), DMI_LENGTH);
  13. def DMI_PLUS = 100 * MovingAverage(averageType, plusDM, DMI_LENGTH) / ATR;
  14. def DMI_MINUS = 100 * MovingAverage(averageType, minusDM, DMI_LENGTH) / ATR;
  15.  
  16. def DX = if (DMI_PLUS + DMI_MINUS > 0) then 100 * AbsValue(DMI_PLUS - DMI_MINUS) / (DMI_PLUS + DMI_MINUS) else 0;
  17. def ADX = MovingAverage(averageType, DX, DMI_LENGTH);
  18.  
  19.  
  20. #========== END DMI CODE =====================
  21.  
  22.  
  23. #========= VWAP CODE =============
  24.  
  25. def numDevDn = -2.0;
  26. def numDevUp = 2.0;
  27. input VWAPtimeFrame = {default DAY, WEEK, MONTH};
  28.  
  29. def cap = getAggregationPeriod();
  30. def errorInAggregation =
  31. VWAPtimeFrame == VWAPtimeFrame and cap >= AggregationPeriod.WEEK or
  32. VWAPtimeFrame == VWAPtimeFrame and cap >= AggregationPeriod.MONTH;
  33. assert(!errorInAggregation, "timeFrame should be not less than current chart aggregation period");
  34.  
  35. def yyyyMmDd = getYyyyMmDd();
  36. def periodIndx;
  37. switch (VWAPtimeFrame) {
  38. case DAY:
  39. periodIndx = yyyyMmDd;
  40. case WEEK:
  41. periodIndx = Floor((daysFromDate(first(yyyyMmDd)) + getDayOfWeek(first(yyyyMmDd))) / 7);
  42. case MONTH:
  43. periodIndx = roundDown(yyyyMmDd / 100, 0);
  44. }
  45. def isPeriodRolled = compoundValue(1, periodIndx != periodIndx[1], yes);
  46.  
  47. def volumeSum;
  48. def volumeVwapSum;
  49. def volumeVwap2Sum;
  50.  
  51. if (isPeriodRolled) {
  52. volumeSum = volume;
  53. volumeVwapSum = volume * vwap;
  54. volumeVwap2Sum = volume * Sqr(vwap);
  55. } else {
  56. volumeSum = compoundValue(1, volumeSum[1] + volume, volume);
  57. volumeVwapSum = compoundValue(1, volumeVwapSum[1] + volume * vwap, volume * vwap);
  58. volumeVwap2Sum = compoundValue(1, volumeVwap2Sum[1] + volume * Sqr(vwap), volume * Sqr(vwap));
  59. }
  60. def price = volumeVwapSum / volumeSum;
  61. def deviation = Sqrt(Max(volumeVwap2Sum / volumeSum - Sqr(price), 0));
  62.  
  63. def MiddleBand = price;
  64. def UpperBand = price + numDevUp * deviation;
  65. def LowerBand = price + numDevDn * deviation;
  66.  
  67. #=========== END VWAP CODE =====================
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83. input RSI_BUY_LIMIT = 50;
  84. input EMA_LENGTH = 13;
  85. input CCILengthForSell = 5;
  86.  
  87. def rising = close > close from 1 bars ago and low > low from 1 bars ago;
  88.  
  89. def closeAboveEMA = close from 1 bars ago > MovAvgExponential(EMA_LENGTH);
  90.  
  91. def isAboveMiddleVWAP = close > MiddleBand;
  92.  
  93. def withinTradingDay = SecondsFromTime(21.0) > 32900 and SecondsFromTime(21.0) < 55000;
  94.  
  95. def adxLowerLows = ADX from 1 bars ago > ADX;
  96. def adxHigherHighs = ADX from 1 bars ago < ADX;
  97. def dmiMinusLowerLows = DMI_MINUS from 1 bars ago > DMI_MINUS;
  98. def dmiPlusHigherHighs = DMI_PLUS from 1 bars ago < DMI_PLUS;
  99. def dmiBuySignal = (dmiPlusHigherHighs and adxLowerLows and dmiMinusLowerLows) or (dmiPlusHigherHighs and adxHigherHighs);
  100.  
  101. def topTail = ((high - close) / high) * 100;
  102.  
  103. def higherHighs = high from 2 bars ago > high from 1 bars ago and high from 1 bars ago > high;
  104.  
  105. def buy = RSI() > RSI_BUY_LIMIT and rising and closeAboveEMA and isAboveMiddleVWAP and withinTradingDay and CCI(22) > 13 and CCI(22) < 100 and dmiBuySignal;
  106.  
  107. def sell = close < MovAvgExponential(EMA_LENGTH) or topTail > 0.3 or SecondsFromTime(21.0) > 55000 or CCI(5) < 0;
  108.  
  109. AddOrder(OrderType.BUY_TO_OPEN, buy, open[-1], 50, Color.GREEN, Color.GREEN, name = "CALL");
  110. 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