Announcement

Collapse
No announcement yet.

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.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        38 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        124 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        64 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        41 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        46 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X