Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Position.MarketPosition Clarification

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

    #16
    Do i need to change marketposition for a different boolean variable?
    I put these additional exit conditions in the onbarupdate method and it won't compile:


    ***********************************


    if(C1ose[0] < Low[1] && Position.MarketPosition == MarketPosition.Long)
    {
    ExitLong(DefaultQuantity,"BULL TRIGGER");
    }
    if(Close[0] > High[1] && Position.MarketPosition == MarketPosition.Short)
    {
    ExitShort(DefaultQuantity,"BEAR TRIGGER");
    }


    ***********************************

    Comment


      #17
      Hello gordongekko,

      Thank you for your response.

      Please provide the compile error descriptions when you report these.

      In your code you provided you appear to have a typo where Close is listed as C1ose. Perhaps this is the error.

      Please let me know if you have any questions.

      Comment


        #18
        It was an error about not being able to convert a string to an int so i removed the string portion which is probably not needed for that anyway but I'm not sure.

        This code compiled but i have not tested it yet:



        if(Close[0] < Low[1] && Position.MarketPosition == MarketPosition.Long)
        {
        ExitLong(DefaultQuantity);
        }
        if(Close[0] > High[1] && Position.MarketPosition == MarketPosition.Short)
        {
        ExitShort(DefaultQuantity);
        }

        ERROR CODE:

        The best overloaded method match for 'NinjaTrader.NinjaScript.StrategyBase.ExitLong(str ing, string)' has some invalid arguments CS1502 Argument 1: cannot convert from 'int' to 'string' CS1503 The best overloaded method match for 'NinjaTrader.NinjaScript.StrategyBase.ExitShort(st ring, string)' has some invalid arguments CS1502 Argument 1: cannot convert from 'int' to 'string' CS1503

        when using this version:


        if(Close[0] < Low[1] && Position.MarketPosition == MarketPosition.Long)
        {
        ExitLong(DefaultQuantity, @"BULL TRIGGER");
        }
        if(Close[0] > High[1] && Position.MarketPosition == MarketPosition.Short)
        {
        ExitShort(DefaultQuantity, @"BEAR TRIGGER");
        }
        Last edited by gordongekko; 02-02-2018, 02:30 PM.

        Comment


          #19
          Hello gordongekko,

          Thank you for your response.

          When using the string and int quantity you need to include two strings; one for the entry signal name and one for the signal name of the exit.

          For example:
          Code:
          ExitLong(DefaultQuantity, [B]"EXIT SIGNAL NAME"[/B], @"BULL TRIGGER");
          Please let me know if you have any questions.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by CarlTrading, 03-31-2026, 09:41 PM
          1 response
          43 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by CarlTrading, 04-01-2026, 02:41 AM
          0 responses
          21 views
          0 likes
          Last Post CarlTrading  
          Started by CaptainJack, 03-31-2026, 11:44 PM
          0 responses
          30 views
          1 like
          Last Post CaptainJack  
          Started by CarlTrading, 03-30-2026, 11:51 AM
          0 responses
          50 views
          0 likes
          Last Post CarlTrading  
          Started by CarlTrading, 03-30-2026, 11:48 AM
          0 responses
          40 views
          0 likes
          Last Post CarlTrading  
          Working...
          X