Announcement

Collapse
No announcement yet.

Ichimoku Strategy modified... questions

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

  • Ichimoku Strategy modified... questions

    OK I used ichimoku(alerts).efs and modified it to become a SAR strategy with stops and limits, display arrows, text, and send me emails. That all works, my question is related to the picture below. The TS line and the KS line cross more than once in the snapshot below, but "long" and "short" and the arrows are only displayed once. What did I do wrong here?



    Here's the script. Any help would be appreciated.

    PHP Code:
    /********************************
    Original file ichimoku(alerts).efs by
    Alexis C. Montenegro © June 2003 
    Ichimoku Euro.efs is an adaptation of 
    the original file by McLean Van Cleve
    *********************************/

    var vDonchian = new DonchianStudy(70);
    var 
    vDonchian_2 = new DonchianStudy(220);
    var 
    vDonchian_3 = new DonchianStudy(722);
    var 
    vDonchian_4 = new DonchianStudy(2222);
    var 
    vDonchian_5 = new DonchianStudy(4422);
    var 
    vCntr 0;

    function 
    preMain() {

        
    setPriceStudy(true);
        
    setStudyTitle("Ichimoku");
        
    setCursorLabelName("Tenkan"0);
        
    setCursorLabelName("Kijun"1);
        
    setCursorLabelName("Chikou"2);
        
    setCursorLabelName("SenkouA"3);
        
    setCursorLabelName("SenkouB"4);
        
    setDefaultBarStyle(PS_SOLID0);
        
    setDefaultBarStyle(PS_SOLID1);
        
    setDefaultBarStyle(PS_SOLID2);
        
    setDefaultBarStyle(PS_SOLID3);
        
    setDefaultBarStyle(PS_SOLID4);
        
    setDefaultBarFgColor(Color.red0);
        
    setDefaultBarFgColor(Color.blue1);
        
    setDefaultBarFgColor(Color.magenta2);
        
    setDefaultBarFgColor(Color.black3);
        
    setDefaultBarFgColor(Color.black4);
        
    setDefaultBarThickness(20);
        
    setDefaultBarThickness(21);
        
    setDefaultBarThickness(22);
        
    setDefaultBarThickness(23);
        
    setDefaultBarThickness(24);
        
    setPlotType(PLOTTYPE_LINE0);
        
    setPlotType(PLOTTYPE_LINE1);
        
    setPlotType(PLOTTYPE_LINE2);
        
    setPlotType(PLOTTYPE_LINE3);
        
    setPlotType(PLOTTYPE_LINE4);
        var 
    fp1 = new FunctionParameter("MinTick"FunctionParameter.NUMBER);
        
    fp1.setDefault(0.0001); //Edit this value to set a new default
        
    var fp2 = new FunctionParameter("Profit"FunctionParameter.NUMBER);
        
    fp2.setName("Ticks Profit");
        
    fp2.setDefault(40); //Edit this value to set a new default
        
    var fp3 = new FunctionParameter("Stop"FunctionParameter.NUMBER);
        
    fp3.setName("Ticks Stop");
        
    fp3.setDefault(40); //Edit this value to set a new default

    }

    var 
    vEntryPrice 0;
    var 
    vTargetPrice 0;
    var 
    vStopPrice 0;
    var 
    BarCntr 0;

    function 
    main(MinTick,Profit,Stop) {

        var 
    space 1;
        if (
    getInterval() != "D")
            
    space high(-1)-low(-1);

        if(
    getBarState()==BARSTATE_NEWBAR){
        
    vCntr +=1;
        }
        if(
    vCntr<53)
        return;
     
        var 
    SenkouA = (vDonchian_3.getValue(DonchianStudy.BASIS)+vDonchian_4.getValue(DonchianStudy.BASIS))/2;
        
        if(
    SenkouA>vDonchian_5.getValue(DonchianStudy.BASIS))
            
    setBarBgColor(Color.white,0,vDonchian_5.getValue(DonchianStudy.BASIS),SenkouA);
        if(
    SenkouA<vDonchian_5.getValue(DonchianStudy.BASIS))
            
    setBarBgColor(Color.white,0,SenkouA,vDonchian_5.getValue(DonchianStudy.BASIS));
            
        if(
    getBarState()==BARSTATE_NEWBAR){ 
            if(
    vDonchian.getValue(DonchianStudy.BASIS,-2)<=vDonchian_2.getValue(DonchianStudy.BASIS,-2)&&
               
    vDonchian.getValue(DonchianStudy.BASIS,-1)>vDonchian_2.getValue(DonchianStudy.BASIS,-1)){
                   
    drawTextRelative(0,low(),"é",Color.blue,null,Text.TOP|Text.CENTER|Text.BOLD,"Wingdings",12,"Up"BarCntr);
                   
    drawTextRelative(-1low(-1)-(space*0.55),"Long",Color.white,Color.blue,Text.FRAME|Text.ONTOP|Text.BOLDnull,12,"text buy"+BarCntr );
                   
    Strategy.doLong("Long",Strategy.MARKET,Strategy.THISBAR);
                   
    vEntryPrice open(0);
                   
    vTargetPrice vEntryPrice+(Profit*MinTick);
                   
    vStopPrice vEntryPrice-(Stop*MinTick); 
                   
    Alert.playSound("long_eur.wav"); 
                   
    Alert.email("Buy EUR/USD""Buy EUR/USD" );
            }
            if(
    vDonchian.getValue(DonchianStudy.BASIS,-2)>=vDonchian_2.getValue(DonchianStudy.BASIS,-2)&&
               
    vDonchian.getValue(DonchianStudy.BASIS,-1)<vDonchian_2.getValue(DonchianStudy.BASIS,-1)){
                   
    drawTextRelative(0,high(),"ê",Color.red,null,Text.BOTTOM|Text.CENTER|Text.BOLD,"Wingdings",12,"Dn"BarCntr);
                   
    drawTextRelative(-1,high(-1)+(space*0.55),"Short",Color.white,Color.red,Text.FRAME|Text.BOTTOM|Text.BOLD,null,12,"text sell"+BarCntr );
                   
    Strategy.doShort("Short",Strategy.MARKET,Strategy.THISBAR);
                   
    vEntryPrice open(0);
                   
    vTargetPrice vEntryPrice-(Profit*MinTick);
                   
    vStopPrice vEntryPrice+(Stop*MinTick);
                   
    Alert.playSound("short_eur.wav");
                   
    Alert.email("Sell EUR/USD""Sell EUR/USD" );
            }
        }
        
        if(
    Strategy.isLong()==true){
            if(
    high(0)>=vTargetPrice){
                
    Strategy.doSell("Profit Sell",Strategy.STOP,Strategy.THISBAR,null,vTargetPrice);
            }
            if(
    low(0)<=vStopPrice){
                
    Strategy.doSell("Stop Sell",Strategy.STOP,Strategy.THISBAR,null,vStopPrice);
            }
        }
        if(
    Strategy.isShort()==true){
            if(
    low(0)<=vTargetPrice){
                
    Strategy.doCover("Profit Cover",Strategy.STOP,Strategy.THISBAR,null,vTargetPrice);
            }
            if(
    high(0)>=vStopPrice){
                
    Strategy.doCover("Stop Cover",Strategy.STOP,Strategy.THISBAR,null,vStopPrice);
            }        
        }

        if(
    getBarState() == BARSTATE_NEWBAR){
            var 
    nNum 1;
        }else{
            var 
    nNum 0;
        }
        
        if(
    getBuildNumber()>636){
            
    setBar(Bar.Value,-26+nNum,2,close(0));
        }else{
            
    setBar(Bar.Value,-26+nNum,new Array(null,null,close(0),null,null));
        }

        return new Array(
    vDonchian.getValue(DonchianStudy.BASIS),vDonchian_2.getValue(DonchianStudy.BASIS),
                         
    null,SenkouA,vDonchian_5.getValue(DonchianStudy.BASIS));

    Oh, the yelllow line is a WMA so disregard that. I plan on further modifying the strategy to only enter long trades if it is above the cloud and the WMA is moving up. The opposite goes for short trades. I just need to get past this problem so I can make sure my backtesting results are accurate. Thanks!
    Last edited by techinvest; 12-04-2005, 01:14 AM.

  • #2
    techinvest
    That is happening because the BarCntr variable used in the tagName of each graphic object is always equal to 0 ie its initial value. Hence there can only be one of each graphic object drawn and specifically the last one.
    You need to increment BarCntr by 1 at every new bar. To do that insert BarCntr++ in the following statement you already have in your script
    if(getBarState()==BARSTATE_NEWBAR){
    vCntr +=1;
    }

    Once you add that line all the arrows and related text will be drawn
    Alex

    Comment


    • #3
      Thanks again! Now to add parameters for the Senkou spans and a 20 period WMA. Hopefully I can figure this part out on my own.

      Ever thought of writing an EFS instructional book Alexis? It might sharpen the learning curve for those of us who are (what's the politically correct word...) programming language challenged?

      Comment


      • #4
        OK, I've sucessfully added my MA strategy to it, but my final addition to enter a long trade is when the close of the previous bar is above the Senkou Span A (or 1) and for short trades, when the close of the previous bar is below Senkou Span B (or 2).

        I've tried the obvious (well obvious to me) and nothing:

        (in function main)
        if(getBarState()==BARSTATE_NEWBAR){
        if(vDonchian.getValue(DonchianStudy.BASIS,-2)<=vDonchian_2.getValue(DonchianStudy.BASIS,-2)&&
        vDonchian.getValue(DonchianStudy.BASIS,-1)>vDonchian_2.getValue(DonchianStudy.BASIS,-1)&&
        vDonchian_4<close(-1)){
        <--- long

        and further down:
        if(vDonchian.getValue(DonchianStudy.BASIS,-2)>=vDonchian_2.getValue(DonchianStudy.BASIS,-2)&&
        vDonchian.getValue(DonchianStudy.BASIS,-1)<vDonchian_2.getValue(DonchianStudy.BASIS,-1)&&
        vDonchian_5>close(-1)){
        <--- short

        The code below still applies as it has only had an addition. I might add that I get absolutley no errors, but even worse I get no trades . Thanks in advance.
        Last edited by techinvest; 12-05-2005, 01:58 AM.

        Comment


        • #5
          Also here's another question. I've attached the updated script without the Senkou Span parameters that I'm trying to add. Any idea why all of the parameters that are in it at this point display without error, but the backtester hangs up on it every time?

          PHP Code:
          /********************************
          Original file ichimoku(alerts).efs by
          Alexis C. Montenegro © June 2003 
          Ichimoku Euro.efs is an adaptation of 
          the original file by McLean Van Cleve
          *********************************/

          var vDonchian = new DonchianStudy(70);
          var 
          vDonchian_2 = new DonchianStudy(220);
          var 
          vDonchian_3 = new DonchianStudy(722);
          var 
          vDonchian_4 = new DonchianStudy(2222);
          var 
          vDonchian_5 = new DonchianStudy(4422);
          var 
          vCntr 0;
          var 
          vMA1 null;

          function 
          preMain() {

              
          setPriceStudy(true);
              
          setStudyTitle("Ichimoku");
              
          setCursorLabelName("Tenkan"0);
              
          setCursorLabelName("Kijun"1);
              
          setCursorLabelName("Chikou"2);
              
          setCursorLabelName("SenkouA"3);
              
          setCursorLabelName("SenkouB"4);
              
          setCursorLabelName("MA1"5);
              
          setDefaultBarStyle(PS_SOLID0);
              
          setDefaultBarStyle(PS_SOLID1);
              
          setDefaultBarStyle(PS_SOLID2);
              
          setDefaultBarStyle(PS_SOLID3);
              
          setDefaultBarStyle(PS_SOLID4);
              
          setDefaultBarStyle(PS_SOLID5);
              
          setDefaultBarFgColor(Color.red0);
              
          setDefaultBarFgColor(Color.blue1);
              
          setDefaultBarFgColor(Color.magenta2);
              
          setDefaultBarFgColor(Color.black3);
              
          setDefaultBarFgColor(Color.green4);
              
          setDefaultBarFgColor(Color.yellow5);
              
          setDefaultBarThickness(20);
              
          setDefaultBarThickness(21);
              
          setDefaultBarThickness(22);
              
          setDefaultBarThickness(23);
              
          setDefaultBarThickness(24);
              
          setDefaultBarThickness(25);
              
          setPlotType(PLOTTYPE_LINE0);
              
          setPlotType(PLOTTYPE_LINE1);
              
          setPlotType(PLOTTYPE_LINE2);
              
          setPlotType(PLOTTYPE_LINE3);
              
          setPlotType(PLOTTYPE_LINE4);
              
          setPlotType(PLOTTYPE_LINE5);
              
              var 
          fp1 = new FunctionParameter("MinTick"FunctionParameter.NUMBER);
              
          fp1.setDefault(0.0001); //Edit this value to set a new default
              
          var fp2 = new FunctionParameter("Profit"FunctionParameter.NUMBER);
              
          fp2.setName("Ticks Profit");
              
          fp2.setDefault(100); //Edit this value to set a new default
              
          var fp3 = new FunctionParameter("Stop"FunctionParameter.NUMBER);
              
          fp3.setName("Ticks Stop");
              
          fp3.setDefault(40); //Edit this value to set a new default
              
              
          var fp4 = new FunctionParameter("MA1Length"FunctionParameter.NUMBER);
              
          fp4.setLowerLimit(1);        
              
          fp4.setDefault(20); //Edit this value to set a new default
              
          var fp5 = new FunctionParameter("MA1Offset"FunctionParameter.NUMBER);
              
          fp5.setDefault(0); //Edit this value to set a new default
              
          var fp6 = new FunctionParameter("MA1Source"FunctionParameter.STRING);
              
          fp6.setName("MA1Source");
              
          fp6.addOption("Close");
              
          fp6.addOption("High");
              
          fp6.addOption("Low");
              
          fp6.addOption("Open");
              
          fp6.addOption("HL/2");
              
          fp6.addOption("HLC/3");
              
          fp6.addOption("OHLC/4");
              
          fp6.setDefault("HLC/3"); //Edit this value to set a new default     
              
          var fp7 = new FunctionParameter("MA1Type"FunctionParameter.STRING);
              
          fp7.setName("MA1Type");
              
          fp7.addOption("MAStudy.SIMPLE");
              
          fp7.addOption("MAStudy.EXPONENTIAL");
              
          fp7.addOption("MAStudy.WEIGHTED");
              
          fp7.addOption("MAStudy.VOLUMEWEIGHTED");
              
          fp7.setDefault("MAStudy.WEIGHTED"); //Edit this value to set a new default

          }

          var 
          vEntryPrice 0;
          var 
          vTargetPrice 0;
          var 
          vStopPrice 0;
          var 
          BarCntr 0;

          function 
          main(MinTick,Profit,Stop,MA1Length,MA1Offset,MA1Source,MA1Type) {

              if (
          vMA1 == nullvMA1 = new MAStudy(MA1LengthMA1OffsetMA1Source, eval(MA1Type));

              var 
          space 1;
              if (
          getInterval() != "D")
                  
          space high(-1)-low(-1);

              if(
          getBarState()==BARSTATE_NEWBAR){
              
          vCntr +=1;
              }
              if(
          vCntr<53)
              return;
              
                  
          BarCntr++
           
              var 
          SenkouA = (vDonchian_3.getValue(DonchianStudy.BASIS)+vDonchian_4.getValue(DonchianStudy.BASIS))/2;
              
              if(
          SenkouA>vDonchian_5.getValue(DonchianStudy.BASIS))
                  
          setBarBgColor(Color.white,0,vDonchian_5.getValue(DonchianStudy.BASIS),SenkouA);
              if(
          SenkouA<vDonchian_5.getValue(DonchianStudy.BASIS))
                  
          setBarBgColor(Color.white,0,SenkouA,vDonchian_5.getValue(DonchianStudy.BASIS));
                  
              if(
          getBarState()==BARSTATE_NEWBAR){ 
                  if(
          vDonchian.getValue(DonchianStudy.BASIS,-2)<=vDonchian_2.getValue(DonchianStudy.BASIS,-2)&&
                     
          vDonchian.getValue(DonchianStudy.BASIS,-1)>vDonchian_2.getValue(DonchianStudy.BASIS,-1)&&
                     
          vMA1.getValue(MAStudy.MA,-1)>vMA1.getValue(MAStudy.MA,-2)){
                         
          drawTextRelative(0,low(),"é",Color.blue,null,Text.TOP|Text.CENTER|Text.BOLD,"Wingdings",12,"Up"BarCntr);
                         
          drawTextRelative(-1low(-1)-(space*0.55),"Long",Color.white,Color.blue,Text.FRAME|Text.ONTOP|Text.BOLDnull,12,"text buy"+BarCntr );
                         
          Strategy.doLong("Long",Strategy.MARKET,Strategy.THISBAR);
                         
          vEntryPrice open(0);
                         
          vTargetPrice vEntryPrice+(Profit*MinTick);
                         
          vStopPrice vEntryPrice-(Stop*MinTick); 
                         
          Alert.playSound("long_eur.wav"); 
                         
          Alert.email("Buy EUR/USD""Buy EUR/USD" );
                  }
                  if(
          vDonchian.getValue(DonchianStudy.BASIS,-2)>=vDonchian_2.getValue(DonchianStudy.BASIS,-2)&&
                     
          vDonchian.getValue(DonchianStudy.BASIS,-1)<vDonchian_2.getValue(DonchianStudy.BASIS,-1)&&
                     
          vMA1.getValue(MAStudy.MA,-1)<vMA1.getValue(MAStudy.MA,-2)){
                         
          drawTextRelative(0,high(),"ê",Color.red,null,Text.BOTTOM|Text.CENTER|Text.BOLD,"Wingdings",12,"Dn"BarCntr);
                         
          drawTextRelative(-1,high(-1)+(space*0.55),"Short",Color.white,Color.red,Text.FRAME|Text.BOTTOM|Text.BOLD,null,12,"text sell"+BarCntr );
                         
          Strategy.doShort("Short",Strategy.MARKET,Strategy.THISBAR);
                         
          vEntryPrice open(0);
                         
          vTargetPrice vEntryPrice-(Profit*MinTick);
                         
          vStopPrice vEntryPrice+(Stop*MinTick);
                         
          Alert.playSound("short_eur.wav");
                         
          Alert.email("Sell EUR/USD""Sell EUR/USD" );
                  }
              }
              
              if(
          Strategy.isLong()==true){
                  if(
          high(0)>=vTargetPrice){
                      
          Strategy.doSell("Profit Sell",Strategy.STOP,Strategy.THISBAR,null,vTargetPrice);
                  }
                  if(
          low(0)<=vStopPrice){
                      
          Strategy.doSell("Stop Sell",Strategy.STOP,Strategy.THISBAR,null,vStopPrice);
                  }
              }
              if(
          Strategy.isShort()==true){
                  if(
          low(0)<=vTargetPrice){
                      
          Strategy.doCover("Profit Cover",Strategy.STOP,Strategy.THISBAR,null,vTargetPrice);
                  }
                  if(
          high(0)>=vStopPrice){
                      
          Strategy.doCover("Stop Cover",Strategy.STOP,Strategy.THISBAR,null,vStopPrice);
                  }        
              }

              if(
          getBarState() == BARSTATE_NEWBAR){
                  var 
          nNum 1;
              }else{
                  var 
          nNum 0;
              }
              
              if(
          getBuildNumber()>636){
                  
          setBar(Bar.Value,-26+nNum,2,close(0));
              }else{
                  
          setBar(Bar.Value,-26+nNum,new Array(null,null,close(0),null,null));
              }

              return new Array(
          vDonchian.getValue(DonchianStudy.BASIS),vDonchian_2.getValue(DonchianStudy.BASIS),
                               
          null,SenkouA,vDonchian_5.getValue(DonchianStudy.BASIS),vMA1.getValue(MAStudy.MA));

          Comment


          • #6
            techinvest
            FWIW I ran the efs on a 1 minute chart of EUR A0-FX and the back tester completed the task without any problems and is reporting trades
            What version of eSignal are you using?
            Alex

            Comment


            • #7
              After looking at a lot of charts I think that the parameter with the Senkou spans might be overkill. As far as what didn't work, I was referring to my post 3 down from this one. Nevvermind though, like I said, I think it may be unnecessary. Just in case though. What is the correct syntax for using the close command?

              For example, my criteria is that the close of the previous bar is greater than indicator "X". Would it be as follows?

              vIndicatorX < close(-1)

              Just in case I decide to add it (or something else) in later. thanks again for all of your help. I might finally be getting the hang of this.

              Comment


              • #8
                techinvest
                close(-1) is the correct syntax. However in the example you are referring to the error is in the syntax of the indicator which should have been vDonchian_4.getValue(DonchianStudy.BASIS,-1) or vDonchian_5.getValue(etc..)
                Alex

                Comment


                • #9
                  OK, I got that part. Now for my last question of the thread (no really, it is ). I was trying to do this:

                  Enter a long trade when the close of the previous bar crossed the KS and the 20WMA was moving up and vice versa for shorts. As you can see in the chart below, it enters a trade for every bar that this is true... not exactly what I had in mind.



                  Now I know that I need to bring into play something that will only enter the trade if I am not currently in a position or if the conditions change from long to short. I was thinking:

                  if(Strategy.isShort==true) or if(Strategy.isLong==false)

                  or maybe
                  if(Strategy.isIntrade==true)&&(StrategyisShort==tr ue)

                  added before the parameters for entering a long trade (line 114) and the opposite for shorts (line 125). The problem is that I don't know the exact syntax to use. If I enter it like this
                  if(Strategy.isShort==true){ I get no trades. If I enter it like this
                  if(Strategy.isShort==true)&& I get a syntax error on the next line. Ugh!

                  I think I'm just confused about the use of the { is it like a return? And how about &&? Doesn't that just bring itto the next line? Which way should it be and what line should I add it to. I've worked on this for 12 hours and I just don't get it. I can't seem to find a definitive answer.

                  Here's the faulty script that generates all of the trades.
                  PHP Code:
                  /********************************
                  Original file ichimoku(alerts).efs by
                  Alexis C. Montenegro © June 2003 
                  Ichimoku Euro.efs is an adaptation of 
                  the original file by McLean Van Cleve
                  *********************************/

                  var vDonchian = new DonchianStudy(70);
                  var 
                  vDonchian_2 = new DonchianStudy(220);
                  var 
                  vDonchian_3 = new DonchianStudy(722);
                  var 
                  vDonchian_4 = new DonchianStudy(2222);
                  var 
                  vDonchian_5 = new DonchianStudy(4422);
                  var 
                  vCntr 0;
                  var 
                  vMA1 null;

                  function 
                  preMain() {

                      
                  setPriceStudy(true);
                      
                  setStudyTitle("Ichimoku");
                      
                  setCursorLabelName("Tenkan"0);
                      
                  setCursorLabelName("Kijun"1);
                      
                  setCursorLabelName("Chikou"2);
                      
                  setCursorLabelName("SenkouA"3);
                      
                  setCursorLabelName("SenkouB"4);
                      
                  setCursorLabelName("MA1"5);
                      
                  setDefaultBarStyle(PS_SOLID0);
                      
                  setDefaultBarStyle(PS_SOLID1);
                      
                  setDefaultBarStyle(PS_SOLID2);
                      
                  setDefaultBarStyle(PS_SOLID3);
                      
                  setDefaultBarStyle(PS_SOLID4);
                      
                  setDefaultBarStyle(PS_SOLID5);
                      
                  setDefaultBarFgColor(Color.red0);
                      
                  setDefaultBarFgColor(Color.blue1);
                      
                  setDefaultBarFgColor(Color.magenta2);
                      
                  setDefaultBarFgColor(Color.black3);
                      
                  setDefaultBarFgColor(Color.green4);
                      
                  setDefaultBarFgColor(Color.yellow5);
                      
                  setDefaultBarThickness(20);
                      
                  setDefaultBarThickness(21);
                      
                  setDefaultBarThickness(22);
                      
                  setDefaultBarThickness(23);
                      
                  setDefaultBarThickness(24);
                      
                  setDefaultBarThickness(25);
                      
                  setPlotType(PLOTTYPE_LINE0);
                      
                  setPlotType(PLOTTYPE_LINE1);
                      
                  setPlotType(PLOTTYPE_LINE2);
                      
                  setPlotType(PLOTTYPE_LINE3);
                      
                  setPlotType(PLOTTYPE_LINE4);
                      
                  setPlotType(PLOTTYPE_LINE5);
                      
                      var 
                  fp1 = new FunctionParameter("MinTick"FunctionParameter.NUMBER);
                      
                  fp1.setDefault(0.0001); //Edit this value to set a new default
                      
                  var fp2 = new FunctionParameter("Profit"FunctionParameter.NUMBER);
                      
                  fp2.setName("Ticks Profit");
                      
                  fp2.setDefault(100); //Edit this value to set a new default
                      
                  var fp3 = new FunctionParameter("Stop"FunctionParameter.NUMBER);
                      
                  fp3.setName("Ticks Stop");
                      
                  fp3.setDefault(40); //Edit this value to set a new default
                      
                      
                  var fp4 = new FunctionParameter("MA1Length"FunctionParameter.NUMBER);
                      
                  fp4.setLowerLimit(1);        
                      
                  fp4.setDefault(20); //Edit this value to set a new default
                      
                  var fp5 = new FunctionParameter("MA1Offset"FunctionParameter.NUMBER);
                      
                  fp5.setDefault(0); //Edit this value to set a new default
                      
                  var fp6 = new FunctionParameter("MA1Source"FunctionParameter.STRING);
                      
                  fp6.setName("MA1Source");
                      
                  fp6.addOption("Close");
                      
                  fp6.addOption("High");
                      
                  fp6.addOption("Low");
                      
                  fp6.addOption("Open");
                      
                  fp6.addOption("HL/2");
                      
                  fp6.addOption("HLC/3");
                      
                  fp6.addOption("OHLC/4");
                      
                  fp6.setDefault("HLC/3"); //Edit this value to set a new default     
                      
                  var fp7 = new FunctionParameter("MA1Type"FunctionParameter.STRING);
                      
                  fp7.setName("MA1Type");
                      
                  fp7.addOption("MAStudy.SIMPLE");
                      
                  fp7.addOption("MAStudy.EXPONENTIAL");
                      
                  fp7.addOption("MAStudy.WEIGHTED");
                      
                  fp7.addOption("MAStudy.VOLUMEWEIGHTED");
                      
                  fp7.setDefault("MAStudy.WEIGHTED"); //Edit this value to set a new default

                  }

                  var 
                  vEntryPrice 0;
                  var 
                  vTargetPrice 0;
                  var 
                  vStopPrice 0;
                  var 
                  BarCntr 0;

                  function 
                  main(MinTick,Profit,Stop,MA1Length,MA1Offset,MA1Source,MA1Type) {

                      if (
                  vMA1 == nullvMA1 = new MAStudy(MA1LengthMA1OffsetMA1Source, eval(MA1Type));

                      var 
                  space 1;
                      if (
                  getInterval() != "D")
                          
                  space high(-1)-low(-1);

                      if(
                  getBarState()==BARSTATE_NEWBAR){
                      
                  vCntr +=1;
                      }
                      if(
                  vCntr<53)
                      return;
                      
                          
                  BarCntr++
                   
                      var 
                  SenkouA = (vDonchian_3.getValue(DonchianStudy.BASIS)+vDonchian_4.getValue(DonchianStudy.BASIS))/2;
                      
                      if(
                  SenkouA>vDonchian_5.getValue(DonchianStudy.BASIS))
                          
                  setBarBgColor(Color.white,0,vDonchian_5.getValue(DonchianStudy.BASIS),SenkouA);
                      if(
                  SenkouA<vDonchian_5.getValue(DonchianStudy.BASIS))
                          
                  setBarBgColor(Color.white,0,SenkouA,vDonchian_5.getValue(DonchianStudy.BASIS));
                          
                      if(
                  getBarState()==BARSTATE_NEWBAR){ 
                          if(
                  close(-1)>vDonchian_2.getValue(DonchianStudy.BASIS,-1)&&
                             
                  vMA1.getValue(MAStudy.MA,-1)>vMA1.getValue(MAStudy.MA,-2)){
                                 
                  drawTextRelative(0,low(),"é",Color.blue,null,Text.TOP|Text.CENTER|Text.BOLD,"Wingdings",12,"Up"BarCntr);
                                 
                  drawTextRelative(-1low(-1)-(space*0.55),"Long",Color.white,Color.blue,Text.FRAME|Text.ONTOP|Text.BOLDnull,12,"text buy"+BarCntr );
                                 
                  Strategy.doLong("Long",Strategy.MARKET,Strategy.THISBAR);
                                 
                  vEntryPrice open(0);
                                 
                  vTargetPrice vEntryPrice+(Profit*MinTick);
                                 
                  vStopPrice vEntryPrice-(Stop*MinTick); 
                                 
                  Alert.playSound("long_eur.wav"); 
                                 
                  Alert.email("Buy EUR/USD""Buy EUR/USD" );
                          }
                          if(
                  close(-1)<vDonchian_2.getValue(DonchianStudy.BASIS,-1)&&
                             
                  vMA1.getValue(MAStudy.MA,-1)<vMA1.getValue(MAStudy.MA,-2)){
                                 
                  drawTextRelative(0,high(),"ê",Color.red,null,Text.BOTTOM|Text.CENTER|Text.BOLD,"Wingdings",12,"Dn"BarCntr);
                                 
                  drawTextRelative(-1,high(-1)+(space*0.55),"Short",Color.white,Color.red,Text.FRAME|Text.BOTTOM|Text.BOLD,null,12,"text sell"+BarCntr );
                                 
                  Strategy.doShort("Short",Strategy.MARKET,Strategy.THISBAR);
                                 
                  vEntryPrice open(0);
                                 
                  vTargetPrice vEntryPrice-(Profit*MinTick);
                                 
                  vStopPrice vEntryPrice+(Stop*MinTick);
                                 
                  Alert.playSound("short_eur.wav");
                                 
                  Alert.email("Sell EUR/USD""Sell EUR/USD" );
                          }
                      }
                      
                      if(
                  Strategy.isLong()==true){
                          if(
                  high(0)>=vTargetPrice){
                              
                  Strategy.doSell("Profit Sell",Strategy.STOP,Strategy.THISBAR,null,vTargetPrice);
                          }
                          if(
                  low(0)<=vStopPrice){
                              
                  Strategy.doSell("Stop Sell",Strategy.STOP,Strategy.THISBAR,null,vStopPrice);
                          }
                      }
                      if(
                  Strategy.isShort()==true){
                          if(
                  low(0)<=vTargetPrice){
                              
                  Strategy.doCover("Profit Cover",Strategy.STOP,Strategy.THISBAR,null,vTargetPrice);
                          }
                          if(
                  high(0)>=vStopPrice){
                              
                  Strategy.doCover("Stop Cover",Strategy.STOP,Strategy.THISBAR,null,vStopPrice);
                          }        
                      }

                      if(
                  getBarState() == BARSTATE_NEWBAR){
                          var 
                  nNum 1;
                      }else{
                          var 
                  nNum 0;
                      }
                      
                      if(
                  getBuildNumber()>636){
                          
                  setBar(Bar.Value,-26+nNum,2,close(0));
                      }else{
                          
                  setBar(Bar.Value,-26+nNum,new Array(null,null,close(0),null,null));
                      }

                      return new Array(
                  vDonchian.getValue(DonchianStudy.BASIS),vDonchian_2.getValue(DonchianStudy.BASIS),
                                       
                  null,SenkouA,vDonchian_5.getValue(DonchianStudy.BASIS),vMA1.getValue(MAStudy.MA));

                  Last edited by techinvest; 12-06-2005, 03:39 AM.

                  Comment


                  • #10
                    techinvest
                    In your Strategy.isLong== or Strategy.isShort== examples you omitted to use the parenthesis ie Strategy.isLong()==
                    The brackets { and } open and close a function or a statement. They are not required (but it is good practice to use them all the time) if the statement executes only one function. For example if you want to color the plot red when a given condition is true you would write

                    if(myCondition==true)
                    setBarFgColor(Color.myColor);


                    However if you want to color the plot and make it thicker now you need to use the brackets ie

                    if(myCondition==true) {
                    setBarFgColor(Color.myColor);
                    setBarThickness(n);
                    }


                    && is a logical operator which means AND. For a complete list of the available operators see this article in the EFS KnowledgeBase
                    Alex

                    Comment


                    • #11
                      Beauuuuuuuuuuuuuuutiful! Thanks again, but alas, I lied to you. I still have another question.

                      What I've noticed in my current strategy is the tendency for the price to retrace enough to cover my broker spreads after I enter the trade. Now... my question is how to properly code that strategy.

                      Ex.
                      1) All conditions true for long position
                      2) Enter position at current bars open minus .0003 (3 pips)

                      or if that's not possible

                      1) All conditions true for long position
                      2) Enter position at previous bars close minus .0003 (3 pips)

                      Here's what I tried:

                      Strategy.doLong("Long",Strategy.LIMIT,Strategy.THI SBAR);
                      buyLimit(open()-(.0003));
                      also: buyLimit(open().getValue-(.0003));

                      and

                      Strategy.doLong("Long",Strategy.LIMIT,Strategy.THI SBAR);
                      buyLimit(close(-1)-(.0003));
                      also: buyLimit(close(-1).getValue-(.0003));

                      but neither work correctly. Thanks in advance,,, again

                      Rest assured that I will post the completed script when it is completed. It backtests very well in it's current configuration and if I can cover the broker spreads in a retracement I'll be very very happy with it.
                      Last edited by techinvest; 12-07-2005, 06:22 AM.

                      Comment


                      • #12
                        Like I said, in it's current configuration (modified since my last posting of the script) it does pretty well.

                        Now, is there anything I need to be concerned with as far as the Kijun-Sen line is concerned? I mean, I know how negative offsets on MA's affect backtesting results now, and I want to make sure the KS doens't negatively impact the trading when it's live. I know the KS is computed using past data, buuuuut I'm just making sure.

                        Also please see my question below about entry upon a 3 pip retracement.
                        Last edited by techinvest; 12-08-2005, 11:56 AM.

                        Comment


                        • #13
                          techinvest
                          You need to include the limit price inside the Strategy.doXxxx() commands. See this article in the EFS KnowledgeBase for the syntax required by the Strategy Objects
                          Alex

                          Comment


                          • #14
                            I suppose there's a reason you keep pointing me to the Knowledge Base . Thank you for doing it though. I am finally getting it all.

                            Just checking (because it works),is this the correct syntax for doing what I mentioned earlier?

                            Strategy.doLong("Long",Strategy.LIMIT,Strategy.THI SBAR,null,close(-1)-.0003);

                            I just want to make sure as it catapulted my profits through the roof. It looks almost too good, so my thoughts??? Something's wrong

                            ADDED 1:52PM CST:

                            This is the original script although I'm only using the cross of the KS and the MA here... I'll take the rest out later. Anyway could you take a look at the script on a 5 minute CHF A0-FX chart and tell me why it keeps making more trades when I'm in a trade? I thought I was getting stopped out and then it would find the conditions true again and re-enter, but nope. The odd thing is if you backtest it, it doesn't report all of those oddball trades, only the original trade until the reverse conditions become present or it gets stopped out. It sure does send out emails and play sounds in real time though

                            PHP Code:
                            /********************************
                            Original file ichimoku(alerts).efs by
                            Alexis C. Montenegro © June 2003 
                            Kijun-Sen Franc.efs is an adaptation of 
                            the original file by McLean Van Cleve
                            *********************************/

                            var vDonchian = new DonchianStudy(70);
                            var 
                            vDonchian_2 = new DonchianStudy(220);
                            var 
                            vDonchian_3 = new DonchianStudy(722);
                            var 
                            vDonchian_4 = new DonchianStudy(2222);
                            var 
                            vDonchian_5 = new DonchianStudy(4422);
                            var 
                            vCntr 0;
                            var 
                            vMA1 null;



                            function 
                            preMain() {

                                
                            setPriceStudy(true);
                                
                            setStudyTitle("Kijun-Sen Franc");
                                
                            setCursorLabelName("Tenkan"0);
                                
                            setCursorLabelName("Kijun"1);
                                
                            setCursorLabelName("Chikou"2);
                                
                            setCursorLabelName("SenkouA"3);
                                
                            setCursorLabelName("SenkouB"4);
                                
                            setCursorLabelName("MA1"5);
                                
                            setDefaultBarStyle(PS_SOLID0);
                                
                            setDefaultBarStyle(PS_SOLID1);
                                
                            setDefaultBarStyle(PS_SOLID2);
                                
                            setDefaultBarStyle(PS_SOLID3);
                                
                            setDefaultBarStyle(PS_SOLID4);
                                
                            setDefaultBarStyle(PS_SOLID5);
                                
                            setDefaultBarFgColor(Color.white0);
                                
                            setDefaultBarFgColor(Color.red1);
                                
                            setDefaultBarFgColor(Color.white2);
                                
                            setDefaultBarFgColor(Color.white3);
                                
                            setDefaultBarFgColor(Color.white4);
                                
                            setDefaultBarFgColor(Color.yellow5);
                                
                            setDefaultBarThickness(20);
                                
                            setDefaultBarThickness(21);
                                
                            setDefaultBarThickness(22);
                                
                            setDefaultBarThickness(23);
                                
                            setDefaultBarThickness(24);
                                
                            setDefaultBarThickness(25);
                                
                            setPlotType(PLOTTYPE_LINE0);
                                
                            setPlotType(PLOTTYPE_LINE1);
                                
                            setPlotType(PLOTTYPE_LINE2);
                                
                            setPlotType(PLOTTYPE_LINE3);
                                
                            setPlotType(PLOTTYPE_LINE4);
                                
                            setPlotType(PLOTTYPE_LINE5);
                                
                                var 
                            fp1 = new FunctionParameter("MinTick"FunctionParameter.NUMBER);
                                
                            fp1.setDefault(0.0001); //Edit this value to set a new default
                                
                            var fp2 = new FunctionParameter("Stop"FunctionParameter.NUMBER);
                                
                            fp2.setName("Ticks Stop");
                                
                            fp2.setDefault(20); //Edit this value to set a new default
                                
                                
                            var fp3 = new FunctionParameter("MA1Length"FunctionParameter.NUMBER);
                                
                            fp3.setLowerLimit(1);        
                                
                            fp3.setDefault(20); //Edit this value to set a new default
                                
                            var fp4 = new FunctionParameter("MA1Offset"FunctionParameter.NUMBER);
                                
                            fp4.setDefault(0); //Edit this value to set a new default
                                
                            var fp5 = new FunctionParameter("MA1Source"FunctionParameter.STRING);
                                
                            fp5.setName("MA1Source");
                                
                            fp5.addOption("Close");
                                
                            fp5.addOption("High");
                                
                            fp5.addOption("Low");
                                
                            fp5.addOption("Open");
                                
                            fp5.addOption("HL/2");
                                
                            fp5.addOption("HLC/3");
                                
                            fp5.addOption("OHLC/4");
                                
                            fp5.setDefault("HLC/3"); //Edit this value to set a new default     
                                
                            var fp6 = new FunctionParameter("MA1Type"FunctionParameter.STRING);
                                
                            fp6.setName("MA1Type");
                                
                            fp6.addOption("MAStudy.SIMPLE");
                                
                            fp6.addOption("MAStudy.EXPONENTIAL");
                                
                            fp6.addOption("MAStudy.WEIGHTED");
                                
                            fp6.addOption("MAStudy.VOLUMEWEIGHTED");
                                
                            fp6.setDefault("MAStudy.WEIGHTED"); //Edit this value to set a new default

                            }

                            var 
                            vEntryPrice 0;
                            var 
                            vStopPrice 0;
                            var 
                            BarCntr 0;

                            function 
                            main(MinTick,Profit,Stop,MA1Length,MA1Offset,MA1Source,MA1Type) {

                                if (
                            vMA1 == nullvMA1 = new MAStudy(MA1LengthMA1OffsetMA1Source, eval(MA1Type));

                                var 
                            space 1;
                                if (
                            getInterval() != "D")
                                    
                            space high(-1)-low(-1);

                                if(
                            getBarState()==BARSTATE_NEWBAR){
                                
                            vCntr +=1;
                                }
                                if(
                            vCntr<53)
                                return;
                                
                                    
                            BarCntr++
                             
                                var 
                            SenkouA = (vDonchian_3.getValue(DonchianStudy.BASIS)+vDonchian_4.getValue(DonchianStudy.BASIS))/2;
                                
                                if(
                            SenkouA>vDonchian_5.getValue(DonchianStudy.BASIS))
                                    
                            setBarBgColor(Color.white,0,vDonchian_5.getValue(DonchianStudy.BASIS),SenkouA);
                                if(
                            SenkouA<vDonchian_5.getValue(DonchianStudy.BASIS))
                                    
                            setBarBgColor(Color.white,0,SenkouA,vDonchian_5.getValue(DonchianStudy.BASIS));
                                    
                                if(
                            getBarState()==BARSTATE_NEWBAR){ 
                                    if(
                            Strategy.isLong() == false)
                                    if(
                            vMA1.getValue(MAStudy.MA,-1)>vDonchian_2.getValue(DonchianStudy.BASIS,-1)){
                                           
                            drawTextRelative(0,low(),"é",Color.blue,null,Text.TOP|Text.CENTER|Text.BOLD,"Wingdings",12,"Up"BarCntr);
                                           
                            drawTextRelative(-1low(-1)-(space*0.55),"Long",Color.white,Color.blue,Text.FRAME|Text.ONTOP|Text.BOLDnull,12,"text buy"+BarCntr );
                                           
                            Strategy.doLong("Long",Strategy.LIMIT,Strategy.THISBAR,null,close(-1)-.0005);
                                           
                            vEntryPrice open(0);
                                           
                            vStopPrice vEntryPrice-(Stop*MinTick); 
                                           
                            Alert.playSound("long_chf.wav"); 
                                           
                            Alert.email("Buy USD/CHF""Buy USD/CHF" );
                                    }
                                    if(
                            Strategy.isShort() == false)
                                    if(
                            vMA1.getValue(MAStudy.MA,-1)<vDonchian_2.getValue(DonchianStudy.BASIS,-1)){
                                           
                            drawTextRelative(0,high(),"ê",Color.red,null,Text.BOTTOM|Text.CENTER|Text.BOLD,"Wingdings",12,"Dn"BarCntr);
                                           
                            drawTextRelative(-1,high(-1)+(space*0.55),"Short",Color.white,Color.red,Text.FRAME|Text.BOTTOM|Text.BOLD,null,12,"text sell"+BarCntr );
                                           
                            Strategy.doShort("Short",Strategy.LIMIT,Strategy.THISBAR,null,close(-1)+.0005);
                                           
                            vEntryPrice open(0);
                                           
                            vStopPrice vEntryPrice+(Stop*MinTick);
                                           
                            Alert.playSound("short_chf.wav");
                                           
                            Alert.email("Sell USD/CHF""Sell USD/CHF" );
                                    }
                                }
                                

                                if(
                            Strategy.isLong()==true){
                                    if(
                            low(0)<=vStopPrice){
                                        
                            Strategy.doSell("Stop Sell",Strategy.STOP,Strategy.THISBAR,null,vStopPrice);
                                    }
                                }
                                if(
                            Strategy.isShort()==true){
                                    if(
                            high(0)>=vStopPrice){
                                        
                            Strategy.doCover("Stop Cover",Strategy.STOP,Strategy.THISBAR,null,vStopPrice);
                                    }        
                                }

                                if(
                            getBarState() == BARSTATE_NEWBAR){
                                    var 
                            nNum 1;
                                }else{
                                    var 
                            nNum 0;
                                }
                                
                                if(
                            getBuildNumber()>636){
                                    
                            setBar(Bar.Value,-26+nNum,2,close(0));
                                }else{
                                    
                            setBar(Bar.Value,-26+nNum,new Array(null,null,close(0),null,null));
                                }

                                return new Array(
                            vDonchian.getValue(DonchianStudy.BASIS),vDonchian_2.getValue(DonchianStudy.BASIS),
                                                 
                            null,SenkouA,vDonchian_5.getValue(DonchianStudy.BASIS),vMA1.getValue(MAStudy.MA));

                            Last edited by techinvest; 12-07-2005, 01:09 PM.

                            Comment


                            • #15
                              techinvest
                              The syntax in Strategy.doLong("Long", Strategy.LIMIT, Strategy.THISBAR, null, close(-1)-.0003); is correct.
                              What it means is "go Long IF the current bar's Low is equal OR lower to the prior bar's Close minus 0.0003".
                              In this description lies the reason why your efs is drawing multiple graphics on the chart (thereby giving the false impression that it is triggering multiple trades) yet showing in the back test only one trade for the corresponding group of graphics.
                              To illustrate the point I will use the following section of code from your efs

                              PHP Code:
                              if(Strategy.isLong() == false){
                                  if(
                              vMA1.getValue(MAStudy.MA,-1)>vDonchian_2.getValue(DonchianStudy.BASIS,-1)){
                                      
                              drawTextRelative(0,low(),"é",Color.blue,null,Text.TOP|Text.CENTER|Text.BOLD,"Wingdings",12,"Up"BarCntr);
                                      
                              drawTextRelative(-1low(-1)-(space*0.55),"Long",Color.white,Color.blue,Text.FRAME|Text.ONTOP|Text.BOLDnull,12,"text buy"+BarCntr );
                                      
                              Strategy.doLong("Long",Strategy.LIMIT,Strategy.THISBAR,null,close(-1)-.0005);
                                      
                              //etc
                                  
                              }

                              This means that on every bar in which the Strategy is NOT Long AND the MA is above the Kijun the condition is true and the corresponding commands will be executed. So all the graphic objects get drawn, the alerts get triggered etc. However unless the Low of the current bar is less or equal to the Close of the prior bar minus 0.0005 the Strategy does not go Long. But at this point the graphic objects are already drawn for the current bar regardless of the fact that the Strategy did not go Long.
                              At the next iteration of the efs the Strategy is still not Long and executes again all the commands ie draws all the grahics etc. This goes on until there is a bar in which the Low is equal or lower than the prior Close - 0.0005. Up to the time when that happens it will continue to execute the commands to draw graphics, trigger alerts, etc because it is NOT Long.
                              Look at the example in the image enclosed below. To better illustrate the point I changed the Limit price to be close(-1) - 0.0010. As you can see the arrows get drawn on each bar in which the MA is above the Kijun. None of those bars however has a Low that equals or breaches the value of close(-1) - 0.0010 hence the Strategy never goes Long. Only the last one actually does that and in fact that is the time and price that appears as a Long entry in the back test report. And no further arrows get drawn beyond that bar because at that point the Strategy goes Long



                              At this point I would suggest that before you modify your efs any further you spend some time reading through the Guide to Developing eSignal Strategies and the Guide to Developing eSignal Graphics both of which are in the EFS KnowledgeBase.
                              I would also suggest that you rewrite your strategy from the beginning adding conditions and commands only once you have verified that each and every addition you implement does exactly what it is supposed to do and when.
                              Alex

                              Comment

                              Working...
                              X