Announcement

Collapse
No announcement yet.

Fixed/trailing stops and limits

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

  • Fixed/trailing stops and limits

    Hi

    Could someone from E-Signal support please direct me to simple code examples or actual coding for fixed and trailing stops and limit orders for forex intra-day back testing.

    As I am not a trained programmer, something to cut and paste into the EFS editor would be great

    Regards

    James

  • #2
    Read the following...

    Go to the EFS help page and read..

    The Guide To Developing Strategies.

    This guide shows examples of stops and trailing stops.

    Brad
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #3
      Code

      Many thanks Brad

      I did see that code before. I have tried to use it and modify it to suit my algorithms, but without luck, considering my limited programming.

      There appear to be some syntax errors in the code as well.

      Actually what I REALLY would appreciate is if someone could send me (via email) a simple code for, for example, a 2 moving average cross over system, complete with stops and limits. Trailing stops even better.

      I am not using an MA cross system, but can put my system code in easily enough, given a basic (working/debugged) framework to work with.

      Any help would be greatly appreciated from anyone who may be able to assist!

      James
      Team Forex
      email: [email protected]

      Comment


      • #4
        Stops...

        OK.

        I have posted many examples of developing trailing stops for a system. If you give me some more details or what you are trying to accomplish, I will try to assist you?
        Brad Matheny
        eSignal Solution Provider since 2000

        Comment


        • #5
          Here is the basic structure for a stop system

          Follow this example for a basic stop system...

          PHP Code:
          var nStopPrice;
          var 
          nLastRawTime  0;
          var 
          BLBarOffset 0;

          function 
          main() {

          //  Bar Counter function.
             
          if (getValue("rawtime"0) != nLastRawTime) {
               
          nLastRawTime getValue("rawtime",0);
               
          BLBarOffset += 1;
             }

          // Handle Stops.
            
          if (Strategy.isInTrade()) {
                  
          drawShapeRelative(0nStopPriceShape.DIAMONDnullColor.blueShape.ONTOPBLBarOffset+"lFSX");
              if (
          Strategy.isLong()) {
                if (
          low() <= nStopPrice) {  //  Long Stop Hit
                  
          if (high() < nStopPrice) {
                    
          Strategy.doSell("LongStop"Strategy.LIMIT,
                       
          Strategy.THISBARStrategy.DEFAULT, open());
                  } else {
                    
          Strategy.doSell("LongStop"Strategy.LIMIT,
                       
          Strategy.THISBARStrategy.DEFAULT, nStopPrice);
                  }
                }
              }
              if (
          Strategy.isShort()) {
                if (
          high() >= nStopPrice) {  //  Short Stop Hit
                  
          if (low() > nStopPrice) {
                    
          Strategy.doCover("ShortStop"Strategy.LIMIT,
                       
          Strategy.THISBARStrategy.DEFAULT, open());
                  } else {
                    
          Strategy.doCover("ShortStop"Strategy.LIMIT,
                       
          Strategy.THISBARStrategy.DEFAULT, nStopPrice);
                  }
                }
              }
            }

          //  Handle Entries.
            
          if ((!Strategy.isInTrade()) || (Strategy.isShort())) {
             
          //  Condition for Long Entries
             
          nStopPrice n;
            }
            if ((!
          Strategy.isInTrade()) || (Strategy.isLong())) {
             
          //  Condition for Short Entries
             
          nStopPrice n;
            }

          }  
          // end of main 
          This is a basic example of a stop system at work in a system. It tests for every possibly condition of the stop order being generated.

          The value nStopPrice is a variable that you set with your entries. You can set it to a fixed value (EntryPrice +/- value) or continue to set it to different values if necessary.

          To make it a trailing stop, you would simply make the following code adjustments...
          1. Track your entry price
          2. Track the stop price compared to the current price (say a high or low).
          3. Add a comparison routine to adjust the nStopPrice value.

          Here is an example of the coade above modified to handle a trailing stop.

          PHP Code:
          var StopLevel 1.5//  Default stop level.

          var nEntryPrice;
          var 
          nStopPrice;
          var 
          nLastRawTime  0;
          var 
          BLBarOffset 0;

          function 
          main() {

          //  Bar Counter function.
             
          if (getValue("rawtime"0) != nLastRawTime) {
               
          nLastRawTime getValue("rawtime",0);
               
          BLBarOffset += 1;
             }

          // Handle Stops.
            
          if (Strategy.isInTrade()) {
             
          //  Draw Current Stop Level on Chart.
                  
          drawShapeRelative(0nStopPriceShape.DIAMONDnullColor.blueShape.ONTOPBLBarOffset+"lFSX");

             
          //-------------------------------------------------
             //  Test for stop exits
              
          if (Strategy.isLong()) {
                if (
          low() <= nStopPrice) {  //  Long Stop Hit
                  
          if (high() < nStopPrice) {
                    
          Strategy.doSell("LongStop"Strategy.LIMIT,
                       
          Strategy.THISBARStrategy.DEFAULT, open());
                  } else {
                    
          Strategy.doSell("LongStop"Strategy.LIMIT,
                       
          Strategy.THISBARStrategy.DEFAULT, nStopPrice);
                  }
                }
              }
              if (
          Strategy.isShort()) {
                if (
          high() >= nStopPrice) {  //  Short Stop Hit
                  
          if (low() > nStopPrice) {
                    
          Strategy.doCover("ShortStop"Strategy.LIMIT,
                       
          Strategy.THISBARStrategy.DEFAULT, open());
                  } else {
                    
          Strategy.doCover("ShortStop"Strategy.LIMIT,
                       
          Strategy.THISBARStrategy.DEFAULT, nStopPrice);
                  }
                }
              }
             
          //  End of test for stop exits
             //--------------------------------------------------------
             //  Text for new trailing stop....
             
          if (Strategy.isLong()) {
               if ((
          high()-StopLevel) > nStopPrice) {
                
          nStopPrice = (high()-StopLevel);
               }
             }
             if (
          Strategy.isShort()) {
               if ((
          low()+StopLevel) < nStopPrice) {
                
          nStopPrice = (low()+StopLevel);
               }
             }

            }  
          //  end if Strategy.isInTrade()


          //  Handle Entries.
            
          if ((!Strategy.isInTrade()) || (Strategy.isShort())) {
             
          //  Condition for Long Entries
             
          nEntryPrice close();  //  assuming our entry is the current price.
             
          nStopPrice nEntryPrice-StopLevel;
            }
            if ((!
          Strategy.isInTrade()) || (Strategy.isLong())) {
             
          //  Condition for Short Entries
             
          nEntryPrice close();  //  assuming our entry is the current price.
             
          nStopPrice nEntryPrice+StopLevel;
            }

          // end of main 
          That is the basics of the system. You can use this code to develop your own system. Let me know if you have any other questions.
          Brad Matheny
          eSignal Solution Provider since 2000

          Comment


          • #6
            Stops and Limits

            Hi

            Many thanks for your VERY helpful reply. I know I'm being a pain, but 2 more questions in relation to this:

            1. Where does the actual entry system code get placed within the code you have posted? I will generate this myself, but perhaps you could include a simple example in your code (eg a cross over system)

            2. Does the code you gave also deal with the limits (profit taking)

            Thanks again in advance

            James

            Comment


            • #7
              To make it easier...

              I can tell this is going to waste your time and mine unless I become a little more clear.

              What I want to do is the following:

              1. Enter long when close is above 100 SMA and 14 period RSI below 30
              2. Enter short when close is below 100 SMA and 14 period RSI above 70
              3. Use 25 pip stop and 50 pip profit target
              4. If stop or limit not hit, and a new direction is given, then reverse trade direction.

              I would like to apply this to the charts with some alert indicator such as a colour or an arrow, and also be able to back test.

              I know this is a big ask, and the basics are all easily found on this forum, but I just can't put it all together. If at all possible, could you knock together the right code for this little trading signal and post it here for me

              Thanks again
              James

              Comment


              • #8
                Take another look at the code..

                TeamForex.....

                Take another look at the code I detailed below. It has a section for ENTRY SIGNALS and has the STOP and PT code in place to handle just about anything you want.

                If you would like me to "complete this code for you", then I would be consulting for you .. and seeing as though you are a "retail firm" .. I would ask your to consider hiring me to develop the code for you.

                If you don't want to consider this option, then you have almost everything you need to get started developing your code from my examples. Try to make it work and see if you can do it yourself - I'm sure you can - it just takes time and patience.

                Brad
                Brad Matheny
                eSignal Solution Provider since 2000

                Comment


                • #9
                  Tried

                  Hi Brad

                  Tried...but failed. Whats it going to cost me for you to help out please? (Have pity)

                  Comment


                  • #10
                    Check your email..

                    James,

                    Check your email. I have sent you all the instructions to begin your project. I will have it finished within the next 24~48 hours.

                    Brad
                    Brad Matheny
                    eSignal Solution Provider since 2000

                    Comment


                    • #11
                      Hello

                      i search also Forex Tradingsystem Esignal can you me help

                      Comment


                      • #12
                        Finger...

                        You have a question or are you trying to find a system to trade??

                        Brad
                        Brad Matheny
                        eSignal Solution Provider since 2000

                        Comment


                        • #13
                          Hello

                          yes i search system for forex

                          Comment


                          • #14
                            Re: Here is the basic structure for a stop system

                            Hello,
                            Is there an easy way to integrate your simple stop system to the Moving Average System below. Obliviously I don't know how to write code.

                            Tried several attempts at trial and error to put them together to no avail.
                            Thanks for any help with this.

                            Originally posted by Doji3333
                            Follow this example for a basic stop system...

                            PHP Code:
                            var nStopPrice;
                            var 
                            nLastRawTime  0;
                            var 
                            BLBarOffset 0;

                            function 
                            main() {

                            //  Bar Counter function.
                               
                            if (getValue("rawtime"0) != nLastRawTime) {
                                 
                            nLastRawTime getValue("rawtime",0);
                                 
                            BLBarOffset += 1;
                               }

                            // Handle Stops.
                              
                            if (Strategy.isInTrade()) {
                                    
                            drawShapeRelative(0nStopPriceShape.DIAMONDnullColor.blueShape.ONTOPBLBarOffset+"lFSX");

                                if (
                            Strategy.isLong()) {
                                  if (
                            low() <= nStopPrice) {  //  Long Stop Hit
                                    
                            if (high() < nStopPrice) {
                                      
                            Strategy.doSell("LongStop"Strategy.LIMIT,
                                         
                            Strategy.THISBARStrategy.DEFAULT, open());
                                    } else {
                                      
                            Strategy.doSell("LongStop"Strategy.LIMIT,
                                         
                            Strategy.THISBARStrategy.DEFAULT, nStopPrice);
                                    }
                                  }
                                }
                                if (
                            Strategy.isShort()) {
                                  if (
                            high() >= nStopPrice) {  //  Short Stop Hit
                                    
                            if (low() > nStopPrice) {
                                      
                            Strategy.doCover("ShortStop"Strategy.LIMIT,
                                         
                            Strategy.THISBARStrategy.DEFAULT, open());
                                    } else {
                                      
                            Strategy.doCover("ShortStop"Strategy.LIMIT,
                                         
                            Strategy.THISBARStrategy.DEFAULT, nStopPrice);
                                    }
                                  }
                                }
                              }

                            //  Handle Entries.
                              
                            if ((!Strategy.isInTrade()) || (Strategy.isShort())) {
                               
                            //  Condition for Long Entries
                               
                            nStopPrice n;
                              }
                              if ((!
                            Strategy.isInTrade()) || (Strategy.isLong())) {
                               
                            //  Condition for Short Entries
                               
                            nStopPrice n;
                              }

                            }  
                            // end of main 
                            This is a basic example of a stop system at work in a system. It tests for every possibly condition of the stop order being generated.

                            The value nStopPrice is a variable that you set with your entries. You can set it to a fixed value (EntryPrice +/- value) or continue to set it to different values if necessary.

                            To make it a trailing stop, you would simply make the following code adjustments...
                            1. Track your entry price
                            2. Track the stop price compared to the current price (say a high or low).
                            3. Add a comparison routine to adjust the nStopPrice value.

                            Here is an example of the coade above modified to handle a trailing stop.

                            PHP Code:
                            var StopLevel 1.5//  Default stop level.

                            var nEntryPrice;
                            var 
                            nStopPrice;
                            var 
                            nLastRawTime  0;
                            var 
                            BLBarOffset 0;

                            function 
                            main() {

                            //  Bar Counter function.
                               
                            if (getValue("rawtime"0) != nLastRawTime) {
                                 
                            nLastRawTime getValue("rawtime",0);
                                 
                            BLBarOffset += 1;
                               }

                            // Handle Stops.
                              
                            if (Strategy.isInTrade()) {
                               
                            //  Draw Current Stop Level on Chart.
                                    
                            drawShapeRelative(0nStopPriceShape.DIAMONDnullColor.blueShape.ONTOPBLBarOffset+"lFSX");

                               
                            //-------------------------------------------------
                               //  Test for stop exits
                                
                            if (Strategy.isLong()) {
                                  if (
                            low() <= nStopPrice) {  //  Long Stop Hit
                                    
                            if (high() < nStopPrice) {
                                      
                            Strategy.doSell("LongStop"Strategy.LIMIT,
                                         
                            Strategy.THISBARStrategy.DEFAULT, open());
                                    } else {
                                      
                            Strategy.doSell("LongStop"Strategy.LIMIT,
                                         
                            Strategy.THISBARStrategy.DEFAULT, nStopPrice);
                                    }
                                  }
                                }
                                if (
                            Strategy.isShort()) {
                                  if (
                            high() >= nStopPrice) {  //  Short Stop Hit
                                    
                            if (low() > nStopPrice) {
                                      
                            Strategy.doCover("ShortStop"Strategy.LIMIT,
                                         
                            Strategy.THISBARStrategy.DEFAULT, open());
                                    } else {
                                      
                            Strategy.doCover("ShortStop"Strategy.LIMIT,
                                         
                            Strategy.THISBARStrategy.DEFAULT, nStopPrice);
                                    }
                                  }
                                }
                               
                            //  End of test for stop exits
                               //--------------------------------------------------------
                               //  Text for new trailing stop....
                               
                            if (Strategy.isLong()) {
                                 if ((
                            high()-StopLevel) > nStopPrice) {
                                  
                            nStopPrice = (high()-StopLevel);
                                 }
                               }
                               if (
                            Strategy.isShort()) {
                                 if ((
                            low()+StopLevel) < nStopPrice) {
                                  
                            nStopPrice = (low()+StopLevel);
                                 }
                               }

                              }  
                            //  end if Strategy.isInTrade()


                            //  Handle Entries.
                              
                            if ((!Strategy.isInTrade()) || (Strategy.isShort())) {
                               
                            //  Condition for Long Entries
                               
                            nEntryPrice close();  //  assuming our entry is the current price.
                               
                            nStopPrice nEntryPrice-StopLevel;
                              }
                              if ((!
                            Strategy.isInTrade()) || (Strategy.isLong())) {
                               
                            //  Condition for Short Entries
                               
                            nEntryPrice close();  //  assuming our entry is the current price.
                               
                            nStopPrice nEntryPrice+StopLevel;
                              }

                            // end of main 
                            That is the basics of the system. You can use this code to develop your own system. Let me know if you have any other questions.
                            Attached Files

                            Comment


                            • #15
                              I can add it....

                              But I would suggest you try to deisgn a stop system based on your needs.. Sometimes stop systems include the following components..

                              1. Initial stop level.
                              2. Breakeven stop adjustment
                              3. Breakeven+ stop adjustment
                              4. Trailing stop levels (normal)
                              5. Trailing stop levels (exhaustion)

                              These are some things I might consider adding to your system if I knew what you were looking for...

                              I'm almost done re-designing my web site. I'll try to take a look at this in the next few days.. I can't tell you how much work is involved in converting a 100+ page web site to a new design - it sucks. It's like re-writing a 100+ page book.

                              B
                              Brad Matheny
                              eSignal Solution Provider since 2000

                              Comment

                              Working...
                              X