Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Slope of EMA of Prices

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

    Slope of EMA of Prices

    I have been successfully trading using ThinkOrSwim for years and I like it a lot... but I just started using NT8 and I think I can do even more "damage" to the markets with NT8 because it has even more flexbility and "power" than ToS.

    I am new to c# and NinjaScript and furiously trying to learn it... I will eventually but the learning curve is there.

    I'm trying to convert my "stuff" from ToS to NT8 and I'm getting close but one thing I cannot sort out is what I talk about below.

    The code below (below the NinjaScript) simply plots the slope of the EMA of the prices and also plots an AVG of the slope itself. It's in ThinkScript. It works, have used it for years.

    I tried converting the code below (below the NinjaScript snippet, which I put in as a reference) with no luck.

    I tried using slope() and slope() must be outputting something different than what I need as it looks nothing like what I have on my ThinkOrSwim charts with the code below.

    I got the slope() code from a NT8 staffer... and like I said, it works in that it shows something but not what I was expecting so it must be outputting the slope differently... because even when the EMA is sloping up... sometimes the code I was given is below 0... and the spikes it has don't coincide with the charts.

    This is the NinjaScript I was given:
    protected override void OnStateChange(){
    if (State == State.SetDefaults){
    AddPlot(Brushes.Goldenrod, "MyPlot");
    }
    }

    protected override void OnBarUpdate()
    { double m = Slope(EMA(14), 10, 0);
    Values[0][0] = m;
    }


    Anyways, can anyone convert the ThinkScript code below to NinjaScript. It's not that long... and I would think an expert in NinjaScript could do it quickly... and the ThinkScript is pretty straight forward and would be easy to understand for a coder, even if you don't know thinkscript... hopefully one day I can get that good in NS as well.

    THE THINKSCRIPT TO CONVERT TO NINJASCRIPT:

    input slopelength = 7;
    input slopeprice = OHLC4;
    input slopeaverageType = AverageType.WEIGHTED;
    def slopeavg = MovingAverage(slopeaverageType, slopeprice, slopelength);
    def height = slopeavg - slopeavg[1];

    input slopeEMAlength = 21;
    input slopeEMAprice = OHLC4;
    input slopeEMAaverageType = AverageType.WEIGHTED;

    plot slope = Atan(height/slopelength) * 180 / Double.Pi;
    plot slopeEMAavg = MovingAverage(slopeEMAaverageType, slope, slopeEMAlength);


    Basically, the end result that I'm looking for is where it plots the slope of the EMA and the AVG of the Slope... and if the Price EMA is heading up, the plot will be above 0 for the slope... now the slope may head up or down, depending on how strong the EMA is going up or down but as long as the EMA is heading higher... even if kind of flat, it will be higher than 0... and I paint the slope line green on my charts.

    And if the EMA is heading down - ie. the slope of the EMA is going down (because prices are going down)... the slope plot will be below 0 and I paint it red on my charts (I left out the thinkscript coloring of the lines).

    I also have an average of the actual slope itself and I plot it in the same panel as the slope.

    Thanks in advance if someone can help me out.

    I looked around on NT support and just found old scripts that didn't work in NT8... or didn't produce the desired result.

    Based on my initial research, I don't think slope() is the right thing to use, I think a custom indicator has to be made... as slope() outputs the slope in a different format (for lack of a better term) than what I'm looking for.

    #2
    Hello TicksBandit,

    In the support department at NinjaTrader we do not create, debug, or modify code for our clients. This is so that we can maintain a high level of service for all of our clients.

    You can also contact a professional NinjaScript Consultants who would be eager to create or modify this script at your request or assist you with your script. Please let me know if you would like our business development follow up with you with a list of professional NinjaScript Consultants who would be happy to create this script or any others at your request.

    Please let us know if you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Maybe another user can help out.

      Comment


        #4
        slope

        I code it using NT8 8.0.2.0 as my broker doesn't support higher version. I think you should be able to run it without any code change. I paste TOS code next to NT8 code so you can compare them.


        Originally posted by TicksBandit View Post
        I have been successfully trading using ThinkOrSwim for years and I like it a lot... but I just started using NT8 and I think I can do even more "damage" to the markets with NT8 because it has even more flexbility and "power" than ToS.

        I am new to c# and NinjaScript and furiously trying to learn it... I will eventually but the learning curve is there.

        I'm trying to convert my "stuff" from ToS to NT8 and I'm getting close but one thing I cannot sort out is what I talk about below.

        The code below (below the NinjaScript) simply plots the slope of the EMA of the prices and also plots an AVG of the slope itself. It's in ThinkScript. It works, have used it for years.

        I tried converting the code below (below the NinjaScript snippet, which I put in as a reference) with no luck.

        I tried using slope() and slope() must be outputting something different than what I need as it looks nothing like what I have on my ThinkOrSwim charts with the code below.

        I got the slope() code from a NT8 staffer... and like I said, it works in that it shows something but not what I was expecting so it must be outputting the slope differently... because even when the EMA is sloping up... sometimes the code I was given is below 0... and the spikes it has don't coincide with the charts.

        This is the NinjaScript I was given:
        protected override void OnStateChange(){
        if (State == State.SetDefaults){
        AddPlot(Brushes.Goldenrod, "MyPlot");
        }
        }

        protected override void OnBarUpdate()
        { double m = Slope(EMA(14), 10, 0);
        Values[0][0] = m;
        }


        Anyways, can anyone convert the ThinkScript code below to NinjaScript. It's not that long... and I would think an expert in NinjaScript could do it quickly... and the ThinkScript is pretty straight forward and would be easy to understand for a coder, even if you don't know thinkscript... hopefully one day I can get that good in NS as well.

        THE THINKSCRIPT TO CONVERT TO NINJASCRIPT:

        input slopelength = 7;
        input slopeprice = OHLC4;
        input slopeaverageType = AverageType.WEIGHTED;
        def slopeavg = MovingAverage(slopeaverageType, slopeprice, slopelength);
        def height = slopeavg - slopeavg[1];

        input slopeEMAlength = 21;
        input slopeEMAprice = OHLC4;
        input slopeEMAaverageType = AverageType.WEIGHTED;

        plot slope = Atan(height/slopelength) * 180 / Double.Pi;
        plot slopeEMAavg = MovingAverage(slopeEMAaverageType, slope, slopeEMAlength);


        Basically, the end result that I'm looking for is where it plots the slope of the EMA and the AVG of the Slope... and if the Price EMA is heading up, the plot will be above 0 for the slope... now the slope may head up or down, depending on how strong the EMA is going up or down but as long as the EMA is heading higher... even if kind of flat, it will be higher than 0... and I paint the slope line green on my charts.

        And if the EMA is heading down - ie. the slope of the EMA is going down (because prices are going down)... the slope plot will be below 0 and I paint it red on my charts (I left out the thinkscript coloring of the lines).

        I also have an average of the actual slope itself and I plot it in the same panel as the slope.

        Thanks in advance if someone can help me out.

        I looked around on NT support and just found old scripts that didn't work in NT8... or didn't produce the desired result.

        Based on my initial research, I don't think slope() is the right thing to use, I think a custom indicator has to be made... as slope() outputs the slope in a different format (for lack of a better term) than what I'm looking for.
        Attached Files

        Comment


          #5
          You win the Internet today! Thanks a bunch... quick question... do you know how to paint the line green when the slope is above 0 and red when it's below?

          Now, if I can only solve why when I do a strategy and I have a chart up with the strategy on it... the signal and the entry is a bar late.... even when the signal is basically when this price area breaks go long. It should do it on the same bar... not signal on the next bar and then go long on the bar after that.

          If I can sort that out, I will buy NT8 and open up a Futures account with them.

          Comment


            #6
            Hello TicksBandit,

            Thank you for your note.

            I would suggest first writing this in the strategy builder. To do this go to Control Center>Tools>Strategy builder>next next until you are on the conditions and actions screen. Then click add to define your first condition.

            For the condition, you will select slope which is under the misc folder, then for an operator you will select > and on the right side you’ll select numeric value 0 which is also under the MISC folder.

            For the action you would click add and select draw line.

            You could then click the view code button if you wanted to copy this code to another script.




            The reason for the trade being executed on the next bar is due to running the strategy with calculate set to OnBarClose. So when the bar closes and the condition is true, the strategy then executes on the open of the next bar. Please see the Calculate section of our helpguide,


            Please let us know if you need further assistance.
            Last edited by NinjaTrader_AlanP; 11-20-2017, 08:33 AM.
            Alan P.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by TicksBandit View Post
              You win the Internet today! Thanks a bunch... quick question... do you know how to paint the line green when the slope is above 0 and red when it's below?

              ....
              1) add zero line
              AddPlot(Brushes.Orange, "SLOPE");
              AddPlot(Brushes.SaddleBrown, "SLOPEAVG");
              AddLine(Brushes.Black, 0, "Zero"); // <==========add this line
              }

              2) paint SLOPE line, add 4 more lines
              //plot slope = Atan(height/slopelength) * 180 / Double.Pi;
              SLOPE[0] = Math.Atan(height/_length) * 180 / Math.PI;
              if (SLOPE[0] < 0) // <=====================add 4 following lines
              PlotBrushes[0][0] = Brushes.Red;
              else
              PlotBrushes[0][0] = Brushes.Green;
              //plot slopeEMAavg = MovingAverage(slopeEMAaverageType, slope, slopeEMAlength);
              SLOPEAVG[0] = SMA(SLOPE,_length2)[0];
              }

              Comment


                #8
                Alan, I have everything... the indicators and the strategy set to calculate on tick... ie. Calculate.OnEachTick I have no idea on why it puts the trade on the next bar. It shouldn't. Any suggestions? Also, is delayed intraday data, like from the $55 Kinetick the same thing as historical data when it comes to Calculate.OnEachTick in that with historical data there is just OHLC when it comes to pricing and no tick data?

                Comment


                  #9
                  Hello TicksBandit,

                  The back part of this is understanding that all historical data process is done as if CalculateOnBarClose = true regardless of user setting to false. False only applies when using live/replay data. Adding a 1 tick series historically brings back the processing to every tick.

                  If you run your strategy on the simulated data feed with Calculate set to OnEachTick, you will see that in real time orders are sent on the current bar.

                  If you wish your historical executions to be on the same bar you will need to add a secondary tick series. I provided a link to this in the last reply.

                  Please let us know if you need further assistance.
                  Alan P.NinjaTrader Customer Service

                  Comment


                    #10
                    I saw the link you sent and don't understand how it's done.. hence my continued being lost on it. The link you sent doesn't really explain it... it just has a link to DL the code... which, I'm still learning to do... and doesn't appear you can use the Strategy builder to send an order to a 2nd time series.

                    Comment


                      #11
                      Also, an update. I just ran my strategy on the simulated datafeed and it's still entering on the next bar... and not entering on the same bar.

                      Comment


                        #12
                        Hello TicksBandit,

                        Without the strategy I am unable to test on my end.

                        If you’d like to send a copy of the strategy you’re running, I can take a look and see if anything jumps out.

                        To export a NinjaScript from NinjaTrader 8 do the following:
                        From the Control Center window select Tools -> Export -> NinjaScript...
                        Click Add>Select the indicator>OK>Export.
                        Then attach that file you saved; under My Docs>NT8>Bin>Custom>Select the downloaded .zip file.

                        Please let us know if you need further assistance.
                        Alan P.NinjaTrader Customer Service

                        Comment


                          #13
                          Can I do it in private... ie. via email or something? I rather not put it out in public. I have several strategies that this same thing occurs on. I can send you a generic one with the same concept/issues.

                          Comment


                            #14
                            Hello TicksBandit,

                            Please send an email to platformsupport[at]ninjatrader[dot]com with Attn: Alan P in the Subject line. Also within the email please include a link to this thread as well as the strategy.

                            I look forward to your reply.
                            Alan P.NinjaTrader Customer Service

                            Comment


                              #15
                              Just sent... it's long winded but I wanted to be very detailed to save both of us time and frustration.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by JagelBagel, Today, 02:16 PM
                              2 responses
                              11 views
                              0 likes
                              Last Post JagelBagel  
                              Started by oliverupnext, 01-16-2024, 03:44 PM
                              4 responses
                              100 views
                              0 likes
                              Last Post NinjaTrader_Eduardo  
                              Started by henry131013, 08-16-2023, 08:48 PM
                              3 responses
                              283 views
                              0 likes
                              Last Post Robelius  
                              Started by notenufftime, Today, 09:36 AM
                              5 responses
                              32 views
                              0 likes
                              Last Post notenufftime  
                              Started by Marklhc1988, 04-19-2023, 11:11 AM
                              14 responses
                              825 views
                              1 like
                              Last Post NinjaTrader_Kimberly  
                              Working...
                              X