Announcement

Collapse
No announcement yet.

can anyone code this strategy?

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

  • can anyone code this strategy?

    Hi there
    I'd like to make my own trading system efs. But i'm new to efs codes.
    Here is my index trading system in my mind.

    Short Signal
    var A=Highest bar in last 20(function parameter) bars.
    var B=Second highest bar in last 20(function parameter) bars.
    var C= KVO indicator number(not trigger number), at var A
    var D= KVO indicator number(not trigger number), at var B
    var E= index Z(ex IWM,QQQ) price at var A
    var F= index Z(ex IWM,QQQ) price at var B
    var G= $PCTABOVEVWAP.NQ-ST at var A
    var H= $PCTABOVEVWAP.NQ-ST at var B

    short signal condition
    var C< var D
    var E< var F
    var G< or = var H

    if those three conditions are met, a down arrow appears on that bar

    Long Signal
    var AA= Lowest bar in last 20(function parameter) bars.
    var BB= Second lowest bar 20(function parameter) bars
    var CC= KVO indicator number(not trigger number) at var AA
    var DD= KVO indicator number(not trigger number) at var BB
    var EE= index Z(ex IWM,QQQ) price at var AA
    var FF= index Z(ex IWM,QQQ)price at var BB
    var GG= $PCTABOVEVWAP.NQ-ST at var AA
    var HH= $PCTABOVEVWAP.NQ-ST at var BB

    conditions
    var CC > var DD
    var EE > var FF
    var GG> or = var HH

    if those three conditions are met, an up arrow appears on that bar

    please let me know, the cost structure

    thanks,
    park

  • #2
    try:
    PHP Code:
    /*********************************
    Provided By:  
        eSignal (Copyright c eSignal), a division of Interactive Data 
        Corporation. 2009. 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:        
        Klinger Volume Oscillator (KVO) 
        
    Version:            1.0  05/27/2009
     
    Formula Parameters:                     Default:
        TrigLen                             13
        FastX                               34
        SlowX                               55
        
    Notes:
        The Klinger Oscillator (KO) was developed by Stephen J. Klinger. Learning 
        from prior research on volume by such well-known technicians as Joseph Granville, 
        Larry Williams, and Marc Chaikin, Mr. Klinger set out to develop a volume-based 
        indicator to help in both short- and long-term analysis.
        The KO was developed with two seemingly opposite goals in mind: to be sensitive 
        enough to signal short-term tops and bottoms, yet accurate enough to reflect the 
        long-term flow of money into and out of a security.
        The KO is based on the following tenets:
        Price range (i.e. High - Low) is a measure of movement and volume is the force behind 
        the movement. The sum of High + Low + Close defines a trend. Accumulation occurs when 
        today's sum is greater than the previous day's. Conversely, distribution occurs when 
        today's sum is less than the previous day's. When the sums are equal, the existing trend 
        is maintained.
        Volume produces continuous intra-day changes in price reflecting buying and selling pressure. 
        The KO quantifies the difference between the number of shares being accumulated and distributed 
        each day as "volume force". A strong, rising volume force should accompany an uptrend and then 
        gradually contract over time during the latter stages of the uptrend and the early stages of 
        the following downtrend. This should be followed by a rising volume force reflecting some 
        accumulation before a bottom develops.

    **********************************/
    var fpArray = new Array();//http://forum.esignal.com/showthread.php?38999-can-anyone-code-this-strategy
    //debugClear();
    function preMain(){
        var 
    aFPArray = new Array();
        
    setPriceStudy(false);
        
    //setStudyTitle("Klinger Volume Oscillator");
        
    setCursorLabelName("KVO",0);
        
    setCursorLabelName("Trigger",1);    
        
    setDefaultBarFgColor(Color.red,0);
        
    setDefaultBarFgColor(Color.brown,1);
        
    addBand(0PS_SOLID1Color.black);
        
    //setIntervalsBackfill(true);
        //setShowTitleParameters( false ); 
        
    var 0;
        
    aFPArray[x] = new FunctionParameter("MktIndex"FunctionParameter.STRING);
        
    with(aFPArray[x++]) {
            
    setName("Market Index");
            
    addOption("IWM");
            
    addOption("QQQ");
            
    setDefault("QQQ");
        }
        
    aFPArray[x] = new FunctionParameter("HL_CalcBar"FunctionParameter.NUMBER);
        
    with(aFPArray[x++]) {
            
    setName("Calculate on Bar #");
            
    setUpperLimit(0);
            
    setLowerLimit(-1);
            
    addOption(0);
            
    addOption(-1);
            
    setDefault(0);
        }
        
    aFPArray[x] = new FunctionParameter("HL_CalcLength"FunctionParameter.NUMBER);
        
    with(aFPArray[x++]) {
            
    setName("Length");
            
    //setUpperLimit(0);
            
    setLowerLimit(2);
            
    setDefault(20);
        }
        
    aFPArray[x] = new FunctionParameter("TrigLen"FunctionParameter.NUMBER);
        
    with(aFPArray[x++]) {
            
    setLowerLimit(1);
            
    setDefault(13);
        }    
        
    aFPArray[x] = new FunctionParameter("FastX"FunctionParameter.NUMBER);
        
    with(aFPArray[x++]) {
            
    setLowerLimit(1);
            
    setDefault(34);
        }    
        
    aFPArray[x] = new FunctionParameter("SlowX"FunctionParameter.NUMBER);
        
    with(aFPArray[x++]) {
            
    setLowerLimit(1);
            
    setDefault(55);
        }    
    }
    var 
    bInit=false;
    var 
    xHighs=[];
    var 
    xLows=[];
    var 
    xKVO null;
    var 
    xTrigger null;
    var 
    zIndex;
    var 
    pctAbVWAP;
    function 
    main(MktIndex,HL_CalcBar,HL_CalcLength,FastXSlowXTrigLen){
        var 
    h0=0,h1=0,l0=99999,l1=999999;
        var 
    nBarState getBarState();
        var 
    nKVO=0;
        var 
    nTrigger 0;
        
    //SHORTS
        
    var nKVO_h 0;
        var 
    nKVO_h1=0;
        var 
    zIndex_h=0;
        var 
    zIndex_h_1=0;
        var 
    pctAbVWAP_h=0;
        var 
    pctAbVWAP_h_1=0;
        var 
    shortSig=false
        
    //LONGS
        
    var nKVO_l 0;
        var 
    nKVO_l1=0;
        var 
    zIndex_l=0;
        var 
    zIndex_l_1=0;
        var 
    pctAbVWAP_l=0;
        var 
    pctAbVWAP_l_1=0;
        var 
    longSig=false;
        
    //
        
    if (nBarState == BARSTATE_ALLBARS) {
            if(
    FastX == nullFastX 34;
            if(
    SlowX == nullSlowX 55;
            if(
    TrigLen == nullTrigLen 13;
        }    
        if(!
    bInit){
            
    xHighs[0]=new Array(HL_CalcLength);
            
    xLows[0]=new Array(HL_CalcLength);
            
    xKVO efsInternal("Calc_KVO"FastXSlowX);
            
    xTrigger ema(TrigLenxKVO);
            
    zIndex=close(sym(MktIndex));
            
    pctAbVWAP=close(sym("$PCTABOVEVWAP.NQ-ST"));
            
    bInit=true;
        }
        if(
    getBarState()==BARSTATE_NEWBAR){
            var 
    xx=ff(HL_CalcLength);
            
    //debugPrintln("15: "+xx);
            
    if(getCurrentBarCount()>=HL_CalcLength){//debugPrintln("22_H: "+xx[0]+"\n22_L"+xx[1]);
                
    var HLv=getHLs(xx[0],xx[1]);//debugPrintln("23: "+xx[1]);
            
    }
        }
        
    nKVO xKVO.getValue(0);
        
    nTrigger xTrigger.getValue(0);
        if(
    HLv){
            if(
    HL_CalcBar==0){
                
    h0=high(0);
                if(
    HLv[0]>h0){
                    
    h0=HLv[0]; 
                    
    h1=HLv[4];
                }else if(
    h0>HLv[0]){
                    
    h1=HLv[0];
                }else if(
    h0==HLv[0]) h1=HLv[1];
                
    l0=low(0);
                if(
    l0>HLv[4]){
                    
    l0=HLv[4];
                    
    l1=HLv[6];
                }else if(
    HLv[4]>l0){
                    
    l1=HLv[6];
                }else if(
    l0==HLv[4]) l1=HLv[6];
            }else if(
    HL_CalcBar==-1){
                
    h0=HLv[0];
                
    h1=HLv[4];
                
    l0=HLv[4];
                
    l1=HLv[6];
                
            }
              
    /*HLv[0]=highestNo = h0
                HLv[1]=hi0Idx
                HLv[2]=xHi_1 = h1
                HLv[3]=hi1Idx
                HLv[4]=lowestNo = l0
                HLv[5]=lo0Idx
                HLv[6]=xLo_1 = l1
                HLv[7]=lo1Idx
              */
            //[highestNo,hi0Idx,xHi_1,hi1Idx,lowestNo,lo0Idx,xLo_1,lo1Idx];

            //debugPrintln("39: "+h0+"\t"+h1+"\t"+l0+"\t"+l1);
            //debugPrintln("40: "+HLv[0]+"\t"+HLv[2]+"\t"+HLv[4]+"\t"+HLv[6])
            
    if(nKVO){//debugPrintln("123: "+HLv[1]);
                //SHORTS
                
    nKVO_h=xKVO.getValue(HLv[1] - getCurrentBarCount());//C
                
    nKVO_h_1=xKVO.getValue(HLv[3] - getCurrentBarCount());//D
                
    zIndex_h=zIndex.getValue(HLv[1] - getCurrentBarCount());//E
                
    zIndex_h_1=zIndex.getValue(HLv[3] - getCurrentBarCount());//F
                
    pctAbVWAP_h=pctAbVWAP.getValue(HLv[1] - getCurrentBarCount());//G
                
    pctAbVWAP_h_1=pctAbVWAP.getValue(HLv[3] - getCurrentBarCount());//H
                
    if(nKVO_h_1>nKVO_h && zIndex_h_1>zIndex_h && pctAbVWAP_h_1>=pctAbVWAP_h){
                    
    shortSig=true;
                    
    drawShapeRelative0BottomRow2Shape.DOWNARROWnull,Color.redShape.ONTOP Shape.PRESET,"d" gID() ); 
                    
    setBarBgColor(Color.RGB(255,215,191));
                }
                
    //LONGS
                
    nKVO_l xKVO.getValue(HLv[5] - getCurrentBarCount());//CC
                
    nKVO_l1=xKVO.getValue(HLv[7] - getCurrentBarCount());//DD
                
    zIndex_l=zIndex.getValue(HLv[5] - getCurrentBarCount());//EE
                
    zIndex_l_1=zIndex.getValue(HLv[7] - getCurrentBarCount());//FF
                
    pctAbVWAP_l=pctAbVWAP.getValue(HLv[5] - getCurrentBarCount());//GG
                
    pctAbVWAP_l_1=pctAbVWAP.getValue(HLv[7] - getCurrentBarCount());//HH
                
    if(nKVO_l>nKVO_l1 && zIndex_l>zIndex_l_1 && pctAbVWAP_l>pctAbVWAP_l_1){
                    
    longSig=true;
                    
    drawShapeRelative0TopRow2Shape.UPARROWnull,Color.greenShape.ONTOP Shape.PRESET,"u" gID() ); 
                    
    setBarBgColor(Color.RGB(200,255,150));
                
                }
                if(
    shortSig && longSigsetBarBgColor(Color.RGB(255,255,200));
            }
        }

        if (
    nTrigger == null) return;
     
        return [
    nKVOnTrigger];
    }
    var 
    ffInit=false;
    function 
    ff(HL_CalcLength){//debugPrintln("30: "+);
        
    if(!ffInit){
            
    ffInit=true;
        }
        
    xHighs.push([high(-1)]);//(-1)
        
    xHighs[xHighs.length-1][1]=getCurrentBarCount();
        if(
    xHighs.length>HL_CalcLengthxHighs.shift();
        
    xLows.push([low(-1)]);//(-1)
        
    xLows[xLows.length-1][1]=getCurrentBarCount();
        if(
    xLows.length>HL_CalcLengthxLows.shift();
        return [
    xHighs,xLows];//.sort(function(a, b){return a[0] > b[0];});
    }
    function 
    getHLs(xArrH,xArrL){
        var 
    highestNo;
        var 
    hi0Idx;
        var 
    lowestNo;
        var 
    lo0Idx;
        var 
    xHi_1;
        var 
    hi1Idx;
        var 
    xLo_1;
        var 
    lo1Idx;
        
    highestNo=0;
        
    xHi_1=0;
        
    lowestNo=9999999999;
        
    xLo_1=999999999;
        
    /*highestNo=xArrH[0][0];
        xHi_1=xArrH[0][0];
        lowestNo=xArrH[0][0];
        xLo_1=xArrH[0][0];*/
        
    var aLen=xArrH.length
        
    for(var i=aLen-1;i>=0;i--){
            if(
    xArrH[i][0]>highestNo){
                
    highestNo=xArrH[i][0];
                
    hi0Idx=xArrH[i][1];
            }
            if(
    lowestNo>xArrL[i][0]){
                
    lowestNo=xArrL[i][0];
                
    lo0Idx=xArrL[i][1];
            }
        }
        for(var 
    i=aLen-1;i>=0;i--){
            if(
    xArrH[i][0]!=highestNo && xArrH[i][0]>xHi_1){
                
    xHi_1=xArrH[i][0];
                
    hi1Idx=xArrH[i][1];
            }
            if(
    xArrL[i][0]!=lowestNo && xLo_1>xArrL[i][0]){
                
    xLo_1=xArrL[i][0]
                
    lo1Idx=xArrL[i][1];
            }
        }
        return [
    highestNo,hi0Idx,xHi_1,hi1Idx,lowestNo,lo0Idx,xLo_1,lo1Idx];
    }
    var 
    bSecondInit false;
    var 
    xFast null;
    var 
    xSlow null;
    var 
    xTrend null;

    function 
    Calc_KVO(FastXSlowX) {
    var 
    nRes 0;
    var 
    FXAvg 0;
    var 
    SXAvg 0;
        if (
    bSecondInit == false) {
            
    xTrend efsInternal("Calc_Trend");
            
    xFast ema(FastXxTrend);
            
    xSlow ema(SlowXxTrend);
            
    bSecondInit true;
        }
        
    FXAvg xFast.getValue(0);
        
    SXAvg xSlow.getValue(0);
        if (
    SXAvg == null) return;
        
    nRes FXAvg SXAvg;
        return 
    nRes;
    }

    var 
    xhlc3 null;

    function 
    Calc_Trend() {
    var 
    nRes 0;
        if (
    xhlc3 == nullxhlc3 hlc3();
        if (
    xhlc3.getValue(-1) == null) return;
        if(
    xhlc3.getValue(0) > xhlc3.getValue(-1))
            
    nRes 1;
        else
            
    nRes = -1;
        
    nRes volume(0) * nRes 100;
        return 
    nRes;
    }
    var 
    grID 0;  
    function 
    gID() {
        
    grID ++;
        return( 
    grID );
    }
    /*
    http://forum.esignal.com/showthread.php?38999-can-anyone-code-this-strategy
    Here is my index trading system in my mind.

     Short Signal
     var A=Highest bar in last 20(function parameter) bars.
     var B=Second highest bar in last 20(function parameter) bars.
     var C= KVO indicator number(not trigger number), at var A
     var D= KVO indicator number(not trigger number), at var B
     var E= index Z(ex IWM,QQQ) price at var A
     var F= index Z(ex IWM,QQQ) price at var B
     var G= $PCTABOVEVWAP.NQ-ST at var A
     var H= $PCTABOVEVWAP.NQ-ST at var B

     short signal condition
     var C< var D
     var E< var F
     var G< or = var H

     if those three conditions are met, a down arrow appears on that bar

     Long Signal
     var AA= Lowest bar in last 20(function parameter) bars.
     var BB= Second lowest bar 20(function parameter) bars
     var CC= KVO indicator number(not trigger number) at var AA
     var DD= KVO indicator number(not trigger number) at var BB
     var EE= index Z(ex IWM,QQQ) price at var AA
     var FF= index Z(ex IWM,QQQ)price at var BB
     var GG= $PCTABOVEVWAP.NQ-ST at var AA
     var HH= $PCTABOVEVWAP.NQ-ST at var BB

     conditions
     var CC > var DD
     var EE > var FF
     var GG> or = var HH

     if those three conditions are met, an up arrow appears on that bar
    */ 
    Wayne
    Last edited by waynecd; 09-24-2013, 11:31 AM.

    Comment


    • #3
      Thank you very much It was too difficult for me to even start!!!
      Is there a way to see past signals?
      I really appreciate it again

      Comment


      • #4
        Yw.

        It plots all back signals as it is, just load more bars onto the chart.
        Script calculations require a minimum # of bars before the lines start plotting.

        The following line under main() serves no purpose and can be removed or commented out.
        PHP Code:
            if (nTrigger == null) return; 
        Wayne

        Comment


        • #5
          Thanks for the help again how did you study efs? I'm pretty new to efs and have been reading tutorials but it seems confusing any recommendation?

          Comment


          • #6
            for some reason I don't get past signal I can only see today's signals.Click image for larger version

Name:	1.png
Views:	1
Size:	98.9 KB
ID:	242901

            Comment


            • #7
              The chart helped.

              In the preMain() function uncomment the following;
              PHP Code:
                  setIntervalsBackfill(true); 
              I'm pretty new to efs and have been reading tutorials but it seems confusing any recommendation?
              As you stated, study the manuals and tutorials. You will also benefit from a search (way back in time) of Forum posts from Alexis C. Montenegro, SteveHare2003, and others.
              They provided great working examples in their File Share. Here are a couple of helpful File Share sites:



              Also, searching the forum and Google for specific programming issues. There is little that is not covered somewhere in the forums.
              Google searches for specific javascript programming concepts using terms like: "javascript getDate", etc.

              Wayne
              Last edited by waynecd; 10-02-2013, 02:18 PM.

              Comment


              • #8
                ha thank you again you seem like a efs wikipedia i'm working on changing this a little bit and try to make an automated trading system.
                have you seen any good automated trading efs(SPY)? I have looked for somewhat reliable one but i couldn't find one

                Comment


                • #9
                  Unfortunately automated system is one of the few things I haven't come across much on.
                  An automated system presumably would autotrade and eSignal just doesn't do that yet.

                  They seem to be working on making it an added subscription service, $$$.

                  Wayne

                  Comment


                  • #10
                    ha I see.
                    Right now i'm trying to find the right mix to use this efs.
                    I have found out that KVO.efs doesn't really work well at the moment.
                    So, I'm trying to use 3 other indexs to find divergence with spy.
                    1)IWM+QQQ
                    2)$ADD
                    3)XLK+XLF
                    When those 3 make any divergence from spy at the same time I go long/short spy.

                    Comment


                    • #11
                      klevera, did that help you?

                      Comment

                      Working...
                      X