Announcement

Collapse
No announcement yet.

EMA Crossover

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

  • EMA Crossover

    I had just subscribe to esignal and I have no idea how to code this scenario.

    Buy when EMA 7 cross-up EMA 21 and sell when it is 50 pips from the crossover point or sell when it goes down 20 pips below the crossover point.

    Vice versa when you short it.

    Any links or help is greatly appreciated.

  • #2
    edmundm
    I think the attached efs does what you want.
    It calculates the two MAs and when a cross is confirmed at the close of a bar it will go long or short accordingly. In either case it will close the trade if the profit target or the stop are touched or if a signal in the opposite direction is generated. When the strategy is long it paints the bars in blue and when short in red.
    All parameters for the MAs can be modified through Edit Studies. Also set in Edit Studies are the minimum tick (default is 0.0001) and the ticks for profit and loss stops (defaults are 50 and 20 respectively).
    Alex
    Attached Files

    Comment


    • #3
      Thank you

      Thank you for the code.

      Another thing is when I backtest and I set it to more than 700 bars in the time template is it will just say "Retrieving X bars" and do nothing so I will just cancel the backtest.

      Any suggestions?

      Comment


      • #4
        edmundm
        That can happen at times if the Back Tester itself has to request the necessary bars.
        When back testing it is best to first open a chart and load it with the desired data using the Time Template. Once that is done run the Back Test on that chart
        Alex

        Comment


        • #5
          Alexis,

          Problem is solve.

          I have this another scenario, I hoe for your help again.

          I would like to go long when RSI drop below 30 and put a stop loss 30 pips (variable) and target price at 100 pips (variable).

          Vice versa on going short.

          I found a code in this site and modified it a bit but can't figure out how to put the above scenario in place.

          I modified it instead of going long when RSI is above 70 and went short and vice versa.

          /************************************************** *****************
          Description : RSI Strategy
          Provided By : Developed by TS Support, LLC for eSignal. (c) Copyright 2002
          ************************************************** ******************/

          var study = new RSIStudy(14, "Close");

          function preMain() {
          setPriceStudy(true);
          setColorPriceBars(true);
          setDefaultPriceBarColor(Color.black);

          }

          function main(oversold,overbought) {
          if (overbought == null)
          overbought = 70;
          if (oversold == null)
          oversold = 30;

          var rsi = study.getValue(RSIStudy.RSI)

          if(rsi == null)
          return;
          if(rsi > overbought && !Strategy.isShort())
          Strategy.doShort("Short", Strategy.CLOSE, Strategy.THISBAR);
          if(rsi < oversold && !Strategy.isLong())
          Strategy.doLong("Long", Strategy.CLOSE, Strategy.THISBAR);
          if(Strategy.isLong())
          setPriceBarColor(Color.lime);
          else if(Strategy.isShort())
          setPriceBarColor(Color.red);
          return;
          }


          Thank you again.

          Comment


          • #6
            edmundm
            The attached efs should do what you asked.
            Compare it to the other strategy and you will see that aside from the study being used the rest of the script is virtually the same.
            As in the other formula all the parameters including MinTick, Profit Target and Stop can be modified through Edit Studies.
            At this point you should have enough examples available to you to implement similar strategies using other studies.
            I would also suggest going through the EFS Help Center & Library and specifically the Guide to Developing EFS Indicators and Guide to Developing EFS Strategies sections.
            Alex
            Attached Files

            Comment


            • #7
              Thank you

              Alexis,

              You're are great. You help people.

              Comment


              • #8
                My thoughts

                The RSI strategy works best in a trading range but on a highly trending market or a breakout it is not good. I look for candle formations (Dojis, Etc) as confirmations before taking a position.

                The last code needs tweaking so that when you short a position when the RSI goes above 70 and cover it after it hits the stop loss it will not open a short position but rather stay on the sideline until the RSI goes back down below 70.

                The same strategy on going long.

                I found this strategy interesting so far.

                Comment


                • #9
                  edmundm
                  If I understand correctly what you are saying then the strategy is already doing that now. For a short trade to be triggered the RSI must have closed below 70 two bars ago and above 70 on the prior bar. The reverse for longs
                  Alex

                  Comment


                  • #10
                    Alexis,

                    You're right. It is already in the code.


                    This strategy works for me because I don't day trade my position. My holding time is between 2 and 6 days or when the stop gets taken out or my target is reached because RSI's cycle from oversold to overbought is from my observation will last for more than 2 days.

                    My strategy to take a position is when I see divergence and candle formations. Another thing is to find out the trend. In an uptrend I will go long when the RSI is below 30 and stay on the sidelines when the RSI goes up above 70. On downtrends I will go short when RSI goes up above 70 and stay on the sideline when RSI is below 30.

                    Thanks again for the code.

                    Comment


                    • #11
                      MA Crossover

                      This strategy is very simple that probably all of you already knew it. Anyway I just wanted it to share to you.

                      A crossover of 5 SMA to 20 SMA produce a very interesting results in the backtester in the 60 minute chart. Entry is on the bar that the SMA crossover happened at market price. Of course not all crossover are tradable - it is now your knowledge, intuition and experience that will tell you which crossover are tradable. You need to find out if it is trending or moving sideways because MA crossovers of any type as I observed is very profitable in trending market.

                      I backtested it on USD/JPY, GBP/USD, EUR/USD and the results are very interesting.

                      Target Price and Stop Loss is also on crossover of the SMA's.

                      Comment

                      Working...
                      X