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 rocketman7, Today, 02:12 AM
        0 responses
        3 views
        0 likes
        Last Post rocketman7  
        Started by dustydbayer, Today, 01:59 AM
        0 responses
        1 view
        0 likes
        Last Post dustydbayer  
        Started by inanazsocial, Today, 01:15 AM
        0 responses
        3 views
        0 likes
        Last Post inanazsocial  
        Started by trilliantrader, 04-18-2024, 08:16 AM
        5 responses
        22 views
        0 likes
        Last Post trilliantrader  
        Started by Davidtowleii, Today, 12:15 AM
        0 responses
        3 views
        0 likes
        Last Post Davidtowleii  
        Working...
        X