Announcement

Collapse
No announcement yet.

RSIPriceBars study

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

  • RSIPriceBars study

    Alex: I need your help. I have downloaded the RSIPriceBars.esf formula that is included with E-Signal advanced charts. I have added a sound feature but whenever the RSI crosses 70 or crosses 30, the sound is continuous as the red or lime price bar is forming. Can you look at the formula for me. I would like the sound effect to only happen at the end(completion) of the red or lime candlestick if it stays lime or red. Hopefully, this makes sense. Anyway, I have not bothered you since Feb 2005 so I would appreciate your usual and expert help. Thank You. Paul W.


    ************************************************** ************************************************** */
    function preMain() {
    setColorPriceBars(true);
    setDefaultPriceBarColor(Color.blue);
    }

    function main(nInputLength) {
    if(nInputLength == null)
    nInputLength = 14;

    var vValue;

    var vValue = call("/library/RSIStandard.efs", nInputLength);

    var fp1 = new FunctionParameter("Source", FunctionParameter.STRING);
    fp1.setName("Source");
    fp1.addOption("Close");
    fp1.addOption("High");
    fp1.addOption("Low");
    fp1.addOption("Open");
    fp1.addOption("HL/2");
    fp1.addOption("HLC/3");
    fp1.addOption("OHLC/4");
    fp1.setDefault("Close"); //Edit this value to set a new default

    if(vValue >= 70) {
    setPriceBarColor(Color.red);
    setBarThickness(6);
    setBarFgColor(Color.red);
    Alert.playSound("chimes.wav");

    } else if(vValue <= 30) {
    setPriceBarColor(Color.lime);
    setBarThickness(6);
    setBarFgColor(Color.lime);
    Alert.playSound("chimes.wav");

    }

    return (vValue);

    }
    Attached Files

  • #2
    Paul
    To check for the condition only at the completion of a bar you have two options.
    The first and simplest one is to add setComputeOnClose() in preMain() of your script. This will force the efs to calculate only on completed bars.
    For the second option instead you need to enclose the conditions that trigger the alert in a BARSTATE_NEWBAR statement and evaluate the state of the RSI at the prior bar. However given the script this solution requires a few other changes as well.
    The first thing that needs to be modified is the variable vValue which needs to be declared as a global variable and not a local variable (ie it needs to be outside of main and not inside main as it currently is). You also need to declare another global variable called vValue_1 which will be the value of the RSI at the prior bar (you will need this to create the conditions)

    PHP Code:
    var vValue null;//this is a global variable
    var vValue_1 null;//as above

    function main(nInputLength){
    if(
    nInputLength == null)
    nInputLength 14;

        var 
    vValue//remove this line

        
    var vValue call("/library/RSIStandard.efs"nInputLength);//remove var from this line

        //rest of your code here 
    Then at every new bar you need to assign to the variable vValue_1 the current value of vValue. This needs to happen before you calculate the current value of vValue.

    PHP Code:
    var vValue null;//this is a global variable
    var vValue_1 null;//as above

    function main(nInputLength){
    if(
    nInputLength == null)
    nInputLength 14;

        if(
    getBarState()==BARSTATE_NEWBAR){//at every new bar 
            
    vValue_1 vValue;//take the last value of vValue and assign it to vValue_1
        
    }

        
    vValue call("/library/RSIStandard.efs"nInputLength);

        
    //rest of your code here 
    Now that you have the value of the RSI at the prior bar you can create your condition that will be checked only at the completion of a bar

    PHP Code:
    var vValue null;//this is a global variable
    var vValue_1 null;//as above

    function main(nInputLength){
    if(
    nInputLength == null)
    nInputLength 14;

        if(
    getBarState()==BARSTATE_NEWBAR){//at every new bar 
            
    vValue_1 vValue;//take the last value of vValue and assign it to vValue_1
            
    if(vValue_1>=70 || vValue_1<=30){//if the RSI at the prior bar is >=70 OR <=30
                
    Alert.playSound("chimes.wav");//play sound
            
    }
        }

        
    vValue call("/library/RSIStandard.efs"nInputLength);

        
    //rest of your code here 
    Lastly you need to clean up the rest of the script. Delete the following section from main as that is not where it is supposed to be (and is not used in the context of the script)

    PHP Code:
    var fp1 = new FunctionParameter("Source"FunctionParameter.STRING);
    fp1.setName("Source");
    fp1.addOption("Close");
    fp1.addOption("High");
    fp1.addOption("Low");
    fp1.addOption("Open");
    fp1.addOption("HL/2");
    fp1.addOption("HLC/3");
    fp1.addOption("OHLC/4");
    fp1.setDefault("Close"); //Edit this value to set a new default 
    And from the conditions that in your original script color the plot and also trigger the sound remove the commands to play the sound.
    Apply the changes suggested above and if you encounter any problems post the efs (preferably enclosing it with PHP tags as I have done) and I will look at it
    Alex

    Comment

    Working...
    X