Announcement

Collapse
No announcement yet.

MACD Normalized

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

  • MACD Normalized

    Alex

    I have a favor to ask; listed below is Metastock code for a normalized MACD with Dema smoothing applied. Could you please convert this to an EFS2 script if you have the time.

    I am hoping that once I have the two scripts to compare side by side that it will help me to be able to convert other scripts on my own.

    Thanks
    Doug




    ========================================

    pds1:=Input("short EMA periods",1,500,12);
    pds2:=Input("long EMA periods",2,500,26);
    pds3:=
    Input("MACD trigger signal periods",1,500,9);
    x:=Input("use Open=1 High=2 Low=3 Close=4 Volume=5 P=6",1,6,4);
    plot:=Input("MACD=1, Histogram=2, trigger crossover Signals=3",1,3,1);

    x:=If(x=1,O,If(x=2,H,If(x=3,L,If(x=5,V,If(x=6,P,C) ))));
    sht:=Mov(x,pds1,W);
    lng:=Mov(x,pds2,W);
    ratio:=Min(sht,lng)/Max(sht,lng);
    Mac:=Dema(If(sht>lng,2-ratio,ratio)-1,2)*100;
    trigger:=Mov(Mac,pds3,W);
    hist:=Mac-trigger;
    signals:=
    Cross(Mac,trigger)+Cross(trigger,Mac)*-1;

    0;
    If(plot=1,trigger,0);
    If(plot=3,signals,If(plot=2,hist,Mac))

  • #2
    Doug
    I am not particularly familiar with Metastock code but I believe the enclosed script should replicate it. The efs makes use of the DEMA study that is in the amStudies Function Library so you will need to download it from here. For the required syntax see the corresponding HTML file available at the same link.
    You will need to add Function Parameters if you want the option to select the source and you may want to initialize the studies to optimize the performance of the script.
    If you have questions regarding EFS2 please post them in the appropriate forum as it is not an officially released product at this time.
    Alex

    PHP Code:
    function preMain(){
        
    setStudyTitle("Norm MACD");
        
    setCursorLabelName("MACD",0);
        
    setCursorLabelName("Signal",1);
        
    setCursorLabelName("Hist",2);
        
    setDefaultBarFgColor(Color.blue,0); 
        
    setDefaultBarFgColor(Color.red,1);
        
    setDefaultBarFgColor(Color.magenta,2); 
        
    setPlotType(PLOTTYPE_LINE,0);
        
    setPlotType(PLOTTYPE_LINE,1);
        
    setPlotType(PLOTTYPE_HISTOGRAM,2); 
    }

    var 
    amLib addLibrary("amStudies.efsLib");

    function 
    main(){

        if(
    getCurrentBarCount()<35) return;

        var 
    Mac    amLib.amDEMA(2,efsInternal("ratio"));
        var 
    Signal wma(9,Mac);

        return new Array (
    Mac,Signal,(Mac-Signal));
    }

    function 
    ratio(){

        var 
    0;
        var 
    sht wma(12);
        var 
    lng wma(26);
        
        var 
    ratio = (Math.min(sht,lng)/Math.max(sht,lng));
        
        var 
    ret sht>lng? ((2-ratio)-1)*100: ((ratio)-1)*100;

        return 
    ret;

    Comment

    Working...
    X