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.

    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.

            Comment

            Latest Posts

            Collapse

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