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

Error that i cant Find

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

    Error that i cant Find

    Hello!

    I have some trouble whit a Strategy i'm making... What i want is this:

    - IF Candle Close < Open (Bearish) -> Sell at the open or open -1 of the next candle

    - I want to have the option to change the Target and Stop Loss, and if possible this works on Range Chart.

    Problems:
    1º When it enters on Trade, dont Stop or Target (just enter the trade)
    2º Most of the times, dont even enter on trade, give me a error "order reject"

    I made whit wizzard, and i even saw a ninjatrader webinar about that. But ther's an error i cant find. Can any 1 help me?


    Thanks alot !
    Attached Files

    #2
    Hello,

    I wanted to check:

    1º When it enters on Trade, dont Stop or Target (just enter the trade)
    Are you asking that when it enters a trade to not use a stop and target but only enter a position?

    2º Most of the times, dont even enter on trade, give me a error "order reject"

    If you are getting a rejected order, the error often tell why the order was rejected, for example if the order was placed on the incorrect side of the market. Can you provide the rejection error you are getting to better understand what may be occurring in the logic?

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks for the fast help

      1º I want that the trades have a Stop and a Target, but it simply enters on the trade.

      2º I think i just correct that error (to be honest not sure how LOL)

      So now is just the fact, that ther is NO Stop or Target. And i would like to have it

      Comment


        #4
        I think you are saying you want to have a stop and target but there is none.

        You want to write that in under your strategy start usually:

        public class Main_strategy : Strategy
        {
        private double profitTargetPct = 0.025; // 2.5% profit target expected
        private double StopLoss = 0.05; //5% stop loss
        }

        then on bar update
        protected override void OnBarUpdate()
        {
        if (CrossAbove(smaFast, smaSlow, 1)
        {
        EnterLong();
        }
        //now create your stop loss and target exit parameters
        if (Position.MarketPosition == MarketPosition.Long && MarketPosition.Average*(1+profitTargetPct) >= Close[0)
        {
        ExitLong();
        }

        ^^ you could create additional parameters so as not to do math within parenthesis and keep code cleaner. But the idea is, check if you're in LONG, or SHORT, and if you hit your profit or you hit your stop exit. For StopLoss, you would do Marketposition.average*(1-StopLoss) <= Close[0] - so checking that your average with stop accounted for is now less than the last close, and you should EXIT.

        Comment


          #5
          Originally posted by lmatiukas View Post
          I think you are saying you want to have a stop and target but there is none.

          You want to write that in under your strategy start usually:

          public class Main_strategy : Strategy
          {
          private double profitTargetPct = 0.025; // 2.5% profit target expected
          private double StopLoss = 0.05; //5% stop loss
          }

          then on bar update
          protected override void OnBarUpdate()
          {
          if (CrossAbove(smaFast, smaSlow, 1)
          {
          EnterLong();
          }
          //now create your stop loss and target exit parameters
          if (Position.MarketPosition == MarketPosition.Long && MarketPosition.Average*(1+profitTargetPct) >= Close[0)
          {
          ExitLong();
          }

          ^^ you could create additional parameters so as not to do math within parenthesis and keep code cleaner. But the idea is, check if you're in LONG, or SHORT, and if you hit your profit or you hit your stop exit. For StopLoss, you would do Marketposition.average*(1-StopLoss) <= Close[0] - so checking that your average with stop accounted for is now less than the last close, and you should EXIT.

          Thanks alot for your awenser! I tryed what you said and it give me alot of errors. i Tryed to fix it, but just created more Is it possible you send me in file whit what you just told me?

          Comment


            #6
            Originally posted by PauloP View Post
            Thanks for the fast help
            So now is just the fact, that ther is NO Stop or Target. And i would like to have it
            Thank you for clearing that up.

            The file you had originally attached is a compiled assembly so I am unable to see the original strategy to know what logic is being used.

            In general to set a StopLoss or Profit target, you could use the Set methods described here:



            You can also use Exit methods and logic as lmatiukas had described.

            We have a few example strategies that include the Set methods here:



            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Brevo, Today, 01:45 AM
            0 responses
            6 views
            0 likes
            Last Post Brevo
            by Brevo
             
            Started by aussugardefender, Today, 01:07 AM
            0 responses
            3 views
            0 likes
            Last Post aussugardefender  
            Started by pvincent, 06-23-2022, 12:53 PM
            14 responses
            241 views
            0 likes
            Last Post Nyman
            by Nyman
             
            Started by TraderG23, 12-08-2023, 07:56 AM
            9 responses
            384 views
            1 like
            Last Post Gavini
            by Gavini
             
            Started by oviejo, Today, 12:28 AM
            0 responses
            6 views
            0 likes
            Last Post oviejo
            by oviejo
             
            Working...
            X