Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Simple strategy

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

    Simple strategy

    Hello
    I would like to create a simple strategy with a stop loss and profit target at the strategy wizard that it is triggered just when I click the buttons BUY MARKET or SELL MARKET.
    I don't want anything else in the strategy. And I would like to use the strategy wizard to create since I would like to have the strategy available at the Strategies section in the CONTROL CENTER, rather than have to use the ATM Strategy in Chart Trader since this creates conflicts with other active strategies.

    How can I do that? I know how to create the options at the Stop loss and profit targets: section, but which options would I have to choose from the sections:
    When the following condictions are true:, and Do the following:, to make it work?

    Thanks very much
    Alberto

    #2
    Hello Alberto,

    Thank you for writing in. Unfortunately there is no way to do this with the strategy wizard and it would be somewhat complicated using regular NinjaScript. This is because the Chart Trader buttons are not available to NinjaScript strategies, you would have to create a new set of buttons which your strategy could receive events from. This is outside of the documented code that is available for NinjaTrader 7. If you are interested in having a 3rd party develop this for you, please let me know and I will have our business development team contact you with further information.

    Thank you in advance.
    Michael M.NinjaTrader Quality Assurance

    Comment


      #3
      Hello Michael
      And , instead of clicking on the BUY SELL buttons, would it be possible to set it up in a way that when price reaches a stop limit placed manually on the chart, the strategy is triggered?
      Thanks very much
      Alberto

      Comment


        #4
        Hello Alberto Moreno,
        While you still cannot do this with the strategy wizard, if you unlock your code, you can add in something like the following:
        Code:
        protected override void Initialize()
        {
            CalculateOnBarClose = false;
        }
        
        protected override void OnBarUpdate()
        {
        	foreach(Order o in Account.Orders)
        	{
        		if(o.LimitPrice != null && o.StopPrice != null && o.LimitPrice != 0 && o.StopPrice != 0) //If we have a stop limit order
        		{
        			if(Close[0] <= o.StopPrice) //If market price is less than or equal to the stop price of the stop limit order
        			{
        				//Run the strategy
        				EnterLong();
        			}
        		}
        	}
        }
        The issue with this is that in addition to your strategy running, your stop limit order would also fill so you would potentially be in two positions.

        I would recommend instead, creating a drawing tool on the chart such as a line and then running your strategy if the price crosses the drawing tool. A basic example of how to have your strategy check against a line you have placed on the chart can be found in this indicator I developed called AlertLines. I have attached it to my post.

        Please let me know if you have any questions or if I may be of further assistance.
        Attached Files
        Michael M.NinjaTrader Quality Assurance

        Comment


          #5
          Hello Michael

          Yes that works but I think you only gave to me the code to enter long. Could you share it to be able to enter both long or short depending on the stop limit I placed?

          Also when I tried to import the Alert indicator, a message came up saying that there were coding errors within a ninja script that needed to be resolved, or I wouldn't be able to import. I deleted the strategy with the code you shared and I was able to import the indicator.

          Also if you could point me to some link where I could get information about how this indicator works it would be great. I have imported it but I don't know what to do with it with the options available at the indicator.


          Thanks very much
          Alberto

          Comment


            #6
            Hello Alberto Moreno,

            How to use the indicator I provided:

            1) Install it

            2) Add it to your chart (it is called AlertLines).

            Explanation of parameters:

            AboveTagName: Each line you draw that you want to sound the alarm if the price crosses above it has to contain this word in its tag name. You can edit a lines tag by right clicking on it and selecting Properties, then the Data tab (Remember each tag has to be unique).

            AlertName: The name of the sound file in your ProgramFiles (x86)\NinjaTrader 7\sounds folder. You need to include the .wav at the end.

            AlertPriority: The alert priority level, 1 is low, 2 is medium (Default), 3 is high.

            BelowTagName: Each line you draw that you want to sound the alarm if the price crosses below it, has to contain this word in its tag name. You can edit a lines tag by right clicking on it and selecting Properties, then the Data tab (Remember each tag has to be unique).

            RearmTime: The amount of time (in seconds) it takes for the alarm to rearm before sounding again

            3) Create a line on your chart. The line has to have its end point in front of the current price for it to work correctly (I believe this is how you were doing it already). You can access this section of your chart by selecting your chart and scrolling up with your mouse wheel.

            4) Right click on your line and select Properties -> Data tab and change the Tag Name to match what you set up in the indicator properties depending on whether you want to check if the price crosses below or above it.

            Please Note: This indicator is only designed to work with regular lines and only lines which were drawn by you (this will not work with lines drawn by other indicators).

            A quick video on the same: http://screencast.com/t/5VrOMnaeUfW

            As far as the code I posted earlier not going short, here are the options:
            1) You can either have the code I provided go long or short, but not both. This is because there is no way to determine what side of the market the stop was originally placed on from a strategy
            2) You can use a different order type for short (Such as stop market, or a limit order). In this case you would have something like the following:
            Code:
            protected override void Initialize()
            {
                CalculateOnBarClose = false;
            }
            
            protected override void OnBarUpdate()
            {
            	foreach(Order o in Account.Orders)
            	{
            		if(o.LimitPrice != null && o.StopPrice != null && o.LimitPrice != 0 && o.StopPrice != 0) //If we have a stop limit order
            		{
            			if(Close[0] <= o.StopPrice) //If market price is less than or equal to the stop price of the stop limit order
            			{
            				//Run the long strategy
            				EnterLong();
            			}
            		}
                            else if(o.LimitPrice != null && o.LimitPrice != 0 && (o.StopPrice == null || o.StopPrice == 0)) //If we have a limit order
                            {
                                    if(Close[0] >= o.LimitPrice) //If the market price is greater than or equal to the limit price of the limit order
                                    {
                                            //Run the short strategy
                                            EnterShort();
                                    }
                            }
            	}
            }
            3) Again, I would recommend instead of the above methods, to review my AlertLines indicator to see how you can make your strategy check the chart for lines and to then determine if the price crosses above or below those lines to submit the orders.

            Please let me know if I may be of further assistance.
            Michael M.NinjaTrader Quality Assurance

            Comment


              #7
              Hello Michael
              I am having an issue in my live account with the strategies that now don't trigger. I deleted the strategy where I placed the code and restarted ninjatrader but the issue happens again. I can't copy now cause I don't want to trigger a buy to experiment in my live account, but it said something like the strategy cannot be triggered and it canceled itself....

              If I place manual order there is no problem and I can trade with no problems but any strategy that I have now cancels itself out. How can I solve the issue?

              This is the first time it happens something like this.

              Thanks very much
              Alberto

              Comment


                #8
                Hello Alberto Moreno,

                Thanks for your post.

                To diagnose the issue, please send your log and trace files in.
                You can do this by going to the Control Center-> Help-> Mail to Platform Support.
                Please reference the following ticket number in the body of the email: Atten Paul, forum post: Simple strategy.
                Paul H.NinjaTrader Customer Service

                Comment


                  #9
                  Hello
                  How do I get log and trace files in?
                  Thank you

                  Comment


                    #10
                    Hello Alberto Moreno,

                    Thanks for your reply.

                    By using the Help>Mail to Platformsupport, the log and trace files should be automatically selected. If you scroll down in that you will see several check boxes, the first one is for the Log and Trace files and it should be checked.

                    Alternatively you can e-mail platformsupport directly and attach only the most recent log and trace files.

                    You will find the log file on your PC in the (My) Documents > NinjaTrader 7 > Log folder.

                    The log file will be named "log.20151130.txt"
                    You will find the trace file on your PC in the (My) Documents > NinjaTrader 7 > Trace folder.

                    The trace file will be named "trace.20151130.txt"

                    These then would need to be e-mailed to platformsupport[at]ninjatrader[dot]com with the same subject line of Atten Paul, forurm thread: simple strategy.

                    Please do not post the files in the forum as they contain sensitive information about your system/account.
                    Paul H.NinjaTrader Customer Service

                    Comment


                      #11
                      Ah ok
                      I already sent the email. Thanks

                      Comment


                        #12
                        adding email alert

                        would like to add an email alert too your indicator with no success. please see some of the options that were used. i did create a bool in the region
                        Code:
                        okToEmail = true;
                        Code:
                        {
                        						IHorizontalLine hline = (IHorizontalLine) draw;
                        						double lineValue = hline.Y;
                        						if(draw.Tag.ToLower().Contains(aboveTagName.ToLower()) && CrossAbove(Close, lineValue, 1)&& okToEmail)
                        						{
                        							Alert(draw.Tag, p, "Price Crossed Above " + draw.Tag, alertName, rearmTime, Color.White, Color.Black);
                        							///SendMail("email1", "email2", "RESISTANCE", "");
                        							///okToEmail = false;
                        							
                        						//if(draw.Tag.ToLower().Contains(aboveTagName.ToLower()) && Close[0]<= lineValue && okToEmail)
                        							//{okToEmail = true;}
                        						}
                        						if(draw.Tag.ToLower().Contains(belowTagName.ToLower()) && CrossBelow(Close, lineValue, 1)&& okToEmail)
                        						{
                        							Alert(draw.Tag, p, "Price Crossed Below " + draw.Tag, alertName, rearmTime, Color.White, Color.Black);
                        							///SendMail("email1", "email2", "SUPPORT", "");
                        							///okToEmail = false;
                        						//if(draw.Tag.ToLower().Contains(aboveTagName.ToLower()) && Close[0]>= lineValue && okToEmail)
                        							//{okToEmail = true;}	
                        						}
                        						//ResetAlert("draw.Tag");
                        						//ResetAlerts();
                        					}

                        Comment


                          #13
                          Hello duck_CA,

                          Thanks for your post.

                          I'm not sure if this is a duplicate of another post you had regarding e-mails that I, members sledge and outsource responded to. Please advise if you are still in need of assistance in this issue.
                          Paul H.NinjaTrader Customer Service

                          Comment


                            #14
                            Code:
                             #region Variables
                            			private Priority p = Priority.Medium;
                            			private int alertpriority = 2;
                            			private string alertName = "Alert1.wav";
                            			private int rearmTime = 1;
                            			private string aboveTagName = "above", belowTagName = "below";
                            		    private int	lastSignal = 0;
                            		    private bool okToEmail = true;
                            //			private string sendEMail = "@gmail.com";
                                    #endregion
                                    protected override void Initialize()
                                    {
                                        Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
                                        Overlay				= true;
                            			CalculateOnBarClose = false;
                            			switch(alertpriority)
                            			{
                            				case 1: p = Priority.Low; break;
                            				case 2: p = Priority.Medium; break;
                            				case 3: p = Priority.High; break;
                            			}
                                    }
                                    protected override void OnBarUpdate()
                                    {
                            			if(!Historical)
                            			{
                            				foreach(IDrawObject draw in DrawObjects)
                            				{
                            					if(draw.UserDrawn == true && draw.DrawType == DrawType.Line)
                            					{
                            						ILine line = (ILine) draw;
                            						double lineValue = Math.Max(line.StartY, line.EndY);
                            						if(DateTime.Compare(Time[0], line.StartTime) >= 0 && DateTime.Compare(Time[0], line.EndTime) <= 0)
                            						{
                            							if(draw.Tag.ToLower().Contains(aboveTagName.ToLower()) && CrossAbove(Close, lineValue, 1))
                            							{
                            								Alert(draw.Tag, p, "Price Crossed Above " + draw.Tag, alertName, rearmTime, Color.White, Color.Black);
                            							}
                            							if(draw.Tag.ToLower().Contains(belowTagName.ToLower()) && CrossBelow(Close, lineValue, 1))
                            							{
                            								Alert(draw.Tag, p, "Price Crossed Below " + draw.Tag, alertName, rearmTime, Color.White, Color.Black);
                            							}
                            						}
                            					}
                            					else if(draw.UserDrawn == true && draw.DrawType == DrawType.HorizontalLine)
                            					{
                            						IHorizontalLine hline = (IHorizontalLine) draw;
                            						double lineValue = hline.Y;
                            						if(draw.Tag.ToLower().Contains(aboveTagName.ToLower()) && CrossAbove(Close, lineValue, 1))
                            						{
                            							Alert(draw.Tag, p, lineValue + " Crossed from " + draw.Tag, alertName, rearmTime, Color.White, Color.Black);
                            						}/*
                            						if(lastSignal < CurrentBar)
                            						{	SendMail("@yahoo.com", "@txt.att.net", "RESISTANCE", "");
                            							lastSignal = CurrentBar;
                            							okToEmail = false;
                            						}
                            						ResetAlerts();
                            */
                            						//if(draw.Tag.ToLower().Contains(aboveTagName.ToLower()) && Close[0]<= lineValue && okToEmail)
                            							//{okToEmail = true;}
                            						
                            						if(draw.Tag.ToLower().Contains(belowTagName.ToLower()) && CrossBelow(Close, lineValue, 1))
                            						{
                            							Alert(draw.Tag, p, lineValue + " Crossed from " + draw.Tag, alertName, rearmTime, Color.White, Color.Black);
                            						}/*
                            						if(lastSignal < CurrentBar)
                            						{	[email protected]", "@txt.att.net", "SUPPORT", "");
                            							lastSignal = CurrentBar;
                            							okToEmail = false;
                            						}*/	
                            //						//if(draw.Tag.ToLower().Contains(aboveTagName.ToLower()) && Close[0]>= lineValue && okToEmail)
                            //							//{okToEmail = true;}	
                            					}
                            				}
                            			}
                                    }
                            hi Paul,

                            I have the following code that are now uncommented in the code above with undesirable results.
                            seems that i need some type of reset function for continued alerts. to clarify, one alert per 5 minute bar is sufficient.
                            thanks for any suggestions.

                            on a side note, is there a way to have a price marker overlay over all indicators at all times?

                            thannks,
                            jason

                            Comment


                              #15
                              Hi Jason,

                              What I recommend is that you add print statements where you would expect to send e-mail to see if that section of code is getting hit but the e-mail is not being sent.
                              Paul H.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by AaronKoRn, Yesterday, 09:49 PM
                              0 responses
                              11 views
                              0 likes
                              Last Post AaronKoRn  
                              Started by carnitron, Yesterday, 08:42 PM
                              0 responses
                              10 views
                              0 likes
                              Last Post carnitron  
                              Started by strategist007, Yesterday, 07:51 PM
                              0 responses
                              12 views
                              0 likes
                              Last Post strategist007  
                              Started by StockTrader88, 03-06-2021, 08:58 AM
                              44 responses
                              3,982 views
                              3 likes
                              Last Post jhudas88  
                              Started by rbeckmann05, Yesterday, 06:48 PM
                              0 responses
                              10 views
                              0 likes
                              Last Post rbeckmann05  
                              Working...
                              X