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 TheWhiteDragon, 01-21-2019, 12:44 PM
        4 responses
        541 views
        0 likes
        Last Post PaulMohn  
        Started by GLFX005, Today, 03:23 AM
        0 responses
        3 views
        0 likes
        Last Post GLFX005
        by GLFX005
         
        Started by XXtrader, Yesterday, 11:30 PM
        2 responses
        11 views
        0 likes
        Last Post XXtrader  
        Started by Waxavi, Today, 02:10 AM
        0 responses
        7 views
        0 likes
        Last Post Waxavi
        by Waxavi
         
        Started by TradeForge, Today, 02:09 AM
        0 responses
        14 views
        0 likes
        Last Post TradeForge  
        Working...
        X