Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to stop Longs or Shorts depending on MarketPosition

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

    How to stop Longs or Shorts depending on MarketPosition

    I would like to insert code for the strategy to only take Longs when in a long position and only take shorts while in a short position. If Flat, take either trade.
    I took an attempt at it but it's not working. Can anyone tell me why this isn't working or make suggested code of how to do it?

    // Condition set for Longs
    { if (Position.MarketPosition != MarketPosition.Flat)
    {if (Indicator().Plot0[0] == 1)
    {
    EnterLong(1, "LongEntry");
    }
    }
    else
    if (Position.MarketPosition != MarketPosition.Long)
    {if (Indicator().Plot0[0] == 1)
    {
    EnterLong(1, "LongEntry");
    }
    }
    }


    // Condition set for Shorts
    {if (Position.MarketPosition != MarketPosition.Flat)
    {if (Indicator().Plot0[0] == -1)
    {
    EnterShort(1, "ShortEntry");
    }
    }
    else
    if (Position.MarketPosition != MarketPosition.Short)
    {if (Indicator().Plot0[0] == -1)
    {
    EnterShort(1, "ShortEntry");
    }

    #2
    Hello,

    Thanks for the forum post.

    When you say it is not working what specifically is not working?

    Have you tried adding in Print statements to debug your strategy?

    Let me know if I can be of further assistance.

    Comment


      #3
      The strategy will close out long positions and enter short, provided a short signal is given. If already short and a long signal is given, it closes the short position and enters long.

      Comment


        #4
        Hello,

        Please add print() statement to debug your NinjaScript strategy.

        Please see this guide on how to do this.



        I look forward to assisting you further.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Mestor, 03-10-2023, 01:50 AM
        16 responses
        389 views
        0 likes
        Last Post z.franck  
        Started by rtwave, 04-12-2024, 09:30 AM
        4 responses
        31 views
        0 likes
        Last Post rtwave
        by rtwave
         
        Started by yertle, Yesterday, 08:38 AM
        7 responses
        29 views
        0 likes
        Last Post yertle
        by yertle
         
        Started by bmartz, 03-12-2024, 06:12 AM
        2 responses
        23 views
        0 likes
        Last Post bmartz
        by bmartz
         
        Started by funk10101, Today, 12:02 AM
        0 responses
        7 views
        0 likes
        Last Post funk10101  
        Working...
        X