Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Proper use of Position.MarketPosition

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

    Proper use of Position.MarketPosition

    Hi,

    a quick (and probably stupid question), how would this strategy behave? would it switch from long to short, and viceverse also if I use the Position.MarketPosition check?

    Code:
    if (Position.MarketPosition == MarketPosition.Flat && CrossAbove(Close,SMA(20),1)
    {
    EnterLong();
    }
    if (Position.MarketPosition == MarketPosition.Flat && CrossBelow(Close,SMA(20),1)
    {
    EnterShort();
    }
    thanks

    #2
    Hi Sburtt.
    I think if you re-write you code as below, it becomes a bit more obvious what will happen.
    1) It will do nothing until you are flat.
    2) It will then do nothing until one of the Cross conditions is true.
    3) When one of them becomes true it will enter in the corresponding direction.
    4) It will do nothing =more till you are flat again


    if (Position.MarketPosition == MarketPosition.Flat)
    {
    if (CrossAbove(Close,SMA(20),1)
    {
    EnterLong();
    }
    if (CrossBelow(Close,SMA(20),1)
    {
    EnterShort();
    }
    }

    Comment


      #3
      Originally posted by DaveS View Post
      Hi Sburtt.
      I think if you re-write you code as below, it becomes a bit more obvious what will happen.
      1) It will do nothing until you are flat.
      2) It will then do nothing until one of the Cross conditions is true.
      3) When one of them becomes true it will enter in the corresponding direction.
      4) It will do nothing =more till you are flat again


      if (Position.MarketPosition == MarketPosition.Flat)
      {
      if (CrossAbove(Close,SMA(20),1)
      {
      EnterLong();
      }
      if (CrossBelow(Close,SMA(20),1)
      {
      EnterShort();
      }
      }
      Dave thanks for your reply, this confirms what i was thinking, basically if I want is to switch from long to short on the SMA cross over, I don't think this will happen with the script you mentioned above. thanks

      Comment


        #4
        What you have written -

        if (Position.MarketPosition == MarketPosition.Flat)
        {
        if (CrossAbove(Close,SMA(20),1)
        {
        EnterLong();
        }
        if (CrossBelow(Close,SMA(20),1)
        {
        EnterShort();
        }
        }

        Will get you in initally.
        If you want to reverse at the crossovers then add -

        if (Position.MarketPosition == MarketPosition.Short)
        {
        if (CrossAbove(Close,SMA(20),1)
        {
        EnterLong();
        }
        }

        if (Position.MarketPosition == MarketPosition.Long)
        {
        if (CrossBelow(Close,SMA(20),1)
        {
        EnterShort();
        }
        }


        NT does a lotot of the work for you, you don't need to close positions to reverse, just enter in the opposite direction and NT will close the old position for you

        What you must do next is decide how to do the final exit.

        Comment


          #5
          Wouldn't it be easier to use simply:
          Code:
          if (CrossAbove(Close,SMA(20),1)
          {
          EnterLong();
          }
          if (CrossBelow(Close,SMA(20),1)
          {
          EnterShort();
          }
          }
          Without checking the maketposition? What arenthe risks with doing this?

          Comment


            #6
            Originally posted by sburtt View Post
            Wouldn't it be easier to use simply:
            Code:
            if (CrossAbove(Close,SMA(20),1)
            {
            EnterLong();
            }
            if (CrossBelow(Close,SMA(20),1)
            {
            EnterShort();
            }
            }
            Without checking the maketposition? What arenthe risks with doing this?
            No risks that I can think of, MarketPosition is often useful in more complcated scripts, but you don't really need it at all. The code in the quote would do the whole job I think.

            Comment


              #7
              Thanks dave

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              647 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              367 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              108 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              571 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              573 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X