Announcement

Collapse
No announcement yet.

Donchian entry problems

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

  • Donchian entry problems

    Hi,

    I'm trying to create a simple Donchian entry code. However when I load the following code I encounter two problems;

    a) For some reason it does not show up in the price study...even though it is set to true.
    b) When I try and backtest this entry code no trades are generated at all.

    Any ideas?

    var vDonch = null;
    var vDonch2 = null;

    function preMain() {

    setPriceStudy(true);
    setStudyTitle("Donchian");
    setCursorLabelName("Upper");
    setCursorLabelName("Lower");
    setDefaultBarFgColor (Color. blue, 0);
    setDefaultBarFgColor (Color. red, 1);
    setDefaultBarThickness(1, 0);
    setDefaultBarThickness(1, 1);

    function main() {

    if (Strategy.isInTrade() == false);
    if (vDonch == null) vDonch = new DonchianStudy (20);
    if (vDonch2 == null) vDonch2 = new DonchianStudy (20);

    if(high() > vDonch.getValue (DonchianStudy.UPPER,-1)
    &&!Strategy.isLong()) {

    Strategy.doLong("Long", Strategy.MARKET,Strategy.NEXTBAR);
    setPriceBarColor(Color.blue);

    }

    if (low() <vDonch2.getValue (DonchianStudy.LOWER,-1)
    &&!Stategy.isShort()) {

    Strategy.doShort("Short", Strategy.MARKET,Strategy.NEXTBAR);
    setPriceBarColor(Color.red);

    }

    return new Array

    (vDonch.getValue (DonchianStudy.UPPER),
    vDonch2.getValue (DonchianStudy.LOWER));

    }
    }

  • #2
    thestranger
    There are some errors in the script
    - Missing closing bracket for the preMain() function [this is incorrectly added at the end of the main() function]
    - The DonchianStudy() requires two parameters. See the link for the correct syntax
    - Stategy instead of Strategy in &&!Stategy.isShort()) {
    - The setPriceBarColor() command needs to be used in conjunction with setColorPriceBars() and setDefaultPriceBarColor(). See this article for more information
    Alex

    Comment


    • #3
      thanks Alex

      Comment


      • #4
        thestranger
        Adding to my prior reply. Unless you have a specific reason for declaring two instances of the DonchianStudy() [ie vDonch and vDonch2] you only need to create one instance of the study and then use the .getValue(DonchianStudy.UPPER) and .getValue(DonchianStudy.LOWER) methods to retrieve the upper and lower channels.
        Alex

        Comment


        • #5
          excellent, I'll strip it out then if its not required.

          thanks again for the pointer.

          Comment

          Working...
          X