Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Automated Random Trading Strategy 1 Tick Chart problem .

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

    Automated Random Trading Strategy 1 Tick Chart problem .

    Well , i like randomness but markets are not random ? ...

    I use a unique way to ramdommize my entries and now i wish to scalp with it . I take the crypto service provider from C# .

    My ninjascript NT7 is fine but i have problems with overfills . For example :


    //__________________________________________________ __________________________________________________ _______________________________
    // __________________________________________________ __________________________________________________ ______________________________
    // Cryptographic Random Number Generator (CRNG)
    byte[] random = new Byte[1];
    RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
    rng.GetBytes(random); // The array is now filled with cryptographically strong random bytes.
    //__________________________________________________ __________________



    // Condition set 1
    if (Position.MarketPosition == MarketPosition.Flat
    && (random[0] < 127) && (BarsSinceExit() > 7 || BarsSinceExit() == -1))
    {
    EnterLong(C, "Alt Norte !");
    }

    // Condition set 2
    if (Position.MarketPosition == MarketPosition.Flat
    && (random[0] >= 127) && (BarsSinceExit() > 7 || BarsSinceExit() == -1))
    {
    EnterShort(C, "Baix Norte !");
    }


    This piece of code could be changed so overfill would be fixed ?

    #2
    Hello Jvferreira,

    An overfill is categorized as when an order returns a "Filled" or "PartFilled" state after the order was already marked for cancellation.

    When using Market orders there is basically one situation that can cause this error. Likely what is happening is an EnterLong and an EnterShort are being called on the same bar at the same time. This will cause an over fill.

    May I confirm that this is the only code in your script?

    I recommend that you print the time of the bar in each condition. When you get the overfill, check to see if the time of the bar appears more than once in the output. If it does, then multiple conditions are being triggered at the same time and there could be both an EnterLong and EnterShort called on the same bar which will cause this error.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello , Chelsea .

      Here's my complete NT7 ninjascript :
      [QUOTE]
      #region Using declarations
      using System;
      using System.Security.Cryptography;
      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>
      /// 1 Second
      /// </summary>
      [Description("1 Second ")]
      public class Norte : Strategy
      {
      #region Variables
      // Wizard generated variables
      private int c = 1; // Default setting for C
      private int tS = 6; // Default setting for TS
      // 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()
      {
      SetTrailStop("", CalculationMode.Ticks, TS, false);

      CalculateOnBarClose = true;
      }

      /// <summary>
      /// Called on each bar update event (incoming tick)
      /// </summary>
      protected override void OnBarUpdate()
      {

      //__________________________________________________ __________________________________________________ _______________________________
      // __________________________________________________ __________________________________________________ ______________________________
      // Cryptographic Random Number Generator (CRNG)
      byte[] random = new Byte[1];
      RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
      rng.GetBytes(random); // The array is now filled with cryptographically strong random bytes.
      //__________________________________________________ __________________



      // Condition set 1
      if (Position.MarketPosition == MarketPosition.Flat
      && (random[0] < 127) && (BarsSinceExit() > 70 || BarsSinceExit() == -1))
      {
      EnterLong(C, "Alt Norte !");
      }

      // Condition set 2
      if (Position.MarketPosition == MarketPosition.Flat
      && (random[0] >= 127) && (BarsSinceExit() > 70 || BarsSinceExit() == -1))
      {
      EnterShort(C, "Baix Norte !");
      }
      }

      Comment


        #4
        Hello Jvferreira,

        May I confirm that you have added a print of the Time of the bar in all conditions that place orders?

        Please include the output of that print with your post.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by wzgy0920, 04-20-2024, 06:09 PM
        2 responses
        26 views
        0 likes
        Last Post wzgy0920  
        Started by wzgy0920, 02-22-2024, 01:11 AM
        5 responses
        32 views
        0 likes
        Last Post wzgy0920  
        Started by wzgy0920, Yesterday, 09:53 PM
        2 responses
        49 views
        0 likes
        Last Post wzgy0920  
        Started by Kensonprib, 04-28-2021, 10:11 AM
        5 responses
        192 views
        0 likes
        Last Post Hasadafa  
        Started by GussJ, 03-04-2020, 03:11 PM
        11 responses
        3,234 views
        0 likes
        Last Post xiinteractive  
        Working...
        X