Announcement

Collapse
No announcement yet.

stopbuy coding after valid signal

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

  • stopbuy coding after valid signal

    hello !

    i´m playing a little bit with strategycoding.
    i got something together, but i have a problem to code
    that if the signalbar was valid, the system should wait until we got a price that was 2 points higher then the high of the signalbar (for longtrades) or 2 point lower then the low (for shorttrades).

    i´m not sure, on what place i have to insert this coding.

    i tryed to change the tradeentryprice-rule and as a aditional rule for the valid signal.
    the best would be, if i could make a variable, that i get as soon i had a valid signalbar. then i could use the variable for the second requirement.

    it would be great if you could help me.

    thank you
    ************************************************** **

    var nNewTrade;
    var nsignal;
    var nTradeEntryPrice;
    var ProfitTarget1 = 20.0;

    function premain() {
    setPriceStudy(true);
    setStudyTitle("Sample Profit Code");
    setCursorLabelName("PT CODE");
    }

    function main() {

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

    if ((Strategy.isInTrade() == true) && (Strategy.isShort() == true)) {
    if (low() <= (nTradeEntryPrice - ProfitTarget1)) {
    Strategy.doCover("Short PT1 Exit", Strategy.STOP, Strategy.THISBAR, Strategy.getDefaultLotSize(), (nTradeEntryPrice - ProfitTarget1));
    }
    }
    if ((Strategy.isInTrade() == true) && (Strategy.isLong() == true)) {
    if (high() >= (nTradeEntryPrice + ProfitTarget1)) {
    Strategy.doSell("Long PT1 Exit", Strategy.STOP, Strategy.THISBAR, Strategy.getDefaultLotSize(), (nTradeEntryPrice + ProfitTarget1));
    }
    }

    if (Strategy.isInTrade() == false) {

    if ((high()-low()) > 12.5 && close() >= open() && open()-low() > high()-close() && open()-low() >= close()-open() && close() > ((high()+low())/2) && low() < low(-1)) {
    nNewTrade = 1;
    nsignal = 1;
    }


    if ((high()-low()) > 12.5 && close() >= open() && high()-close() > open()-low() && high()-close() >= close()-open() && open() < ((high()+low())/2) && high() > high(-1)) {
    nNewTrade = 1;
    nsignal = -1;
    }

    }
    if (nNewTrade == 1) {
    if (Strategy.isInTrade() == true) {
    if ((nsignal > 0) && (Strategy.isShort() == true)) {
    Strategy.doCover("Exit Short", Strategy.MARKET, Strategy.NEXTBAR);
    Strategy.doLong("Rev Long", Strategy.MARKET, Strategy.NEXTBAR);
    }
    if ((nsignal < 0) && (Strategy.isLong() == true)) {
    Strategy.doSell("Exit Long", Strategy.MARKET, Strategy.NEXTBAR);
    Strategy.doShort("Rev Short", Strategy.MARKET, Strategy.NEXTBAR);
    }
    } else {
    if ((nsignal > 0)) {
    Strategy.doLong("Go Long", Strategy.MARKET, Strategy.NEXTBAR);
    }
    if ((nsignal < 0)) {
    Strategy.doShort("Go Short", Strategy.MARKET, Strategy.NEXTBAR);
    }
    }
    }

    }

  • #2
    Hello thedon,

    I made a few changes to your code for you to test. Let me now if this works the way you intended it to.

    PHP Code:
    var nTradeEntryPrice

    function 
    preMain() {
        
    setPriceStudy(true);
        
    setStudyTitle("Sample Profit Code");
        
    setShowCursorLabel(false);
    }

    function 
    main(ProfitTarget1) {
        if (
    getCurrentBarIndex() == 0) return;
        
        if (
    ProfitTarget1 == nullProfitTarget1 20.0;
        
        var 
    vOpen open();
        var 
    vHigh high();
        var 
    vLow low();
        var 
    vClose close();

        if (
    Strategy.isShort() == true) {
            if (
    vLow <= (nTradeEntryPrice ProfitTarget1)) {
                
    Strategy.doCover("Short PT1 Exit"Strategy.STOPStrategy.THISBARStrategy.getDefaultLotSize(), (nTradeEntryPrice ProfitTarget1));
            }
        }

        if (
    Strategy.isLong() == true) {
            if (
    vHigh >= (nTradeEntryPrice ProfitTarget1)) {
                
    Strategy.doSell("Long PT1 Exit"Strategy.STOPStrategy.THISBARStrategy.getDefaultLotSize(), (nTradeEntryPrice ProfitTarget1));
            }
        }

        if (
    Strategy.isInTrade() == false) { 
            if (
    vHigh-vLow 12.5 && vClose >= vOpen && vOpen-vLow vHigh-vClose && vOpen-vLow >= vClose-vOpen && vClose > (vHigh+vLow)/&& vLow low(-1)) {
                
    Strategy.doLong("Rev Long"Strategy.MARKETStrategy.NEXTBAR);
                
    nTradeEntryPrice open(1);
            }
            if (
    vHigh-vLow 12.5 && vClose >= vOpen && vHigh-vClose vOpen-vLow && vHigh-vClose >= vClose-vOpen && vOpen < (vHigh+vLow)/&& vHigh high(-1)) {
                
    Strategy.doShort("Rev Short"Strategy.MARKETStrategy.NEXTBAR);
                
    nTradeEntryPrice open(1);
            }
        }
        
        return;

    Attached Files
    Jason K.
    Project Manager
    eSignal - an Interactive Data company

    EFS KnowledgeBase
    JavaScript for EFS Video Series
    EFS Beginner Tutorial Series
    EFS Glossary
    Custom EFS Development Policy

    New User Orientation

    Comment


    • #3
      Hello Jason,

      the coding is now much simpller, thank you for that.

      But unfortunately my problem is not solved.

      What i need is something like a second requirement.
      the first one is, that i need the valid signalbar itself.
      But i dont want to enter the market as soon i got the signalbar,
      í like to add one more requirement. only if i get the signalbar AND one of the following bars (not only the following) hits the price from the high of the signalbar PLUS 12 points.

      That means, if the high of the bullish "hammer-bar" was 3400, and the signalbar is valid then i will only enter if the market hits 3412. If the market doesnt hit this price, then i dont take the trade.

      May you have a idea here.
      That would be great
      Thank you
      thedon

      Comment


      • #4
        Hello thedon,

        Your new formula below uses global variables to keep track of when the signal bars are found. Once we have a signal, the formula will wait until your entry condition is met to enter the trade.

        PHP Code:
        var nTradeEntryPrice
        var 
        vTriggerLong false;
        var 
        vTriggerShort false;
        var 
        vSignalBarH null;
        var 
        vSignalBarL null;

        function 
        preMain() {
            
        setPriceStudy(true);
            
        setStudyTitle("Sample Profit Code");
            
        setShowCursorLabel(false);
        }

        function 
        main(ProfitTarget1EntryAmt) {
            if (
        getCurrentBarIndex() == 0) return;
            
            if (
        ProfitTarget1 == nullProfitTarget1 20.0;
            if (
        EntryAmt == nullEntryAmt 12.0;
            
            var 
        vOpen open();
            var 
        vHigh high();
            var 
        vLow low();
            var 
        vClose close();

            if (
        Strategy.isShort() == true) {
                if (
        vLow <= (nTradeEntryPrice ProfitTarget1)) {
                    
        Strategy.doCover("Short PT1 Exit"Strategy.STOPStrategy.THISBARStrategy.getDefaultLotSize(), (nTradeEntryPrice ProfitTarget1));
                    
        vTriggerShort false;
                }
            }

            if (
        Strategy.isLong() == true) {
                if (
        vHigh >= (nTradeEntryPrice ProfitTarget1)) {
                    
        Strategy.doSell("Long PT1 Exit"Strategy.STOPStrategy.THISBARStrategy.getDefaultLotSize(), (nTradeEntryPrice ProfitTarget1));
                    
        vTriggerLong false;
                }
            }

            if (
        Strategy.isInTrade() == false) { 
                if (
        vTriggerLong == true && close() >= vSignalBarH EntryAmt) {
                    
        Strategy.doLong("Rev Long"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, (vSignalBarH EntryAmt));
                    
        nTradeEntryPrice = (vSignalBarH EntryAmt);
                }
                if (
        vTriggerShort == true && close() <= vSignalBarL EntryAmt) {
                    
        Strategy.doShort("Rev Short"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, (vSignalBarL EntryAmt));
                    
        nTradeEntryPrice = (vSignalBarL EntryAmt);
                }
            }

            if (
        Strategy.isInTrade() == false) {
                if (
        vTriggerLong == false) {
                    if (
        vHigh-vLow 12.5 && vClose >= vOpen && vOpen-vLow vHigh-vClose && vOpen-vLow >= vClose-vOpen && vClose > (vHigh+vLow)/&& vLow low(-1)) {
                        
        vTriggerLong true;
                        
        vSignalBarH high();
                    }
                }
                if (
        vTriggerShort == false) {
                    if (
        vHigh-vLow 12.5 && vClose >= vOpen && vHigh-vClose vOpen-vLow && vHigh-vClose >= vClose-vOpen && vOpen < (vHigh+vLow)/&& vHigh high(-1)) {
                        
        vTriggerShort true;
                        
        vSignalBarL low();
                    }
                }
            }
            
            return;

        Attached Files
        Jason K.
        Project Manager
        eSignal - an Interactive Data company

        EFS KnowledgeBase
        JavaScript for EFS Video Series
        EFS Beginner Tutorial Series
        EFS Glossary
        Custom EFS Development Policy

        New User Orientation

        Comment

        Working...
        X