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

Ninja script and atm implementation

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

    Ninja script and atm implementation

    Hello,

    i am looking to have my ATM strategy to be triggered by a Ninja Script, which is very simple.
    Go long or short on cross above of two EMA's and exit long or short on a cross of the opposite direction.

    when the position is open i need this position to be managed by my ATM strategy. and whatever shares are left open to be closed by NT on the opposite cross.

    So far the script i have triggers on the crossover, and the ATM strategy i need. But it does not close the position in the opposite cross. Please have a look at my script below and advise me how to rectify this problem

    Your time and efforts are greatly appreciated. PLEASE let me know.

    Thanks

    NT SCRIPT:

    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Indicator;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Strategy;
    #endregion

    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    /// <summary>
    /// ENTER LONG & EXIT LONG ONLY
    /// </summary>
    [Description("ENTER LONG & EXIT LONG ONLY")]
    public class LONG : Strategy
    {
    #region Variables
    // Wizard generated variables
    private int fAST = 15; // Default setting for FAST
    private int sLOW = 35; // Default setting for SLOW
    // User defined variables (add any user defined variables below)
    #endregion

    /// <summary>
    /// This method is used to configure the strategy and is called once before any strategy method is called.
    /// </summary>
    protected override void Initialize()
    {

    CalculateOnBarClose = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (CrossAbove(EMA(15), EMA(35), 1))
    {
    //string a = "b12345";
    string a = GetAtmStrategyUniqueId();
    string orderId = GetAtmStrategyUniqueId();
    AtmStrategyCreate(Action.Buy, OrderType.Market, 0, 0,TimeInForce.Day, orderId, "TNA 50 SHARES",GetAtmStrategyUniqueId());
    Alert("CROSS ABOVE", Priority.High, "TNA ENTER LONG", "", 0, Color.White, Color.Black);
    }

    // Condition set 2
    //if (atmStrategyId.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyId) == Cbi.MarketPosition.Flat)
    if (CrossBelow(EMA(15), EMA(35), 1))
    {
    //AtmStrategyClose(a);
    //AtmStrategyChangeStopTarget(0, EMA(15)[0], "STOP1",GetAtmStrategyUniqueId() );
    //ExitLong();
    Alert("EXIT LONG", Priority.High, "TNA EXIT LONG", "", 0, Color.White, Color.Black);
    }
    }

    #region Properties
    [Description("")]
    [Category("Parameters")]
    public int FAST
    {
    get { return fAST; }
    set { fAST = Math.Max(18, value); }
    }

    [Description("")]
    [Category("Parameters")]
    public int SLOW
    {
    get { return sLOW; }
    set { sLOW = Math.Max(25, value); }
    }
    #endregion
    }
    }

    #2
    Hello demit177,

    Thanks for the post and welcome to the NinjaTrader forums. With a ATM strategy in NinjaScript, you don't have the convenience of the standard strategy management of orders / positions. In a standard NinjaScript strategy, you write only an Enter method and this can automatically take care of the reversal with appropriate position management.

    Unfortunately this is not a simple one line fix. With an ATM strategy, this reversal handling must be custom coded. You close one atm strategy and open another but have to duplicate the same structure used in the first ATM Strategy for the second ATM strategy. You also need some mechanism for communicating a successful ATM strategy close to the next ATM strategy opening.

    To create this you will have to be familiar with all parts of the sample, and work with the ATM Strategy methods here:
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Unrealized P/L with ATM in NinjaScript

      I have realized a strategy in Ninja script inserting the education AtmStrategyCreate. I have activated the strategy hooking her/it to an account simulated named Account. Don't I succeed in the relative columns the P/L for which motive? Thanks.

      Comment


        #4
        Hi there, unfortunately I am unable to understand your request. What are you trying to do here? By looking at your post's subject line it looks like you're trying to find unrealized P/L of a ATM strategy? Please see this help guide page if that is true - http://www.ninjatrader.com/support/h...izedprofit.htm.

        You can also take a look at the sample ATM NinjaScript strategy in NinjaTrader at Tools -> Edit NinjaScript -> SampleAtmStrategy.
        AustinNinjaTrader Customer Service

        Comment


          #5
          Re - Unrealized P/L with ATM in NinjaScript

          I have activated the strategy in the panel of the control center. In the panel there are the columns related to the P/L: unrealized, realized, account... where the values are visualized in real-time of the profits related to the select account. Using really the strategy that you have pointed out me SampleAtmStrategy I don't see the results in the columns above you name. Any is the P/L reached with the strategy zero it always appears as gives.

          Comment


            #6
            onurbbruno, correct the ATM's would not report in the Strategies even if called from a NinjaScript strategy.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              I didn't know him/it. To see the P/L I will use the superdom or the output in the strategy with ninja script. Thanks for the speed of the answer.

              Comment


                #8
                This subject is spot on. I want to do the same thing, but when I enter the market, I want a short ATM strategy and a long ATM strategy to drop in at the same time on the same tick price.

                I can manually apply both, but if I manually do it, I can't get the entries on the same tick price. That's the only thing I need help on.

                Thanks for you support.

                Comment


                  #9
                  Hello OathMark1,

                  Thank you for writing in. I have replied to your other thread, however if I am misunderstanding your request and you simply want to submit two ATM strategies at the same time, please feel free to check our the SampleAtmStrategy script included with NinjaTrader. You can access it by going to Tools -> Edit NinjaScript -> Strategy -> SampleAtmStrategy. You would want to use that as a template.

                  You can find the definitions for different NinjaScript methods in our help guide here: http://ninjatrader.com/support/helpG..._reference.htm

                  You can find the ATM strategy methods here: http://ninjatrader.com/support/helpG...gy_methods.htm

                  If you have any specific questions with the code, please let me know.
                  Michael M.NinjaTrader Quality Assurance

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Segwin, 05-07-2018, 02:15 PM
                  10 responses
                  1,769 views
                  0 likes
                  Last Post Leafcutter  
                  Started by Rapine Heihei, 04-23-2024, 07:51 PM
                  2 responses
                  30 views
                  0 likes
                  Last Post Max238
                  by Max238
                   
                  Started by Shansen, 08-30-2019, 10:18 PM
                  24 responses
                  943 views
                  0 likes
                  Last Post spwizard  
                  Started by Max238, Today, 01:28 AM
                  0 responses
                  10 views
                  0 likes
                  Last Post Max238
                  by Max238
                   
                  Started by rocketman7, Today, 01:00 AM
                  0 responses
                  7 views
                  0 likes
                  Last Post rocketman7  
                  Working...
                  X