Board logo

标题: 【TPO_VA_HighLow】 [打印本页]

作者: 龙听    时间: 2022-11-2 14:00     标题: 【TPO_VA_HighLow】

  1. inputs:
  2.         VAPercent(NumericSimple),
  3.         VAHigh(NumericRef),
  4.         VALow(NumericRef);


  5. if (VAPercent < 0 or VAPercent > 100) then
  6.         raiseruntimeerror("Incorrect VAPercent input value! Supported values are from 0 to 100.");

  7. if (TPO_POC < 0) then
  8.         raiseruntimeerror("TPO_VA_HighLow function can be applied to TPO resolution only!");

  9. vars: _total(0), _target(0), _upLvlSearch(0), _dnLvlSearch(0), _summBlocks(0), _ticksize(TickSize), _candidateUp(0), _candidateUpPrice(0), _candidateDn(0), _candidateDnPrice(0), _skipZeroIdx(0);

  10. TPO_VA_HighLow = 0;

  11. _total = TPO_TotalBlocks;
  12. _target = intportion(_total * VAPercent * 0.01);

  13. if (TPO_POC_Value >= _target) then begin
  14.         VAHigh = TPO_POC;
  15.         VALow = TPO_POC;
  16.         #return;
  17. end;

  18. if (_target > _total - minlist(TPO_Levels_Value(TPO_Levels_Low, 0), TPO_Levels_Value(TPO_Levels_High, 0))) then begin
  19.         VAHigh = TPO_Levels_High;
  20.         VALow = TPO_Levels_Low;
  21.         #return;
  22. end;

  23. _upLvlSearch = TPO_POC;
  24. _dnLvlSearch = TPO_POC;
  25. _summBlocks = TPO_POC_Value;

  26. while _summBlocks < _target begin
  27.         // can move up
  28.         if (_upLvlSearch < TPO_Levels_High) then begin

  29.                 // can move down
  30.                 if (_dnLvlSearch > TPO_Levels_Low ) then begin

  31.                         _candidateUpPrice = _upLvlSearch + _ticksize;
  32.                         _candidateUp = TPO_Levels_Value(_candidateUpPrice, 0);
  33.                        
  34.                         // skip possible zero blocks
  35.                         _skipZeroIdx = 2;
  36.                         while (_candidateUp <= 0 and _upLvlSearch + _skipZeroIdx * _ticksize <= TPO_Levels_High) begin
  37.                                 _candidateUpPrice = _upLvlSearch + _skipZeroIdx * _ticksize;
  38.                                 _candidateUp = TPO_Levels_Value(_candidateUpPrice, 0);
  39.                                 _skipZeroIdx += 1;
  40.                         end;

  41.                         _candidateDnPrice = _dnLvlSearch - _ticksize;
  42.                         _candidateDn = TPO_Levels_Value(_candidateDnPrice, 0);

  43.                         // skip possible zero blocks
  44.                         _skipZeroIdx = 2;
  45.                         while (_candidateDn <= 0 and _dnLvlSearch - _skipZeroIdx * _ticksize >= TPO_Levels_Low) begin
  46.                                 _candidateDnPrice = _dnLvlSearch - _skipZeroIdx * _ticksize;
  47.                                 _candidateDn = TPO_Levels_Value(_candidateDnPrice, 0);
  48.                                 _skipZeroIdx += 1;
  49.                         end;

  50.                         // If both 'next'/adjacent prices have the same number of TPO's we choose the higher price.
  51.                         if (_candidateUp >= _candidateDn) then begin
  52.                                 _upLvlSearch = _candidateUpPrice;
  53.                                 _summBlocks += _candidateUp;
  54.                         end
  55.                         else begin
  56.                                 _dnLvlSearch = _candidateDnPrice;
  57.                                 _summBlocks += _candidateDn;
  58.                         end;
  59.                 end
  60.                 else begin
  61.                         _upLvlSearch += _ticksize;
  62.                         _summBlocks += TPO_Levels_Value(_upLvlSearch, 0);
  63.                 end;
  64.         end
  65.         else begin
  66.                 _dnLvlSearch -= _ticksize;
  67.                 _summBlocks += TPO_Levels_Value(_dnLvlSearch, 0);
  68.         end;
  69. end;

  70. VAHigh = _upLvlSearch;
  71. VALow = _dnLvlSearch;
复制代码





欢迎光临 龙听期货论坛 (http://www.qhlt.cn/) Powered by Discuz! 7.2