Announcement

Collapse
No announcement yet.

Rsi

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

  • waynecd
    replied
    Assuming that vx is the the current value of RSI if you are not using BARSTATE_ALLBARS otherwise the last RSI value. You now have to create a variable with the last RSI value. A simple way to do this is by:
    1. Make sure vx is a global variable, i.e., in a line right above "function main(...){" should be the code "var vx = null;"
    2. Add a second global variable there, like: "var vxLast = null;"
    3. Add the following code below the code you posted: "vxLast = vx;"
    4. Modify the trigger criteria to compare the last RSI value above/below the upper/lower levels and the current RSI crossing the levels to the other side.
    5. Assumptions: enter long if oversold and RSI <30 then crosses above 30 and short if overbought and then crosses below 70. Longs exit when RSI crosses 70 (now overbought) and shorts exit when RSI crosses 30 (now oversold)

    Sample follows:

    PHP Code:
    function premain(){
    ...
    }

    var 
    vx null;
    var 
    vxLast null;

    function 
    main(){
    //...(enter study code here)
    //Close trade?
        
    if(Strategy.isLong()) {
            if(
    vx >= 70) {//exit longs when RSI is overbought
                
    Strategy.doSell("Exit Long Signal"Strategy.CLOSEStrategy.THISBAR,Strategy.ALL);
            }
        }
        if(
    Strategy.isShort()) {
            if(
    vx <= 30) {//exit shorts when RSI is oversold
                
    Strategy.doCover("Exit Short Signal"Strategy.CLOSEStrategy.THISBAR,Strategy.ALL);
            }
        }

        
    //Open new position?
            
    if(vxLast <= 30 && vx 30) {//oversold then turns up through 30 to go long
                
    if(!Strategy.isLong()) {
                    
    Strategy.doLong("RSI low",Strategy.CLOSE,Strategy.THISBAR,SharesToTrade);
                }
            } 
            if(
    vxLast >= 70 && vx 70) {//overbought then turns down through 70 to go short
                
    if(!Strategy.isShort()) {
                    
    Strategy.doShort("RSI high",Strategy.CLOSE,Strategy.THISBAR,SharesToTrade);
                }
            }
        }

    }
        
    vxLast vx
    I'll leave the testing to you.
    Last edited by waynecd; 06-09-2009, 01:47 PM.

    Leave a comment:


  • marc
    replied
    waynecd, correct!

    the code i am using...

    PHP Code:

        
    //Close trade?
        
    if(Strategy.isLong()) {
            if(
    vx <= 30) {
                
    Strategy.doSell("Exit Long Signal"Strategy.CLOSEStrategy.THISBAR,Strategy.ALL);
            }
        }
        if(
    Strategy.isShort()) {
            if(
    vx >= 70) {
                
    Strategy.doCover("Exit Short Signal"Strategy.CLOSEStrategy.THISBAR,Strategy.ALL);
            }
        }

        
    //Open new position?
            
    if(vx >= 70) {
                if(!
    Strategy.isLong()) {
                    
    Strategy.doLong("RSI low",Strategy.CLOSE,Strategy.THISBAR,SharesToTrade);
                }
            } 
            if(
    vx <= 30) {
                if(!
    Strategy.isShort()) {
                    
    Strategy.doShort("RSI high",Strategy.CLOSE,Strategy.THISBAR,SharesToTrade);
                }
            }
        } 

    Leave a comment:


  • waynecd
    replied
    It seems you have an efs script that triggers trades, just not where you want it to. If that is the case it is just a matter of changing the parameters that define when the trade is triggered.

    If you post the code you already have it will likely be easy to show you how to modify the trigger parameters.

    Leave a comment:


  • marc
    started a topic Rsi

    Rsi

    I have just started using e-signal / EFS codes to perform some back testing.

    Using some sample scripts i have done some testing with the RSI study.

    However, i am looking to change it ,so instead of getting into the trade when the price crosses the line (either over bought / over sold) i am looking to get into the trade when the price exists the overbought / sold area, ahnd then get out of the trade, when it enters the other area.

    If anyone can point me in the direction of where to start looking, would be much appreciated.


    Thanks
Working...
X