Announcement

Collapse
No announcement yet.

setting stop

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

  • setting stop

    This is probably the simplest thing to do (or at least it should be) but I can't figure it out. All I want to do is set my stop to 1.5 pts(ES) behing my entry for longs and shorts. Can someone help me with this? I've attached the EFS I'm speaking of.
    Attached Files

  • #2
    Here you go...

    Here you go... The stop setting is on line 17. If you have any questions, please let me know..

    PHP Code:
    //{{EFSWizard_Description
    //
    //    This formula was generated by the Alert Wizard
    //
    //}}EFSWizard_Description 7532


    //{{EFSWizard_Declarations

    var vMACD5_13 = new MACDStudy(5136"Close"false);
    var 
    vStoch9_3 = new StochStudy(933);
    var 
    vChop14 = new ChopStudy(14);
    var 
    vLastAlert = -1;
    var 
    nEntryPrice 0;

    //  Set the value below to your stop setting
    var nStopLevel 1.5;

    //}}EFSWizard_Declarations 19386


    function preMain() {
       
    /**
        *  This function is called only once, before any of the bars are loaded.
        *  Place any study or EFS configuration commands here.
        */
    //{{EFSWizard_PreMain
        
    setPriceStudy(true);
        
    setStudyTitle("Rocket");
        
    setComputeOnClose(true);
    //}}EFSWizard_PreMain 6797

    }

    function 
    main() {
       
    /**
        *  The main() function is called once per bar on all previous bars, once per
        *  each incoming completed bar, and if you don't have 'setComputeOnClose(true)'
        *  in your preMain(), it is also called on every tick.
        */

    //{{EFSWizard_Expressions
        //{{EFSWizard_Expression_1
            
    if (
                
    vStoch9_3.getValue(StochStudy.FAST) > vStoch9_3.getValue(StochStudy.SLOW) &&
                
    vStoch9_3.getValue(StochStudy.FAST) > 20 &&
                
    vStoch9_3.getValue(StochStudy.SLOW) > 20 &&
                
    vMACD5_13.getValue(MACDStudy.HIST, -1) < vMACD5_13.getValue(MACDStudy.HIST) &&
                
    vChop14.getValue(ChopStudy.CHOP) < 62
            
    onAction1()
        
    //}}EFSWizard_Expression_1 42971
        
        //{{EFSWizard_Expression_2
            
    else if (
                
    vStoch9_3.getValue(StochStudy.FAST) < vStoch9_3.getValue(StochStudy.SLOW) &&
                
    vStoch9_3.getValue(StochStudy.FAST) < 80 &&
                
    vStoch9_3.getValue(StochStudy.SLOW) < 80 &&
                
    vMACD5_13.getValue(MACDStudy.HIST, -1) > vMACD5_13.getValue(MACDStudy.HIST) &&
                
    vChop14.getValue(ChopStudy.CHOP) < 62
            
    onAction2();
        
    //}}EFSWizard_Expression_2 44243
        
    //}}EFSWizard_Expressions 113301

      
    if (Strategy.isShort()) {
         if (
    high() >= (nEntryPrice+nStopLevel)) { // stopped out of short position
           
    if (low() >= (nEntryPrice+nStopLevel)) { // Price gap above stop
            
    Strategy.doCover("Short Stop"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, open());
           } else {
            
    Strategy.doCover("Short Stop"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, (nEntryPrice+nStopLevel));
           }
         }
      }
      if (
    Strategy.isLong()) {
         if (
    low() <= (nEntryPrice-nStopLevel)) { // stopped out of short position
           
    if (high() <= (nEntryPrice-nStopLevel)) { // Price gap above stop
            
    Strategy.doSell("Long Stop"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, open());
           } else {
            
    Strategy.doSell("Long Stop"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, (nEntryPrice-nStopLevel));
           }
         }
      }


    //{{EFSWizard_Return
        
    return null;
    //}}EFSWizard_Return 2256

    }

    function 
    postMain() {
       
    /**
        *  The postMain() function is called only once, when the EFS is no longer used for
        *  the current symbol (ie, symbol change, chart closing, or application shutdown).
        */
    }

    //{{EFSWizard_Actions
        //{{EFSWizard_Action_1
        
    function onAction1() {
            if (
    vLastAlert != 1drawShapeRelative(0low()-.15Shape.UPARROW""Color.RGB(0,255,0), Shape.LEFT);
            if (
    vLastAlert != 1Strategy.doLong("long"Strategy.MARKETStrategy.NEXTBARStrategy.DEFAULT, 0);
            
    nEntryPrice open(1);
            
    vLastAlert 1;
        }
        
    //}}EFSWizard_Action_1 32527
        
        //{{EFSWizard_Action_2
        
    function onAction2() {
            if (
    vLastAlert != 2drawShapeRelative(0high()+.15Shape.DOWNARROW""Color.RGB(255,0,0), Shape.LEFT);
            if (
    vLastAlert != 2Strategy.doShort("short"Strategy.MARKETStrategy.NEXTBARStrategy.DEFAULT, 0);
            
    nEntryPrice open(1);
            
    vLastAlert 2;
        }
        
    //}}EFSWizard_Action_2 32086
        
    //}}EFSWizard_Actions 88583 

    Brad
    Attached Files
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #3
      Set stop

      Thanks Brad, that's what I was looking for, unfortunately the results are not what I was hoping for. I seem to be getting stopped out even though the price never reaches my stop price. I'm back testing the 3M ES. Is there a trick to back testing the E-minis? Also, if one wanted to set a target in addition to a stop would the proceedure be the same, only reversed?

      thanks
      Jim

      Comment

      Working...
      X