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 funk10101, Today, 12:02 AM
        1 response
        10 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Started by GLFX005, Today, 03:23 AM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_Erick  
        Started by nandhumca, Yesterday, 03:41 PM
        1 response
        12 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by The_Sec, Yesterday, 03:37 PM
        1 response
        11 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by vecnopus, Today, 06:15 AM
        0 responses
        1 view
        0 likes
        Last Post vecnopus  
        Working...
        X