Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

i would like to create a test strategy that alternated between long-short positions.

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

    i would like to create a test strategy that alternated between long-short positions.



    people with nt,



    regards.


    i have had several issues trying to get nt to trade my strategies automated. nt insists that the strategy and the position in my account are in synchronization but that's just not the case.


    in another inferior platform (ts), i was able to create a very simple strategy that would alternate between long and short positions if the bar number of the current bar could be exactly divided by 2 or not. i imagine such a strategy must also be easily achievable in nt but i have searched through the help guide and tried to use the strategy build tool without success. this kind of strategy is quite helpful when trying to determine whether orders are being correctly processed and sent or not.


    the following fragment is an amalgamation of ninjascript and the structure of this strategy in the other platform:

    Code:
    if mod(currentbar,2)=0 and lastbaronchart and barstatus( 1 ) = 2 then
    {
    EnterShort(2, Convert.ToInt32(Psize), @"sp01");
    }
    if mod(currentbar,2)=1 and lastbaronchart and barstatus( 1 ) = 2 then
    {
    EnterLong(2, Convert.ToInt32(Psize), @"lp01");
    }

    ¿how would it be possible to get nt to generate long or short orders at the close of each bar depending on whether its bar number is divisible by 2 or not?

    very well, thanks, regards.
    Last edited by rtwave; 10-03-2019, 12:14 AM.

    #2
    Hello,

    To find if the bar number is divisible by 2 in C#:

    if (CurrentBar % 2 == 0)
    {
    // trigger action
    }

    Below is a link to a forum post about synchronizing and start behavior.
    https://ninjatrader.com/support/foru...-open-position
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3


      Chelsea,



      thanks.


      the code you suggested works to perfection.


      i share this strategy in case it could be of use to anyone, if this strategy on a 10 second bar chart doesn't generate endless alternating positions then there's something wrong with the platform, internet connection, account, etc. if this strategy does generate a torrent of alternating positions but other strategies you are working on do not generate valid orders then the problem lies with your other strategies.


      Code:
      if (CurrentBars[0] <= BarsRequiredToTrade) return;
      
      // Set 1
      if (CurrentBar % 2 == 0)
      {
      EnterShort(Convert.ToInt32(DefaultQuantity), "");
      }
      
      // Set 2
      if (CurrentBar % 2 == 1)
      {
      EnterLong(Convert.ToInt32(DefaultQuantity), "");
      }
      Last edited by rtwave; 10-03-2019, 12:15 AM.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Stanfillirenfro, Today, 03:41 AM
      1 response
      11 views
      0 likes
      Last Post s.kinra
      by s.kinra
       
      Started by trader3000a, Today, 04:16 AM
      1 response
      2 views
      0 likes
      Last Post NinjaTrader_Marco  
      Started by itsthefriz, Yesterday, 09:16 PM
      0 responses
      6 views
      0 likes
      Last Post itsthefriz  
      Started by schmidtbc16, Yesterday, 03:36 PM
      1 response
      13 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by RT001, Yesterday, 03:25 PM
      2 responses
      20 views
      0 likes
      Last Post RT001
      by RT001
       
      Working...
      X