Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Overfill Proof Skelton Code

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

    Overfill Proof Skelton Code

    Hi Guys,

    I am new to the forum and to NT. Love this tool. I am writing a simple scripts to make sure that there is no overfill errors. I am not having just two conditions of enterShort() or EnterLong(). On top of that I will have ExitLong() and ExitShort(). Can you please help me with the skeleton of the code that can accomplish this. Never mind about the actual condition. I am trying this but it does not seem to be working. Thanks,

    -----

    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    /// <summary>
    /// Enter the description of your strategy here
    /// </summary>
    [Description("Enter the description of your strategy here")]
    public class Sha****est : Strategy
    {
    #region Variables
    // Wizard generated variables
    private int varZero = 0; // Default setting for VarZero
    // 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()
    {
    Add(macdShashi(12, 26, 20));
    Add(macdShashi(12, 26, 20));
    Add(macdShashi(12, 26, 20));
    Add(macdShashi(12, 26, 20));
    EntriesPerDirection = 2;
    EntryHandling = EntryHandling.AllEntries;
    CalculateOnBarClose = false;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    private IOrder entryOrder = null;
    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (macdShashi(12, 26, 20).Diff[0] < VarZero && entryOrder == null)
    entryOrder = SubmitOrder(0, OrderAction.SellShort, OrderType.Market, 1, 0, 0, "", "Enter Short");

    // Condition set 2
    if (macdShashi(12, 26, 20)[0] > macdShashi(12, 26, 20)[1] && entryOrder == null)
    entryOrder = SubmitOrder(0, OrderAction.BuyToCover, OrderType.Market, 1, 0, 0, "", "Exit Short");
    Last edited by traderbhai; 02-19-2016, 08:34 AM.

    #2
    Hello,

    Thank you for the question.

    What specifically is not working for you? I would be unable to say from the partial sample and description, if you can provide further detail on exactly what is not or is occurring that should not, it would be helpful to find the answer.


    Please let me know if I may be of further assistance.

    Comment


      #3
      Originally posted by NinjaTrader_Jesse View Post
      Hello,

      Thank you for the question.

      What specifically is not working for you? I would be unable to say from the partial sample and description, if you can provide further detail on exactly what is not or is occurring that should not, it would be helpful to find the answer.


      Please let me know if I may be of further assistance.
      Hi Jesse,

      Thanks for the response. What I am doing is having four conditions in my strategy. One for each conditions. But it is giving me over fill error because I am not doing the simple enterlong() and entershort() which takes care of the issues of overfill I am told. Attached is the whole code. All I want from you is what should I add to the code to make sure that overfills do not happen. I was chatting with Chelsea through emails and she asked me to do something. But my scripts is not running in backtest mode. If you can point me to a place where there is a code that handles that I will appreciate that. I am sure I am not the first person to see this error.

      I just need directions so that I can add relevant pieces to my code. Something that handles overfill without the conditions. I will handle the condition by my self.

      Thanks again for your help.
      Attached Files

      Comment


        #4
        Originally posted by traderbhai View Post
        Hi Jesse,

        Thanks for the response. What I am doing is having four conditions in my strategy. One for each conditions. But it is giving me over fill error because I am not doing the simple enterlong() and entershort() which takes care of the issues of overfill I am told. Attached is the whole code. All I want from you is what should I add to the code to make sure that overfills do not happen. I was chatting with Chelsea through emails and she asked me to do something. But my scripts is not running in backtest mode. If you can point me to a place where there is a code that handles that I will appreciate that. I am sure I am not the first person to see this error.

        I just need directions so that I can add relevant pieces to my code. Something that handles overfill without the conditions. I will handle the condition by my self.

        Thanks again for your help.
        You are using unmanaged code, so if you want to handle overfills yourself, tell the code so.

        Ref: http://ninjatrader.com/support/helpG...reoverfill.htm

        Heed the warnings! You must know what you are doing. It is not the kind of thing that I would have tackled when your statement: "I am new to ... NT." was true of me.

        Comment


          #5
          Originally posted by koganam View Post
          You are using unmanaged code, so if you want to handle overfills yourself, tell the code so.

          Ref: http://ninjatrader.com/support/helpG...reoverfill.htm

          Heed the warnings! You must know what you are doing. It is not the kind of thing that I would have tackled when your statement: "I am new to ... NT." was true of me.
          New to NT but not new to programming. Just need some background. Thanks for the support. Appreciate the help.

          Comment


            #6
            Hello traderbhai,

            Thank you for your patience.

            Please take a look at the video I created for you at the following link: http://screencast.com/t/aclEHsf2kI

            Comment


              #7
              And below is the code from the video:
              Code:
                          // Condition set 1
                          if (MACDwma(12, 26, 9).Diff[0] < VarZero
                              && MACD(12, 26, 9).Diff[0] < VarZero)
                          {
                              EnterShort(DefaultQuantity, "");
                          }
              
                          // Condition set 2
                          if (MACDwma(12, 26, 9).Diff[0] > VarZero
                              && MACD(12, 26, 9).Diff[0] > VarZero)
                          {
                              EnterLong(DefaultQuantity, "");
                          }
              
                          // Condition set 3
                          if (CrossAbove(MACDwma(12, 26, 9).Avg, MACDwma(12, 26, 9), 1)
              				&& MACDwma(12, 26, 9).Diff[0] >= VarZero
              				&& MACD(12, 26, 9).Diff[0] >= VarZero)
                          {
                              ExitLong("", "");
                          }
              
                          // Condition set 4
                          if (CrossBelow(MACDwma(12, 26, 9).Avg, MACDwma(12, 26, 9), 1)
              				&& MACDwma(12, 26, 9).Diff[0] <= VarZero
              				&& MACD(12, 26, 9).Diff[0] <= VarZero)
                          {
                              ExitShort("", "");
                          }

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by argusthome, 03-08-2026, 10:06 AM
              0 responses
              71 views
              0 likes
              Last Post argusthome  
              Started by NabilKhattabi, 03-06-2026, 11:18 AM
              0 responses
              42 views
              0 likes
              Last Post NabilKhattabi  
              Started by Deep42, 03-06-2026, 12:28 AM
              0 responses
              25 views
              0 likes
              Last Post Deep42
              by Deep42
               
              Started by TheRealMorford, 03-05-2026, 06:15 PM
              0 responses
              28 views
              0 likes
              Last Post TheRealMorford  
              Started by Mindset, 02-28-2026, 06:16 AM
              0 responses
              56 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Working...
              X