Announcement

Collapse
No announcement yet.

EFS doesn't always update chart or pop up message

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

  • EFS doesn't always update chart or pop up message

    I wrote this (borrowed parts of other people's code) and am wondering what I did wrong.

    The EFS doesn't always update the chart or pop up a message. If applied to a chart of past data, it works fine. It does not always update on a live chart. Sometimes it will and sometimes it won't.

    Thanks for the help.

    Code:
    var vADXDM = new ADXDMStudy(14);
    var vLastAlert = -1;
    
    function preMain() {
    
        setPriceStudy(true);
        setStudyTitle("thEdge");
        setShowCursorLabel(false);
        
    }
    
    function main() {
    
        if (getBarState() != BARSTATE_NEWBAR) 
        return;
     
            if (
                vADXDM.getValue(ADXDMStudy.PDI, -1) < vADXDM.getValue(ADXDMStudy.NDI, -1) &&
                vADXDM.getValue(ADXDMStudy.PDI) > vADXDM.getValue(ADXDMStudy.NDI)
            ) onAction1();
             
     
            else if (
                vADXDM.getValue(ADXDMStudy.PDI, -1) > vADXDM.getValue(ADXDMStudy.NDI, -1) &&
                vADXDM.getValue(ADXDMStudy.PDI) < vADXDM.getValue(ADXDMStudy.NDI)
            ) onAction2();
     
        return ;
    
    }
    
    function onAction1() {
        setBarBgColor(Color.green);
        Alert.addToList(getSymbol(), "BUY", Color.black, Color.green);
        Alert.playSound("C:\\PROGRAM FILES\\ESIGNAL\\Sounds\\Ding.wav");
        Strategy.doLong("", Strategy.MARKET, Strategy.THISBAR, Strategy.DEFAULT, 0);
            if (vLastAlert != 1) Strategy.doCover("", Strategy.CLOSE, Strategy.THISBAR, Strategy.ALL, 0);
        vLastAlert = 1;
        
       
    }
     
    function onAction2() {
        setBarBgColor(Color.red);
        Alert.addToList(getSymbol(), "SELL", Color.black, Color.red);
        Alert.playSound("C:\\PROGRAM FILES\\ESIGNAL\\Sounds\\Ding.wav");
        Strategy.doShort("", Strategy.MARKET, Strategy.THISBAR, Strategy.DEFAULT, 0);
            if (vLastAlert != 2) Strategy.doSell("", Strategy.CLOSE, Strategy.THISBAR, Strategy.ALL, 0);
        vLastAlert = 2;
        
    }
    Last edited by CommercEngineer; 11-01-2005, 06:42 PM.

  • #2
    you have written your efs to return if it is not a new bar. Then on a new bar, it executes your conditional alert code.

    When you are running real-time, on a new bar, you need to understand that when you refer to the previous bar with a vADXDM.getValue(ADXDMStudy.PDI, -1), you are looking at the value of the indicator at the close of the last bar, 1 tic previous. Your next value you look at in the next conditional vADXDM.getValue(ADXDMStudy.PDI) is looking at the current bar, which is only 1 tic long (so far).

    This works fine when looking at historical data (as you have seen), however, as written, it is not doing what you believe after all the historical bars have run and you are in real time. There are several ways to remedy this as you have set the efs up.

    The first is to set up the efs to only compute on close. You can do this by placing this line in preMain() setComputeOnClose(). You can remove the line to test for newbar then.

    Alternatively, you can query the last bar (-1) and the previous bar to that (-2) and leave the efs pretty much as is.

    e.g. vADXDM.getValue(ADXDMStudy.PDI, -2) and

    vADXDM.getValue(ADXDMStudy.PDI,-1)

    I hope this helps

    Comment


    • #3
      Thank you.

      I'll modify the code and post if it works tonight.

      Comment


      • #4
        works a lot better.

        Originally posted by CommercEngineer
        Thank you.

        I'll modify the code and post if it works tonight.

        Comment


        • #5
          CommercEngineer,

          You are most welcome, I am glad this worked out for you.

          Comment

          Working...
          X