Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 cmtjoancolmenero, Yesterday, 03:58 PM
          1 response
          17 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by benmarkal, Yesterday, 12:52 PM
          3 responses
          23 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by helpwanted, Today, 03:06 AM
          1 response
          20 views
          0 likes
          Last Post sarafuenonly123  
          Started by Brevo, Today, 01:45 AM
          0 responses
          12 views
          0 likes
          Last Post Brevo
          by Brevo
           
          Started by pvincent, 06-23-2022, 12:53 PM
          14 responses
          244 views
          0 likes
          Last Post Nyman
          by Nyman
           
          Working...
          X