File Name: symOverlay2.efs

Description:
Overlays a symbol as a price study and auto scales the overlay symbol's prices to match the price levels of your chart's symbol.

Formula Parameters:
nSymbol: Enter a symbol for comparison. Default is set to $SPX.

nFactor: Multiplier that adjusts nSymbol to match the price level of the chart’s symbol

Notes:
The overlay symbol and nFactor for scaling can be changed via the “Edit Studies” option. The initial nFactor is based on the first (oldest) bar in your chart. It is recommended to apply a custom time template to your chart that limits the number of days or bars loaded into your chart. The current value of the nFactor is displayed in the cursor label window.

Download File:
symOverlay2.efs




EFS Code:
PHP Code:
/*******************************
Provided By : eSignal. (c) Copyright 2003
*******************************/
var vLoaded false;

function 
preMain() {
    if (
vLoaded == false) {
        
setPriceStudy(true);
        
setDefaultBarThickness(2);
        
setDefaultBarFgColor(Color.green);
    } else {
        
setCursorLabelName(vSymbol);
        
setStudyTitle("Overlay: ");
    }
}

var 
vSymbol "";
var 
vSym "";
var 
vInterval 0;
var 
str = new String();
    
function 
main(nSymbolnFactor){
    if (
vLoaded == false) {
        if (
nSymbol == null)
            
nSymbol "$SPX";
        
vInterval getInterval();    
        if (
nFactor == null) {
            var 
close();
            if (
== null) {
                return;
            }
            var 
c1 close(01nSymbol);
            if (
c1 == null) {
                return;
            }
            
nFactor = (c/c1);
            
nFactor *= 10000
            nFactor 
Math.round(nFactor);
            
nFactor /= 10000
            str 
nFactor;
        } else {
            var 
vFactor nFactor+'';
            var 
strLength vFactor.length
            
var de false;
            for (
0strLength; ++i) {
                
str += vFactor.charAt(i)
                if (
vFactor.charAt(i) == ".") {
                    
de true;
                }
            }
            if (
de == false) {
                
str += ".0"
            
}
        }
        
vSym = (str nSymbol "," vInterval);
        
vLoaded true;
        
vSymbol = (str " x " nSymbol);
        
preMain();
    }
    
    var 
close(01vSym);
    if (
== null) {
        return;
    }

    return 
v;