Announcement

Collapse
No announcement yet.

Highest high or Donchian won't seem to work for me

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Highest high or Donchian won't seem to work for me

    Can anyone tell me why this code may not be working. It works fine without the "high() > highest(3,high())" portion.

    if(getBarState()==BARSTATE_NEWBAR){
    if(!Strategy.isLong() && vMA1.getValue(MAStudy.MA,-1) > vMA2.getValue(MAStudy.MA,-1) &&
    high() > highest (3, high())){
    Strategy.doLong("Long",Strategy.CLOSE,Strategy.THI SBAR);
    Alert.playSound("ding.wav");
    nStopPrice = close()-(2*atr(14));
    }

    Any help would be greatly appreciated.

    Thanks

  • #2
    curly68
    By definition the current value of high() cannot be greater than the current value of highest(3,high()). You need to look at the prior value of highest(3,high())
    Replace high()>highest(3,high()) with high(0)>upperDonchian(3,-1) and it should work. In this specific context you cannot use the function highest() because it does not have barIndex as a parameter. You can however declare it as a series and then retrieve the prior value ie
    var HighestH = highest(3,high());
    if (high(0)>HighestH.getValue(-1))

    Alex

    Comment


    • #3
      Thanks

      Thanks for that Alexis. I didn't realise the current bar would be included when using "highest". Of course it should and it all makes perfect sense now, thanks again.

      Comment

      Working...
      X