Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Position.MarketPosition == MarketPosition.Long (doesnt work)

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

    Position.MarketPosition == MarketPosition.Long (doesnt work)

    Im trying to write a code that says, if a current market position is open, do not create a contract. So the code has to wait and check till the old contract finishes, then enters a new one.

    I tried the following..."doesnt work)
    I also tried using just
    if (Position.MarketPosition == MarketPosition.Long)
    Still doesnt work.,....on a 1min chart, the code keeps buying multiple contracts...and you can see it increase....2,3.....4...
    I want to make sure it enters only one at a time...



    if (Position.MarketPosition == MarketPosition.Long || Position.MarketPosition)
    {
    if (MACD(12, 26, 9)[0] > MACD(12, 26, 9)[1]
    && MACD(12, 26, 9).Avg[0] > MACD(12, 26, 9).Avg[1])
    {
    AtmStrategyCreate(OrderAction.Buy, OrderType.Market, 0, 0,
    TimeInForce.Day, GetAtmStrategyUniqueId(), "myfill",
    GetAtmStrategyUniqueId());
    }
    }



    regards,

    #2
    Hi Dave, since you're working with the AtmStrategy methods here you would need to use the related GetAtmStrategyMarketPosition() as well for those checks -


    A complete workking example of those methods combined can be reviewed via the 'SampleAtmStrategy' script installed with NT per default.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Ive tried many ways.....strategy still keeps entering orders even when there is an existing open position.

      if (GetAtmStrategyMarketPosition("myfill") == MarketPosition.Long
      || GetAtmStrategyMarketPosition("myfill") == MarketPosition.Short)
      {dont enter}



      if (GetAtmStrategyMarketPosition("myfill") != (MarketPosition.Long | MarketPosition.Short))
      {enter}

      no matter what i do.... != == ||....doesnt work....strategy still enters market multiple times. I even tried MarketPosition.Flat (assuming Flat means not long or short)


      Full Code:

      if (GetAtmStrategyMarketPosition("myfill") == MarketPosition.Long
      || GetAtmStrategyMarketPosition("myfill") == MarketPosition.Short)
      {
      }
      else
      {
      if (MACD(12, 26, 9)[0] > MACD(12, 26, 9)[1]
      && MACD(12, 26, 9).Avg[0] > MACD(12, 26, 9).Avg[1])
      {
      AtmStrategyCreate(OrderAction.Buy, OrderType.Market, 0, 0,
      TimeInForce.Day, GetAtmStrategyUniqueId(), "myfill",
      GetAtmStrategyUniqueId());
      }

      // Condition set 2
      if (MACD(12, 26, 9)[0] < MACD(12, 26, 9)[1]
      && MACD(12, 26, 9).Avg[0] < MACD(12, 26, 9).Avg[1])
      {
      AtmStrategyCreate(OrderAction.Sell, OrderType.Market, 0, 0,
      TimeInForce.Day, GetAtmStrategyUniqueId(), "myfill",
      GetAtmStrategyUniqueId());
      }
      }

      Comment


        #4
        This seemed to work....messy code...but works

        if (MACD(12, 26, 9)[0] > MACD(12, 26, 9)[1]
        && MACD(12, 26, 9).Avg[0] > MACD(12, 26, 9).Avg[1]
        && GetAtmStrategyMarketPosition("myfill") == MarketPosition.Flat)
        {
        AtmStrategyCreate(OrderAction.Buy, OrderType.Market, 0, 0,
        TimeInForce.Day, GetAtmStrategyUniqueId(), "myfill",
        GetAtmStrategyUniqueId());
        }

        // Condition set 2
        if (MACD(12, 26, 9)[0] < MACD(12, 26, 9)[1]
        && MACD(12, 26, 9).Avg[0] < MACD(12, 26, 9).Avg[1]
        && GetAtmStrategyMarketPosition("myfill") == MarketPosition.Flat)
        {
        AtmStrategyCreate(OrderAction.Sell, OrderType.Market, 0, 0,
        TimeInForce.Day, GetAtmStrategyUniqueId(), "myfill",
        GetAtmStrategyUniqueId());
        }

        Comment


          #5
          Originally posted by davedxb View Post
          This seemed to work....messy code...but works

          if (MACD(12, 26, 9)[0] > MACD(12, 26, 9)[1]
          && MACD(12, 26, 9).Avg[0] > MACD(12, 26, 9).Avg[1]
          && GetAtmStrategyMarketPosition("myfill") == MarketPosition.Flat)
          {
          AtmStrategyCreate(OrderAction.Buy, OrderType.Market, 0, 0,
          TimeInForce.Day, GetAtmStrategyUniqueId(), "myfill",
          GetAtmStrategyUniqueId());
          }

          // Condition set 2
          if (MACD(12, 26, 9)[0] < MACD(12, 26, 9)[1]
          && MACD(12, 26, 9).Avg[0] < MACD(12, 26, 9).Avg[1]
          && GetAtmStrategyMarketPosition("myfill") == MarketPosition.Flat)
          {
          AtmStrategyCreate(OrderAction.Sell, OrderType.Market, 0, 0,
          TimeInForce.Day, GetAtmStrategyUniqueId(), "myfill",
          GetAtmStrategyUniqueId());
          }

          No does not work....just looked at it....entered 2 contracts after a couple of minutes

          Comment


            #6
            Dave, please check into the example we ship with NT, namely the 'SampleAtmStrategy' - it would show how to setup the general structure, which would include checks and reset for the order and atmStrategyId.
            BertrandNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Belfortbucks, Today, 09:29 PM
            0 responses
            3 views
            0 likes
            Last Post Belfortbucks  
            Started by zstheorist, Today, 07:52 PM
            0 responses
            7 views
            0 likes
            Last Post zstheorist  
            Started by pmachiraju, 11-01-2023, 04:46 AM
            8 responses
            150 views
            0 likes
            Last Post rehmans
            by rehmans
             
            Started by mattbsea, Today, 05:44 PM
            0 responses
            6 views
            0 likes
            Last Post mattbsea  
            Started by RideMe, 04-07-2024, 04:54 PM
            6 responses
            33 views
            0 likes
            Last Post RideMe
            by RideMe
             
            Working...
            X