Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Enter Order when Indicator pattern found

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

    Enter Order when Indicator pattern found

    hi,
    I would like to enter order in my strategy script when an indicator pattern is found in an indicator script. How do I do this? Below is part of the indicator script. I would like to EnterLong() on my strategy script when (CurrentBar - barback != myBarUp)
    thank you for your help!



    Code:
    #region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.DrawingTools;
    //using System.Speech.AudioFormat; 
    #endregion
    
    //This namespace holds Indicators in this folder and is required. Do not change it. 
    namespace NinjaTrader.NinjaScript.Indicators
    {
        public class NinjaPriceAction : Indicator
        {
            private int     barsback;
            private double     prevhigh;
            private double     prevlow;
            private double     curhigh;
            private double     curlow;
            private double     offset;
            private double     curATR;
            private double     toffset;
            private ATR     myATR;
            private Swing     mySwing;
            private double     tOffset;        
            private int        myBarUp, myBarDown;
    
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                                    = @"Labels the swing points";
                    Name                                        = "NinjaPriceAction";
                    Calculate                                    = Calculate.OnBarClose;
                    IsOverlay                                    = true;
                    DisplayInDataBox                            = true;
                    DrawOnPricePanel                            = true;
                    DrawHorizontalGridLines                        = true;
                    DrawVerticalGridLines                        = true;
                    PaintPriceMarkers                            = true;
                    ScaleJustification                            = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                    //Disable this property if your indicator requires custom values that cumulate with each new market data event. 
                    //See Help Guide for additional information.
                    IsSuspendedWhileInactive                    = true;
                    Strength                    = 3;
                    TextOffset                    = 3;
                    LookBack                    = 50;
                    DTBStrength                    = 15;
                    TextFont                    = new NinjaTrader.Gui.Tools.SimpleFont("Arial", 12); 
                    DBcolor                        = Brushes.Gold;
                    DTcolor                        = Brushes.Gold;
                    HHcolor                        = Brushes.Green;
                    HLcolor                        = Brushes.White;
                    LLcolor                        = Brushes.Red;
                    LHcolor                        = Brushes.White;
                }
                else if (State == State.DataLoaded)
                {
                    myATR = ATR(14);            
                    mySwing = Swing(Strength);
                    tOffset = TextOffset * TickSize;
                }            
            }
    
            protected override void OnBarUpdate()
            {
    
                if (CurrentBar < LookBack + 1) return;
    
                barsback = mySwing.SwingHighBar(0,2,LookBack);
    
                if (barsback == -1) 
                    return; 
    
                prevhigh = mySwing.SwingHigh[barsback]; 
    
                barsback = mySwing.SwingHighBar(0,1,LookBack);
    
                if (barsback == -1) 
                    return; 
    
                curhigh = mySwing.SwingHigh[barsback]; 
    
                curATR    = myATR[barsback];    
                offset    = curATR * DTBStrength / 100;
    
                if (curhigh < prevhigh + offset && curhigh > prevhigh - offset && CurrentBar - barsback != myBarUp)
                {
                    myBarUp = CurrentBar - barsback;
                    Draw.Text(this, "DT"+CurrentBar, true, "DT", barsback, High[barsback] + tOffset, 0, DTcolor, 
                        TextFont, TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 0);    
    
                }
                else if (curhigh > prevhigh && CurrentBar - barsback != myBarUp)
                {
                    myBarUp = CurrentBar - barsback;
                    Draw.Text(this, "HH"+CurrentBar, true, "HH", barsback, High[barsback] + tOffset, 0, HHcolor,
                        TextFont, TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 0);
                }
                else if [COLOR=#00FF00](CurrentBar - barsback != myBarUp)[/COLOR]
                {
                    myBarUp = CurrentBar - barsback;
                    Draw.Text(this, "LH"+CurrentBar, true, "LH",barsback, High[barsback] + tOffset, 0,  LHcolor, 
                        TextFont, TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 0);
    
                }

    #2
    The code would look like this:



    if ( YOUR CODE HERE )
    {
    EnterLong(Convert.ToInt32(666), @"LongEntry");
    EnterShort(Convert.ToInt32(666), @"ShortEntry");
    }



    Just use the Strategy Builder to help you with the code. You use the Strategy Builder with the guidelines, you compile it and look at the resulted code. You copy the code to your own code and you continue like this until you have what you need! There are few type of orders, so, I suggest you look at the Strategy Builder first. This type of orders above are just examples (market orders). It maybe not fit your need. And as you may understand, I gave 2 types of orders. In real life, just one is required for each condition.


    Have a nice weekend!

    Comment


      #3
      Thanks Bricolico. I know how to do that in the strategy but my goal is to enter an order when the indicator triggers "LH" and I don't know how to implement it. the code for the indicator is included.

      Comment


        #4
        Hi daicacon, thanks for your question.

        Unfortunately, the support team can not create custom code. This is so we can provide the same high level of service for all of our clients. So that members of the community can help, you should describe in as much detail as possible what you want your condition to be (what indicators need to be used and what values must reach a certain criteria).

        Kind regards.
        Chris L.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by lorem, 04-25-2024, 09:18 AM
        18 responses
        75 views
        0 likes
        Last Post lorem
        by lorem
         
        Started by joselube001, 05-10-2024, 12:17 PM
        4 responses
        20 views
        0 likes
        Last Post NinjaTrader_Erick  
        Started by DawnTreader, 05-08-2024, 05:58 PM
        21 responses
        81 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by doihaveto13, Today, 12:46 PM
        2 responses
        4 views
        0 likes
        Last Post doihaveto13  
        Started by Vitamite, Today, 12:48 PM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X