Announcement

Collapse
No announcement yet.

Multi-Timeframe Stochastics

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

  • Multi-Timeframe Stochastics

    I have been trying to create an alert for Stochastics, whereby for example, over a 1 min and 2 min timeframe, an alert will fire.

    As I am dealing with two different timeframes;
    Stoch- 2min will cross and be confirmed with the getBarState() on the next tick.
    At exactly the same time the 2 min period ends, I am looking for the 1 min to cross and be confirmed with the getBarState() on the next tick, (it should be the same tick that confirms the 2 min)

    In order for this EFS to be correct, I am assuming because the result is based on closed price bars, that if I run this EFS realtime during the trading day, that if I were to run the exact same EFS after trading hours the results would be exactly the same.

    Unfortunately, the results I have been getting are not the same, therefore I must be doing something incorrectly.

    If anyone can add any thoughts as to where I might be going wrong, it would be greatly appreciated.

    I am also attaching the latest version of my EFS for review

    Royce
    Attached Files

  • #2
    Hello Royce,

    Here are a couple suggestions for you to start with.

    With your set of if() statements, you do not need a separate if() statement that checks for the new bar state of the 2-min interval for each condition you want to check. Change that structure from...

    PHP Code:
    if (getBarStateInterval("2") == BARSTATE_NEWBAR){
            if (...){}            
    }    

    if (
    getBarStateInterval("2") == BARSTATE_NEWBAR){
            if (...){}            
    }    

    if (
    getBarStateInterval("2") == BARSTATE_NEWBAR){
            if (...){}            
    }    

    if (
    getBarStateInterval("2") == BARSTATE_NEWBAR){
            if (...){}            

    to the following structure ....

    PHP Code:
    if (getBarStateInterval("2") == BARSTATE_NEWBAR){
            if (...){}            
            if (...){}            
            if (...){}            
            if (...){}            

    The second suggestion is to change your conditions to look only at the completed bars, which are bar indexes less than 0 (i.e. -1 and -2). Evaluating bar 0 at the new bar state is the reason real time signals will not match when you reload this study after hours. In real time, the formula processes every trade. At the new bar state in real time the bar 0 references are referring to the opening trade for the bar. After hours ( or once the real time bar becomes a historical bar) when you reload the formula, each historical bar is only processed once. The bar state for these historical evaluations is BARSTATE_NEWBAR, but the formula is evaluating completed bar data. A bar 0 reference on historical bars refers to the closing value of the bar. This logic creates the difference that you are seeing when comparing your current code's real time result with the historical result after hours. The key is to not use the "_01" variables in your conditions.
    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