Announcement

Collapse
No announcement yet.

Syntax error

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

  • Syntax error

    Hi,

    I'm getting a syntax error on the else if logic in "stop loss/profit exit" part of the the following code. I dont understand why? I'm sure its very simple!
    PHP Code:
    var vDonch null;
    var 
    vDonchExit null;
    var 
    nNewTrade;
    var 
    nSignal;
    var 
    nTradeEntryPrice;
    var 
    nStopLevel;
    var 
    atrLevel;
    var 
    inTrade;

    function 
    preMain() {

    setPriceStudy(true);
    setStudyTitle("Donchian");
    setCursorLabelName("Upper"0);
    setCursorLabelName("Lower"1);
    setColorPriceBars(true);
    setDefaultBarFgColor (Colorblue0);
    setDefaultBarFgColor (Colorred1);
    setDefaultBarThickness(10);
    setDefaultBarThickness(11);
    setDefaultPriceBarColor(Color.black);

    }

    function 
    main() {

    if (
    vDonch == nullvDonch = new DonchianStudy (20,0);
    if (
    vDonch2 == nullvDonch2 = new DonchianStudy (10,0);

    // identify entry price

    if (Strategy.isInTrade() == true && (nNewTrade == 1)) {
    nTradeEntryPrice open();
    nNewTrade 0;
    atrLevel atr(20);

    if (
    Strategy.isLong() == truesetPriceBarColor(Color.green);
    if (
    Strategy.isShort() == truesetPriceBarColor(Color.red);

    }

    //stop loss/profit exit

    if (Strategy.isLong() == true && (Strategy.isInTrade() == true));
    if (
    low() <= (nTradeEntryPrice nStopLevel)); {

    Strategy.doSell("Stop Sell"Strategy.LIMITStrategy,THISBARStrategy.ALL,nStopLevel);

    inTrade 0

    }

    else if (
    low() <= vDonch2.getValue(DonchianStudy.LOWER, -1)) {
    var 
    longExit vDonch2.getValue(DonchianStudy.LOWER, -1));
    if (
    open() < longExitlongExit open();

    Strategy.doSell("10 day low",Strategy.LIMIT,Strategy.THISBAR,Strategy.ALL,longExit);

    inTrade 0;

    }

    if (
    Strategy.isShort() == true && (Strategy.isInTrade() == true));
    if (
    high() >= (nTradeEntryPrice nStopLevel)); {

    Strategy.doCover("Cover",Strategy.LIMITStrategy,THISBAR,Strategy.ALL,nStopLevel);

    inTrade 0;

    }

    else if (
    high() >= vDonch2.getValue(DonchianStudy.UPPER, -1)) {
    var 
    shortExit vDonch2.getValue(DonchianStudy.UPPER, -1));
    if (
    open() > shortExitshortExit open();

    Strategy.doSell("10 day low",Strategy.LIMIT,Strategy.THISBAR,Strategy.ALL,shortExit);

    inTrade 0;

    }

    //identify entry signal

    if inTrade == 0;
    if 
    high() >= vDonch.getValue(DonchianStudy.UPPER, -1)) {
    nNewTrade 1;
    nSignal 1;
    nStopLevel nTradeEntryPrice -  (atrLevel 2);

    }

    if 
    inTrade == 0;
    if 
    low() <= vDonch.getValue(DonchianStudy.LOWER, -1)) {
    nNewTrade 1;
    nSignal = -1;
    nStopLevel nTradeEntryPrice +  (atrLevel 2);

    }

    //execute trade

    if(nNewTrade == 1) && (nSignal 0) {

    Strategy.doLong("Long"Strategy.MARKETStrategy.NEXTBAR);

    inTrade 1;

    }

    if(
    nNewTrade == 1)  && (nSignal 0) {

    Strategy.doShort("Short"Strategy.MARKETStrategy.NEXTBAR);

    inTrade 1;

    }

    return new Array

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


    Thanks

  • #2
    Your code was hard to read -- try indenting blocks.

    Anyway, the problem may be here:

    if (low() <= (nTradeEntryPrice - nStopLevel)); {....}

    where you have an extra ; after the if statement.

    Take a look at this also:

    if (Strategy.isLong() == true && (Strategy.isInTrade() == true));

    what does this mean -- it does nothing?

    Comment


    • #3
      thanks buhrmaster

      Comment

      Working...
      X