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 waltFX, Today, 04:28 PM
            0 responses
            6 views
            0 likes
            Last Post waltFX
            by waltFX
             
            Started by dajunuka, Today, 02:41 PM
            2 responses
            14 views
            0 likes
            Last Post dajunuka  
            Started by connorlmarble, Yesterday, 08:25 PM
            5 responses
            33 views
            0 likes
            Last Post NinjaTrader_LuisH  
            Started by quebequer, Today, 06:51 AM
            3 responses
            23 views
            0 likes
            Last Post NinjaTrader_LuisH  
            Started by Curerious, Today, 03:05 PM
            0 responses
            6 views
            0 likes
            Last Post Curerious  
            Working...
            X