• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Ema crossover indicator

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

    Ema crossover indicator

    HI ALL ! DURING THIS DAY I AM MOVING FROM TRADESTATION TO NINJA TRADER AND I AM TRYING TO SET UP ALL THE INDICATORS THAT I NEED.
    I AM LOOKING FOR AN INDICATOR WHO PLOT A VERTICAL LINE ON THE CHART WHEN THE EMA34 AND EMA 8 CROSSOVER.
    I CHECKED THE FORUM BUT I HAVE NOT FOUND THIS INDICATOR.
    COULD YOU PLEASE ADDRESS ME WHERE TO FIND IT, OR EVENTUALLY HELP ME TO CONVERT THE EASYLANGUAGE CODE TO A NINJA SCRIPT?
    HERE ATTACHED THE CODE AND ONE PHOTO ABOUT HOW THE INDICATOR SHOULD WORK.

    HERE TO FOLLOW THE EASYLANGUAGE CODE:

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    inputs:

    double Price( Close ), { price used in average calculations for the
    oscillator }
    int FastLength( 8 ), { fast moving average length for oscillator }
    int SlowLength( 34 ), { slow moving average length for oscillator }


    Line1(True),
    String LineColor1("Cyan"),
    Line2(True),
    String LineColor2("yellow");

    Using elsystem.drawingobjects;
    Using elsystem.drawing;

    variables:
    intrabarpersist bool InAChart( false ),
    FastAvg( 0 ),
    SlowAvg( 0 ) ,
    double AO( 0 ),
    bool AOSaucerBuy( false ),
    bool AOCrossBuy( false ),
    bool TwinPeaksBuy( false ),
    bool LookForTwinPeaksBuy( false ),
    bool AOSaucerSell( false ),
    bool AOCrossSell( false ),
    bool TwinPeaksSell( false ),
    bool LookForTwinPeaksSell( false ),
    bool AOPivotLow( false ),
    double AOPivotLowVal( 0 ),
    double AOPivotHighVal( 0 ),
    bool AOPivotHigh( false ),
    bool AlertCondition( false ),
    string GridString( "" ) ,
    VerticalLine VL(null);



    Method void DrawVerticalLine() begin
    VL = VerticalLine.Create(DTPoint.Create(BarDateTime,0)) ;
    VL.Persist = False;
    DrawingObjects.Add(VL);
    End;

    { calculate the oscillator value }
    AO = PriceOscillator( Price, FastLength, SlowLength ) ;
    FastAvg = XAverage( Price, FastLength ) ;
    SlowAvg = XAverage( Price, SlowLength ) ;

    #region Formatting and Alerts
    {
    { set histogram color }
    if FastAvg > SlowAvg then
    SetPlotColor( 1, HistUpColor )
    else if FastAvg < SlowAvg then
    SetPlotColor( 1, HistDownColor )
    else
    SetPlotColor( 1, GetPlotColor( 1 )[1] ) ;}

    #region Buy Setups

    AOCrossBuy = FastAvg crosses above SlowAvg ;

    #endregion

    #region Sell Setups

    AOCrossSell = FastAvg crosses below SlowAvg ;


    #endregion


    { plot dots on histogram in Charting for Buy and Sell setups, set RadarScreen text,
    and trigger alerts }

    if AOCrossBuy then
    begin
    DrawVerticalLine();
    VL.Color = Color.FromName(LineColor1);
    VL.Style = StyleType.Dashed;
    VL.Weight = 0;
    end


    else if AOCrossSell then
    begin

    DrawVerticalLine();
    VL.Color = Color.FromName(LineColor2);
    VL.Style = StyleType.Dashed;
    VL.Weight = 0;
    end



    #endregion

    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    THANK YOU IN ADVANCE

    MARCO
    Attached Files

    #2
    Thank you for your question demo152160 . While directly converting your EasyLanguage code is beyond the scope of the support we can provide I would like to encourage you to review the SampleMACrossover strategy built-in to NinjaTrader. Just follow these steps.

    • New -> NinjaScript Editor
    • Double-click Strategies -> Double-click SampleMACrossover
    • Right-click in the editor window that appears and select "Save As"
    • Save this as SampleEMACrossover

    You can now edit this new copy. If you change the SMA indicators on lines 33 and 34, and lines 50 and 51, to EMA indicators, you will now have the strategy you described.


    Please let us know if there are any other ways we can help.
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      HI JESSICA THANK YOU FOR YOUR FAST ANSWER!

      I HAVE DONE WHAT YOU SUGGESTED BUT WHAT I DO NEED IT IS AN INDICATOR WHO PLOT A VERTICAL LINE IN THE CHART WHEN THE CONDITIONS ARE TRUE NOT A STRATEGY.

      COULD YOU PLEASE SEND ME INSTRUCTIONS ABOUT HOW TO MODIFY THE CODE TO TRANSFORM THIS STRATEGY INTO AN INDICATOR?

      HOPEFULLY, I JUST NEED TO CHANGE THIS FUNCTIONS

      if (CrossAbove(smaFast, smaSlow, 1))
      ----> EnterLong();
      else if (CrossBelow(smaFast, smaSlow, 1))
      ----> EnterShort();
      }

      THANK YOU FOR YOUR SUPPORT
      MARCO

      Comment


        #4
        You are correct that this is all we need to change. You can change these lines to

        Code:
        Draw.VerticalLine(this, "CrossAbove" + CurrentBar, 0, Brushes.ForestGreen);
        and

        Code:
        Draw.VerticalLine(this, "CrossBelow" + CurrentBar, 0, Brushes.DarkRed);
        This said, since this is a Strategy, I have modified this slightly to turn it into an Indicator, and attached the result to this reply. I would like to invite you to study the differences between the code I am sending, and the code on your end, as this will make it easier for you in the future to generate code in the strategy builder and turn it into indicator code.

        You can install the code I am giving you to (My) Documents\NinjaTrader 8\bin\Custom\Indicators
        Attached Files
        Jessica P.NinjaTrader Customer Service

        Comment


          #5
          Great it works!
          Thank you very much, Jessica!
          In the future I would like to learn how to develop code, does Ninja trader offer material to study? Books videos etc?

          Thank you
          Kind regards

          Marco

          Comment


            #6
            If you would like to take on learning NinjaScript, we have a fully documented help guide which will help you get started. You will find language references to all of the methods and functions you will be using. You will also see a tutorial section which will help you create your first indicator and get you started with some of these concepts.
            a link to our help guide can be found below


            NT7: https://ninjatrader.com/support/help..._resources.htm


            NT8: http://ninjatrader.com/support/helpG..._resources.htm


            If, like me, you learn well from video, this video introducing the NinjaScript editor is an excellent resource,


            NT7: https://www.youtube.com/watch?v=K8v_...56536A44DD7105


            NT8: https://www.youtube.com/watch?v=T0Lt...dHqbaCU0MsgflK


            You will find reference samples online as well as some tips and tricks for both indicators and strategies:


            http://www.ninjatrader.com/support/f...splay.php?f=30
            http://www.ninjatrader.com/support/f...ead.php?t=3229


            These samples can be downloaded, installed and modified from NinjaTrader and hopefully serve as a good base for your custom works.


            There is a also a growing library of user submitted custom indicators (100+) and strategies that can be downloaded from our support form. Please look in the NinjaScript file sharing section of our support forum as you may find what you are looking for there:


            http://www.ninjatrader.com/support/f...splay.php?f=37


            Finally, the following link is to our help guide with an alphabetical reference list to all supported methods, properties, and objects that are used in NinjaScript.


            NT7: http://ninjatrader.com/support/helpG..._reference.htm


            NT8: http://ninjatrader.com/support/helpG..._reference.htm
            Jessica P.NinjaTrader Customer Service

            Comment


              #7
              Thank you very mutch for your support very appreciated!!

              Comment


                #8
                Originally posted by NinjaTrader_JessicaP View Post
                You are correct that this is all we need to change. You can change these lines to

                Code:
                Draw.VerticalLine(this, "CrossAbove" + CurrentBar, 0, Brushes.ForestGreen);
                and

                Code:
                Draw.VerticalLine(this, "CrossBelow" + CurrentBar, 0, Brushes.DarkRed);
                This said, since this is a Strategy, I have modified this slightly to turn it into an Indicator, and attached the result to this reply. I would like to invite you to study the differences between the code I am sending, and the code on your end, as this will make it easier for you in the future to generate code in the strategy builder and turn it into indicator code.

                You can install the code I am giving you to (My) Documents\NinjaTrader 8\bin\Custom\Indicators
                I have free version of NT7, would you be able to export this as an indicator so that i can import it and use it? THank you so much!

                Comment


                  #9
                  Hello teekay and thank you for writing in.


                  Since you are using NinjaTrader 7, and this is a NinjaTrader 8 tool, I have attached versions of this script for both platforms.


                  Whenever you find any "loose" .cs file on the internet you can turn it into an exported zip through the following process.


                  NinjaTrader 7
                  1. ) Copy your .cs file to one of :

                  * Documents\NinjaTrader 8\bin\Custom\Indicator for an indicator

                  * Documents\NinjaTrader 8\bin\Custom\Strategy for a strategy
                  2. ) In Ninja, File => Utilities => Export NinjaScript
                  3. ) Select your NinjaScript file on the left, and click the > button. Enter a filename. Click export.
                  4. ) Select yes and OK to any pop-ups that appear
                  Your exported NinjaScript file is now at Documents\NinjaTrader 7\bin\Custom\ExportNinjaScript


                  NinjaTrader 8
                  1. ) Copy your .cs file to one of :

                  * Documents\NinjaTrader 8\bin\Custom\Indicators for an indicator

                  * Documents\NinjaTrader 8\bin\Custom\Strategies for a strategy
                  2. ) In Ninja, Tools => Export => NinjaScript Add On
                  3. ) Click add in the lower right => Check all your NinjaScript => Press OK
                  4. ) Press Export => give your export zip a name => Click Save => click yes and OK to any prompts that appear
                  Your exported NinjaScript file is now at Documents\NinjaTrader 8\bin\Custom\ExportNinjaScript


                  Please let us know if there are any other ways we can help.
                  Attached Files
                  Jessica P.NinjaTrader Customer Service

                  Comment


                    #10
                    Excellent! Thank you so much!

                    Can I ask you for one more favor? Is it possible to have this indicator draw an arrow down on the the bar high where fast crosses below slow and vice versa? Maybe have an option to draw an arrow or a line? Also... possibly can the width of the line be adjusted as well as the size of the arrow?

                    I know I am asking for a lot but this would really help me in conversion from other platform as well, thank you so much Jessica!


                    Originally posted by NinjaTrader_JessicaP View Post
                    Hello teekay and thank you for writing in.


                    Since you are using NinjaTrader 7, and this is a NinjaTrader 8 tool, I have attached versions of this script for both platforms.


                    Whenever you find any "loose" .cs file on the internet you can turn it into an exported zip through the following process.


                    NinjaTrader 7
                    1. ) Copy your .cs file to one of :

                    * Documents\NinjaTrader 8\bin\Custom\Indicator for an indicator

                    * Documents\NinjaTrader 8\bin\Custom\Strategy for a strategy
                    2. ) In Ninja, File => Utilities => Export NinjaScript
                    3. ) Select your NinjaScript file on the left, and click the > button. Enter a filename. Click export.
                    4. ) Select yes and OK to any pop-ups that appear
                    Your exported NinjaScript file is now at Documents\NinjaTrader 7\bin\Custom\ExportNinjaScript


                    NinjaTrader 8
                    1. ) Copy your .cs file to one of :

                    * Documents\NinjaTrader 8\bin\Custom\Indicators for an indicator

                    * Documents\NinjaTrader 8\bin\Custom\Strategies for a strategy
                    2. ) In Ninja, Tools => Export => NinjaScript Add On
                    3. ) Click add in the lower right => Check all your NinjaScript => Press OK
                    4. ) Press Export => give your export zip a name => Click Save => click yes and OK to any prompts that appear
                    Your exported NinjaScript file is now at Documents\NinjaTrader 8\bin\Custom\ExportNinjaScript


                    Please let us know if there are any other ways we can help.

                    Comment


                      #11
                      Hello teekay,

                      Thank you for the reply.

                      You can certainly do this if you would like to. You can find various samples of the drawing tools and their syntax in the helpguide links here:

                      https://ninjatrader.com/support/help...t7/drawing.htm
                      https://ninjatrader.com/support/help...us/drawing.htm


                      To have more than one object, you can use a unique tag like the following:

                      Code:
                      "MyTag" + CurrentBar
                      In the scripts that have been provided previously, you could insert the drawing syntax into the conditions you want to visualize. It looks like in the previos sample it was coded to not have bodies for the conditions so you would need to add them if you wanted to do more than just draw a verticle line:

                      Code:
                      if (CrossAbove(emaFast, emaSlow, 1))
                      	DrawVerticalLine("CrossAbove" + CurrentBar, 0, Color.ForestGreen);
                      to

                      Code:
                      if (CrossAbove(emaFast, emaSlow, 1))
                      {
                          DrawVerticalLine("CrossAbove" + CurrentBar, 0, Color.ForestGreen);
                          // add more code for this condition here 
                      }
                      I look forward to being of further assistance.
                      JesseNinjaTrader Customer Service

                      Comment


                        #12
                        Originally posted by NinjaTrader_JessicaP View Post
                        Please let us know if there are any other ways we can help.
                        Yes, please

                        On the posted "Sample EMA Crossover" indicator (the one in this thread for NT8), would you please replace the "draw vertical lines" function with a sound alert ?
                        Last edited by jtrade; 09-26-2018, 12:13 AM.

                        Comment


                          #13
                          Hello jtrade,

                          Thank you for the post.

                          This is certainly something you can modify with the sample script.

                          The syntax to play a sound is very simple, you can find an example in the help guide here:
                          https://ninjatrader.com/support/help...tsub=playsound

                          Wherever you would like to play a sound, you would place that syntax. In case you wanted a sound instead of a line, you would just need to replace the drawing object syntax with the playsound syntax.

                          We also have a video that covers using the NinjaScript editor here: https://youtu.be/BA0W4ECyVdc



                          Please let me know if I may be of additional assistance.
                          JesseNinjaTrader Customer Service

                          Comment


                            #14
                            EMA with sound alert

                            Holy Toledo - it seems to work (will run Live tomorrow) !

                            Here is the cut copy paste result (NB. as I simply want an alert when price touches my EMA, I set the fast EMA value to (1) :
                            Attached Files
                            Last edited by jtrade; 09-26-2018, 11:49 AM.

                            Comment


                              #15
                              Hi Jessica P.

                              I used the file "SampleEMACrossover.NT8.zip" you attached at post #9 and Draw.ArrowUp, Draw.ArrowDown to make arrow indicator. It works good.
                              I can see two different EMA lines and the arrow after EMA crosses.
                              I would like to ask how to modify the script to hide both of two EMA lines, so that the indicator shows only arrow up or down signs without showing the EMA lines.

                              Thanks,

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Orden33, Today, 10:09 AM
                              1 response
                              4 views
                              0 likes
                              Last Post NinjaTrader_Jim  
                              Started by martyn73, Today, 10:18 AM
                              1 response
                              4 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by silverm3170, Today, 10:03 AM
                              1 response
                              1 view
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by diff24rac, 04-04-2018, 05:32 AM
                              6 responses
                              473 views
                              0 likes
                              Last Post fx.practic  
                              Started by gma17, Today, 08:58 AM
                              1 response
                              10 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Working...
                              X