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 ZenCortexCLICK, Today, 04:58 AM
        0 responses
        5 views
        0 likes
        Last Post ZenCortexCLICK  
        Started by sidlercom80, 10-28-2023, 08:49 AM
        172 responses
        2,281 views
        0 likes
        Last Post sidlercom80  
        Started by Irukandji, Yesterday, 02:53 AM
        2 responses
        18 views
        0 likes
        Last Post Irukandji  
        Started by adeelshahzad, Today, 03:54 AM
        0 responses
        8 views
        0 likes
        Last Post adeelshahzad  
        Started by Barry Milan, Yesterday, 10:35 PM
        3 responses
        13 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Working...
        X