Announcement

Collapse
No announcement yet.

indicator not calculating properly

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

  • indicator not calculating properly

    Hi there,

    I wrote this custom indicator with the desire that it would calculate on each and every trade, rather than on the close.

    When I apply it to the chart I notice that sometimes it apppears to
    be calculating on every trade and other times the market ticks up and down several times with no change in the total being returned in the indicator.

    The if else statement that I have comented out within the EFS internal, is just another attempt that I made to get it to work properly.

    Any help is appreciated.

    Thanks,

    John
    Attached Files

  • #2
    Hello John,

    What is happening is that at newbar, your indicator updates by the initial value assigned to nTradeSize because you're only assigning a value to this variable at start up. Your variables are static as a result. To debug logic issues like this, try placing the variables in debugPrintln statements. For example, place the following line of code in main just before your return statement and you will see what the static values are.

    PHP Code:
    debugPrintln(nTradeSize "  " nTrade "  " nBid "  " nAsk); 
    The solution is to add some logic inside main() that will update these variables on each tick in real time. Try the following.

    PHP Code:
    function main() {

        if (
    getCurrentBarIndex() < 0) return;
        
        
    nTradeSize    getMostRecentTradeSize();  
        
    nTrade        getMostRecentTrade();
        
    nBid          getMostRecentBid();
        
    nAsk          getMostRecentAsk();
        
        return 
    tangent1();

    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