Announcement

Collapse
No announcement yet.

Can't get any trades on strategy

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

  • Can't get any trades on strategy

    var newtrade = 0;
    var entpric = 0;

    Hi:

    This program should generate a sell signal when 2 bars are lower one from the previous one, and a buy signal when higher from previous one. It is not generating any trades in back testing. WHY?

    Thank you


    function preMain(){
    setPriceStudy(true);
    setStudyTitle("STRAT_TEST");
    setCursorLabelName("STEST",0);

    }


    function main(proftar, xstop){
    if(proftar == null)
    proftar = 5;
    if(xstop == null)
    xstop = 2.5;

    if (newtrade == 1)
    entpric = open();


    if (Strategy.isInTrade() == true && (Strategy.isShort() == true)) {
    if (low() <= (entpric - proftar)) {
    Strategy.doCover("Short PT1 Exit", Strategy.STOP, Strategy.THISBAR,
    Strategy.getDefaultLotSize(), (entpric - proftar));

    }
    }
    if (Strategy.isInTrade() == true && (Strategy.isLong() == true)) {
    if (high() >= (entpric + proftar)) {
    Strategy.doSell("Long PT1 Exit", Strategy.STOP, Strategy.THISBAR,
    Strategy.getDefaultLotSize(), (entpric + proftar));

    }
    }
    if (Strategy.isInTrade() == true && (Strategy.isShort() == true)) {
    if (high() >= (entpric + xstop)) {
    Strategy.doCover("Short stp Exit", Strategy.STOP, Strategy.THISBAR,
    Strategy.getDefaultLotSize(), (entpric + xstop));

    }
    }
    if (Strategy.isInTrade() == true && (Strategy.isLong() == true)) {
    if (low() <= (entpric - xstop)) {
    Strategy.doSell("Long stp Exit", Strategy.STOP, Strategy.THISBAR,
    Strategy.getDefaultLotSize(), (entpric - xstop));

    }
    }

    newtrade = 0;

    if(low() < low(1) && low(1) < low(2) && Strategy.isInTrade() == false){
    Strategy.doShort("GO SHORT", Strategy.MARKET, Strategy.Nextbar);
    newtrade = 1;
    }

    if(high() > high(1) && high(1) > high(2) && Strategy.isInTrade() == false){
    Strategy.doLong("GO LONG", Strategy.MARKET, Strategy.Nextbar);
    newtrade = 1;
    }
    }

  • #2
    sol123
    Are high(1) low(1) high(2), etc in your code supposed to reference the highs or lows of 1 or 2 bars ago?
    If that is the case they need to be high(-1) low(-1) high(-2) etc
    Alex

    Comment

    Working...
    X