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

command for long and short

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

    command for long and short

    hi
    i use
    EnterLong(1,"long");​
    for long but its not work.
    which command set for long and short and stop loss and profit target?

    #2
    Hello f.saeidi,

    Thank you for your post.

    EnterLong() does generate a buy order to enter a long position. You can use EnterShort() to enter a short position.



    The help guide page below lists the order methods for the managed approach:



    You can use SetProfitTarget() and SetStopLoss() as well.





    Please let us know if we can assist further.
    Gaby V.NinjaTrader Customer Service

    Comment


      #3
      pls look below script:

      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.Indicators;
      using NinjaTrader.NinjaScript.DrawingTools;
      #endregion

      //This namespace holds Strategies in this folder and is required. Do not change it.
      namespace NinjaTrader.NinjaScript.Strategies
      {
      public class RsiStrategy : Strategy
      {

      double ThirtySecOpen;
      double ThirtySecClose;
      double ThirtySecBid;




      double oneMinOpen;
      double oneMinClose;
      double oneMinBid;

      double fiveMinOpen;
      double fiveMinClose;
      double fiveMinBid;

      double fifteenMinOpen;
      double fifteenMinClose;
      double fifteenMinBid;


      double thirtyMinOpen;
      double thirtyMinClose;
      double thirtyMinBid;


      double sixtyMinOpen;
      double sixtyMinClose;
      double sixtyMinBid;


      double twohundredMinOpen;
      double twohundredMinClose;
      double twohundredMinBid;


      double dailyMinOpen;
      double dailyMinClose;
      double dailyMinBid;




      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Description = @"Enter the description for your new custom Strategy here.";
      Name = "RsiStrategy";
      Calculate = Calculate.OnPriceChange;
      EntriesPerDirection = 1;
      EntryHandling = EntryHandling.AllEntries;
      IsExitOnSessionCloseStrategy = true;
      ExitOnSessionCloseSeconds = 30;
      IsFillLimitOnTouch = false;
      MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
      OrderFillResolution = OrderFillResolution.Standard;
      Slippage = 0;
      StartBehavior = StartBehavior.WaitUntilFlat;
      TimeInForce = TimeInForce.Gtc;
      TraceOrders = false;
      RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
      StopTargetHandling = StopTargetHandling.PerEntryExecution;
      BarsRequiredToTrade = 20;

      // Disable this property for performance gains in Strategy Analyzer optimizations
      // See the Help Guide for additional information
      IsInstantiatedOnEachOptimizationIteration = true;
      Qt = 1;
      Sl = 6;
      Pt = 28;
      StartTime = DateTime.Parse("09:30", System.Globalization.CultureInfo.InvariantCulture) ;
      EndTime = DateTime.Parse("23:00", System.Globalization.CultureInfo.InvariantCulture) ;
      }
      else if (State == State.Configure)
      {
      SetTrailStop(@"long", CalculationMode.Ticks, Sl, false);
      SetTrailStop(@"short", CalculationMode.Ticks, Sl, false);

      AddDataSeries(null, BarsPeriodType.Second,30);
      AddDataSeries(null,BarsPeriodType.Minute,1);
      AddDataSeries(null,BarsPeriodType.Minute,5);
      AddDataSeries(null,BarsPeriodType.Minute,15);
      AddDataSeries(null,BarsPeriodType.Minute,30);
      AddDataSeries(null,BarsPeriodType.Minute,60);
      AddDataSeries(null,BarsPeriodType.Minute,240);
      AddDataSeries(null, BarsPeriodType.Day,1);

      }
      }

      protected override void OnBarUpdate()
      {

      if (CurrentBars[0] < 5|| CurrentBars[1] < 5 )

      return;

      bool noTrades=Position.MarketPosition == MarketPosition.Flat;


      if (BarsInProgress ==1)


      {


      if (CrossAbove(RSI(25,3),60,1) && noTrades )

      {


      EnterLong(1, "long");

      }


      }
      }

      region Properties
      [NinjaScriptProperty]
      [Range(1, int.MaxValue)]
      [Display(Name="Qt", Order=1, GroupName="Parameters")]
      public int Qt
      { get; set; }

      [NinjaScriptProperty]
      [Range(1, int.MaxValue)]
      [Display(Name="Sl", Order=2, GroupName="Parameters")]
      public int Sl
      { get; set; }

      [NinjaScriptProperty]
      [Range(1, int.MaxValue)]
      [Display(Name="Pt", Order=3, GroupName="Parameters")]
      public int Pt
      { get; set; }

      [NinjaScriptProperty]
      [PropertyEditor("NinjaTrader.Gui.Tools.TimeEditorKe y")]
      [Display(Name="StartTime", Order=4, GroupName="Parameters")]
      public DateTime StartTime
      { get; set; }

      [NinjaScriptProperty]
      [PropertyEditor("NinjaTrader.Gui.Tools.TimeEditorKe y")]
      [Display(Name="EndTime", Order=5, GroupName="Parameters")]
      public DateTime EndTime
      { get; set; }
      #endregion

      }
      }


      why its not work for buy??

      Comment


        #4
        Hello,

        Thank you for your response.

        If the strategy is applied to a chart, is there data with new bars appearing on the chart the Strategy is applied to?

        Is the strategy showing as enabled on the Strategies tab of the Control Center?

        Importantly, are there errors appearing on the Log tab of the Control Center?


        Try testing the Sample MA Crossover strategy included with NinjaTrader on the same chart or Strategy Analyzer using the same instrument, bar type, interval, and date range.

        Do you see results with the Sample MA Crossover strategy? (This would confirm for us data is available and the issue is with the logic in the custom script)


        If the strategy is getting data and the strategy is enabled or a backtest is run with no errors in the Log tab of the Control Center, and the Sample MA Crossover is returning results, then would likely indicate the logic conditions in the custom strategy did not evaluate as true or orders are being ignored or cancelled.

        In order to better understand how the code is working, it will be necessary to use Print to see how the conditions are evaluating and enable TraceOrders to see if orders are being submitted, ignored, rejected, or cancelled.

        Below is a link to a forum post that demonstrates using prints to understand behavior and includes a link to a video recorded using the Strategy Builder to add prints.


        Enable TraceOrders, print the time of the bar and all values used in the conditions that submit entry orders. Include labels for all values and comparison operators.

        Let me know if you need any assistance creating a print or enabling TraceOrders.

        Save the output from the output window to a text file and provide this with your reply.

        I'll be happy to assist with analyzing the output.​
        Gaby V.NinjaTrader Customer Service

        Comment


          #5
          plz give me your desire code for long and sell?
          i mean your example that work without make with strategy builder.

          Comment


            #6
            Hello,

            There is no specific desired code for using EnterLong() or EnterShort().

            I recommend taking a look at the SampleMACrossover script included in NinjaTrader, which demonstrates using EnterLong() and EnterShort() with CrossAbove and CrossBelow conditions.

            Please let us know if you have any further questions.
            Gaby V.NinjaTrader Customer Service

            Comment


              #7
              when i make with strategy builder long and short position work well but its not work when i enter (enter long and enter short) command.
              main problem in on this command .

              Comment


                #8
                plz give me this ma cross enter long link.

                Comment


                  #9
                  as your advise i saw ma cross:

                  // Only enter if at least 10 bars has passed since our last entry
                  if ( CrossAbove(SMA(10), SMA(20), 1))
                  EnterLong(1,"SMA Cross Entry");​

                  again its not work.
                  i dont want to use strategy builder.i need to enter direct command.
                  what is your advise?
                  its seems again we have serious problem with ninja script.
                  Last edited by f.saeidi; 04-24-2024, 01:57 PM.

                  Comment


                    #10
                    I find what problem is.
                    Your format for enter long and enter short is not complete.
                    I guess nt8 manual pdf is weak and you need to upgrade with complete and practical commands.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by PhillT, 04-19-2024, 02:16 PM
                    3 responses
                    14 views
                    0 likes
                    Last Post mangel2000  
                    Started by TraderBCL, Today, 02:37 AM
                    0 responses
                    1 view
                    0 likes
                    Last Post TraderBCL  
                    Started by mangel2000, Today, 02:23 AM
                    0 responses
                    5 views
                    0 likes
                    Last Post mangel2000  
                    Started by mangel2000, Today, 01:30 AM
                    0 responses
                    14 views
                    0 likes
                    Last Post mangel2000  
                    Started by Doxxxx, Today, 01:24 AM
                    0 responses
                    5 views
                    0 likes
                    Last Post Doxxxx
                    by Doxxxx
                     
                    Working...
                    X