File Name: FVEStrategy.efs

Description:
FVE Strategy

Formula Parameters:
Samples - number of bars to calculate FVE: 50
FVEenterl - lower entry level of FVE: -20
FVEenteru - upper entry level of FVE: 10
MA - number of bars to calculate MA: 40
LRPeriod - number of bars to calculate Linear regression: 20
Bangle - the angle to buy: 30
Sangle - the angle to sell: -30
LRC - number of bars to calculate Linear regression slope: 30
UB - limit for Linear regression rising: 0.1
LB - limit for Linear regression falling: -0.5
BarToExitOn - number of bars to exit position: 70


Notes:
This is a strategy based on FVE (Finite Volume Elements) indicator.

Download File:
FVEStrategy.efs



EFS Code:
PHP Code:
/*********************************
Provided By:  
    eSignal (Copyright c eSignal), a division of Interactive Data 
    Corporation. 2008. All rights reserved. This sample eSignal 
    Formula Script (EFS) is for educational purposes only and may be 
    modified and saved under a new file name.  eSignal is not responsible
    for the functionality once modified.  eSignal reserves the right 
    to modify and overwrite this EFS file with each new release.


Description:        
    FVE Strategy 

Version:            1.0  10/14/2008

Notes:
    This is a strategy based on FVE (Finite Volume Elements) indicator. 

Formula Parameters:                                      Default:
    Samples - number of bars to calculate FVE                50  
    FVEenterl - lower entry level of FVE                        -20
    FVEenteru - upper entry level of FVE                        10
    MA - number of bars to calculate MA                         40
    LRPeriod - number of bars to calculate Linear regression    20
    Bangle - the angle to buy                                   30
    Sangle - the angle to sell                                  -30
    LRC - number of bars to calculate Linear regression slope   30
    UB - limit for Linear regression rising                     0.1
    LB - limit for Linear regression falling                    -0.5
    BarToExitOn - number of bars to exit position               70
**********************************/

var fpArray = new Array();
var 
bInit false;

function 
preMain(){
    
setPriceStudy(false);
    
setShowCursorLabel(false);
    
setShowTitleParametersfalse );
    
    
setStudyTitle("FVE Strategy");
    
setColorPriceBars(true);

    var 
x=0;
    
fpArray[x] = new FunctionParameter("Samples"FunctionParameter.NUMBER);
    
with(fpArray[x++]){
        
setName("Number Of Bars To Calculate FVE");        
        
setLowerLimit(1);        
        
setDefault(50);
    }
    
fpArray[x] = new FunctionParameter("FVEenterl"FunctionParameter.NUMBER);
    
with(fpArray[x++]){
        
setName("Lower Entry Level Pf FVE");
        
setLowerLimit(-100);        
        
setDefault(-20);
    }
    
fpArray[x] = new FunctionParameter("FVEenteru"FunctionParameter.NUMBER);
    
with(fpArray[x++]){
        
setName("Upper Entry Level Of FVE");
        
setLowerLimit(1);        
        
setDefault(10);
    }
    
fpArray[x] = new FunctionParameter("MA"FunctionParameter.NUMBER);
    
with(fpArray[x++]){
        
setName("Length To Calculate MA");
        
setLowerLimit(1);        
        
setDefault(40);
    }
    
fpArray[x] = new FunctionParameter("LRPeriod"FunctionParameter.NUMBER);
    
with(fpArray[x++]){
        
setName("Length To Calculate Linear Regression");
        
setLowerLimit(1);        
        
setDefault(20);
    }
    
fpArray[x] = new FunctionParameter("Bangle"FunctionParameter.NUMBER);
    
with(fpArray[x++]){
        
setName("The Angle To Buy");
        
setLowerLimit(0);        
        
setDefault(30);
    }
    
fpArray[x] = new FunctionParameter("Sangle"FunctionParameter.NUMBER);
    
with(fpArray[x++]){
        
setName("The Angle To Sell");
        
setLowerLimit(-100);        
        
setDefault(-30);
    }
    
fpArray[x] = new FunctionParameter("LRC"FunctionParameter.NUMBER);
    
with(fpArray[x++]){
        
setName("Length Linear Regression Slope");
        
setLowerLimit(1);        
        
setDefault(30);
    }
    
fpArray[x] = new FunctionParameter("UB"FunctionParameter.NUMBER);
    
with(fpArray[x++]){
        
setName("Limit Ror Linear Regression Rising");
        
setLowerLimit(0);        
        
setDefault(0.1);
    }
    
fpArray[x] = new FunctionParameter("LB"FunctionParameter.NUMBER);
    
with(fpArray[x++]){
        
setName("Limit For Linear Regression Falling");
        
setLowerLimit(-100);        
        
setDefault(-0.5);
    }
    
fpArray[x] = new FunctionParameter("BarToExitOn"FunctionParameter.NUMBER);
    
with(fpArray[x++]){
        
setName("Length To Exit Position");
        
setLowerLimit(1);        
        
setDefault(70);
    }
}

var 
EMA_1 0;
var 
EMA 0
var 
VolumePlusMinusArray = new Array();
var 
FVEArray = new Array();
var 
BarsSinceEntry 0;

var 
xTP null;

function 
main(SamplesFVEenterlFVEenteruMALRPeriodBangleSangleLRCUBLBBarToExitOn){
var 
nState getBarState();
var 
TP 0,
    
TP1 0,
    
MF 0,
    
Cintra .1,
    
Cinter .1,
    
CutOff 0,
    
VolumePlusMinus 0,
    
FVE 0,
    
Fvesum 0,
    
FveFactor 0,
    
Intra 0
    
Inter 0
    
Vintra 0
    
Vinter 0,
    
0
    
VolSum 0
    
/ (MA 1), 
    
vHL high(0) - low(0), 
    
vVar vHL 0.25,
    
vAddVar vVar 0.35
    
Condition1 false
    
Condition2 false
    
Condition3 false
    
Condition4 false
    
Condition5 false;

var    
IntraArray = new Array();
var    
InterArray = new Array();

    if (
nState == BARSTATE_ALLBARS) {
        if(
Samples == nullSamples 50;
        if(
FVEenterl == nullFVEenterl = -20;
        if(
FVEenteru == nullFVEenteru 10;
        if(
MA == nullMA 40;
        if(
LRPeriod == nullLRPeriod 20;
        if(
Bangle == nullBangle 30;
        if(
Sangle == nullSangle = -30;
        if(
LRC == null)    LRC 30;
        if(
UB == nullUB .1;
        if(
LB == nullLB = -.5;
        if(
BarToExitOn == nullBarToExitOn 70;
    }

    if (
bInit == false) {
        
xTP hlc3();
        
bInit true;
    }

    if(
getCurrentBarIndex() == 0) return;

    
setPriceBarColor(Color.black);

    for(
0Samplesi++){
        
IntraArray[i] = Math.log(high(-i)) - Math.log(low(-i));
        
InterArray[i] = Math.log(xTP.getValue(-i)) - Math.log(xTP.getValue(-i-1));
    }
    
    
Intra Math.log(high(0)) - Math.log(low(0));
    
Vintra StandardDev(IntraArraySamples);
    
Inter Math.log(xTP.getValue(0)) - Math.log(xTP.getValue(-1));
    
Vinter StandardDev(InterArraySamples);
    
CutOff Cintra Vintra Cinter Vinter;    
    
MF = (close(0) - (high(0) + low(0))/2)+ xTP.getValue(0) - xTP.getValue(-1);
    
    if(
MF CutOff close(0))
        
FveFactor 1;
    else if(
MF < -CutOff close(0))
        
FveFactor = -1;
    else
        
FveFactor=0;
        
    
VolumePlusMinus volume(0) * FveFactor;

    for(
Samples 10i--)
        
VolumePlusMinusArray[i] = VolumePlusMinusArray[1];
        
    
VolumePlusMinusArray[0] = VolumePlusMinus;
    
    for(
0Samplesi++){
        
Fvesum += VolumePlusMinusArray[i];
        
VolSum += volume(-i);
    }
    
    if(
VolumePlusMinusArray[Samples 1] != null){
        
FVE = (Fvesum VolSum) * 100;
        for(
LRPeriod 10i--)
            
FVEArray[i] = FVEArray[1];
        
FVEArray[0] = FVE;
        if (
getBarState() == BARSTATE_NEWBAR)
            
EMA_1 EMA;
        
EMA FVE  + (K) * EMA_1;
    }
    else
        return;
    
    
    if(
FVEArray[LRPeriod 1] != null){
        
BarsSinceEntry++;
        if(
FVE FVEenterl && FVE FVEenteru){
            
Condition1 true;
        }
        if(
LinearReg(FVEArray,LRPeriod,"AngleFC",LRC-1) > Bangle){
            
Condition2 true;
        }
        if(
FVE EMA){
            
Condition3 true;
        }
        if(
LinearReg(close(0,-LRC),LRC,"Slope",LRC-1) < UB LinearReg(close(0,-LRC),LRC,"Value",LRC-1) / 100 &&  LinearReg(close(0,-LRC),LRC,"Slope",LRC-1) > LB LinearReg(close(0,-LRC),LRC,"Value",LRC-1) / 100){
            
Condition4 true;
        }
        if(
LinearReg(FVEArray,LRPeriod,"AngleFC",LRC-1) < Sangle){
            
Condition5 true;
        }
        if(!
Strategy.isLong()  && Condition1 && Condition2 && Condition3 && Condition4){
            
Strategy.doLong("BUY"Strategy.CLOSEStrategy.THISBAR);
            
setPriceBarColor(Color.lime);
            
drawTextRelative(-10"Long"Color.blackColor.limeText.VCENTER  Text.BOLD |  Text.PRESETnullnull"buyTxt" getValue("time"));
            
BarsSinceEntry 0;
        }
        if(
Condition5 && Strategy.isLong()){
            
Strategy.doSell("FVE EXIT"Strategy.CLOSEStrategy.THISBAR);
            
setPriceBarColor(Color.red);
            
drawTextRelative(-10"Exit Long"Color.blackColor.redText.VCENTER Text.BOLD |  Text.PRESETnullnull"buyTxt" getValue("time"));
        }
        if(
BarsSinceEntry == BarToExitOn && Strategy.isLong()){
            
Strategy.doSell("TimeBarsLX"Strategy.CLOSEStrategy.THISBAR);
            
setPriceBarColor(Color.red);
            
drawTextRelative(-10"Exit Long"Color.blackColor.redText.VCENTER Text.BOLD |  Text.PRESETnullnull"buyTxt" getValue("time"));
        }
        return 
LinearReg(close(0,-LRC),LRC,"Slope",LRC-1);
    }
    else
        return;
}
        
                
function 
StandardDev(Array, LengthType){
    var 
i;
    var 
vSum 0;
    var 
SumSqr 0;
    var 
StdDev 0;
    
    for(
0Lengthi++)
            
vSum += Array[i];

    if(
Length != 0)
        for(
0Lengthi++)
            
SumSqr += (Array[i] - vSum Length) * (Array[i] - vSum Length);

    
StdDev Math.sqrt(SumSqr Length);
    return 
StdDev;
}

function 
LinearReg(Array, LengthTypeTargetB){
    var 
0num1 0num2 0SumBars 0SumSqrBars 0SumY 0Sum1 0Sum2 0Slope 0Intercept 0;

    if(
Length == 0)
        return 
0;
    
    
SumBars Length * (Length 1) * .5;
    
SumSqrBars = (Length 1) * Length * (Length 1) / 6;
    
    
Sum1 0;
    for(
0Lengthi++){
        
Sum1 += * Array[i];
        
SumY += Array[i];
    }
    
Sum2 SumBars SumY;
    
Num1 Length Sum1 Sum2;
    
Num2 SumBars SumBars Length SumSqrBars;

    if(
Num2 != 0)
        
Slope Num1 Num2;
    else 
        
Slope 0;
    if(
Type == "AngleFC")
        return 
Math.atan(Slope); 
    else if(
Type == "Slope")
        return 
Slope
    else if(
Type == "Value"){
        
Intercept = (SumY Slope SumBars) / Length;
        return 
Intercept Slope * (Length TargetB);
    }