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

Multiple entries; else if

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

    Multiple entries; else if

    Hi

    if (market=flat & close>0)
    {enter long}
    else if market = long & close is less than threshold
    {enter short}
    else if market = short & close is > than threshold
    {enter long}
    else if market = long & close is less than threshold
    {enter short}
    ....
    .... and so on

    my question is that by using 'else if' does the system read this script from top to bottom? meaning the fourth else if condition is still Long or Short, will that interfere with the first one?

    essentially what i am trying to do is reverse my positions if trade goes against me. but i want to happen in the order from top to bottom. if i get stopped out of the first one, then go to next else if statement, if i get stopped out of that one, then go to next else if statement and so on

    #2
    Originally posted by calhawk01 View Post
    Hi

    if (market=flat & close>0)
    {enter long}
    else if market = long & close is less than threshold
    {enter short}
    else if market = short & close is > than threshold
    {enter long}
    else if market = long & close is less than threshold
    {enter short}
    ....
    .... and so on

    my question is that by using 'else if' does the system read this script from top to bottom? meaning the fourth else if condition is still Long or Short, will that interfere with the first one?

    essentially what i am trying to do is reverse my positions if trade goes against me. but i want to happen in the order from top to bottom. if i get stopped out of the first one, then go to next else if statement, if i get stopped out of that one, then go to next else if statement and so on
    In a statement like that it won't hit each section if it finds a match.

    if (market=flat & close>0)
    {enter long} //if it meets the criteria here it won't attempt to hit the other statements
    else if market = long & close is less than threshold
    {enter short}
    else if market = short & close is > than threshold
    {enter long}
    else if market = long & close is less than threshold
    {enter short}

    The code would skip what ever until it gets to the end or you have another section of code here.

    To reverse position, just entershort while you have an enterlong in play.

    if(market=flat & close>0)
    {
    enterlong
    }

    if(market=long & criteria = x)
    {
    entershort
    }

    if(market=short & criteria = x)
    {
    enterlong
    }
    Last edited by happypappy; 10-24-2014, 01:02 AM.

    Comment


      #3
      Hello Calhawk01,

      Thank you for your note.

      Happypappy suggestion is correct here. If one of the conditions in the Else IF's is met then the script will stop of that section of IF Statements and move on to the next group in the code.
      Cal H.NinjaTrader Customer Service

      Comment


        #4
        Originally posted by NinjaTrader_Cal View Post
        Hello Calhawk01,

        Thank you for your note.

        Happypappy suggestion is correct here. If one of the conditions in the Else IF's is met then the script will stop of that section of IF Statements and move on to the next group in the code.
        Thank you Happypappy and Cal

        is there a way to define the quantity for stoploss orders?

        for example if i'm long 1 contract, and my stoploss is hit, i want to sell 3 contracts within the built in stoploss limit order.

        right now what i'm doing is defining a threshold in OBU as stoploss, meaning, if price goes down below threshold (stoploss) sell market 3 contracts. but this is causing huge slippage. it would be best to enter limit orders sell of 3 contracts when i go long 1 contracts at the same time. any idea?

        what i want to do is

        go long 1 contract if XYZ happens
        {set profit target}
        {set stoploss 3 contracts} //this will take me short if stoploss is hit

        if profit is hit, then restart the script, if stoploss is hit and position = short 2 contracts
        {set stoploss 5 contracts} //this will take me long if stoploss is hit
        {set profit target}

        if profit is hit, then restart the script, if stoploss is hit and position = long 3 contracts
        {same setup as above}
        .....


        thanks

        Comment


          #5
          Hello Calhawk01,

          The Set() methods will only place orders for the number of positions the strategy has. You would need to use Entry and Exit orders to submit these additional orders to go in the opposite direction.

          You may even need to use Unmanaged() approach so that you have a more direct control over your orders in this matter.
          Cal H.NinjaTrader Customer Service

          Comment


            #6
            Is there a way to check to see if specific entry name is flat rather than market position?

            Ie; EnterLong(1,"entryname1")

            if entryname1= flat
            {do xya}

            Comment


              #7
              Calhawk01,

              You cannot detect when a specific order is flat. This would be related to a position.

              However, you would need to set some kind of variable that when the entry was filled would set this variable to what you would define as long or short.

              Take an int variable for instance.

              Let's say that my entry gets filled for long, I then set the int variable to 1 to represent long.
              If it went short I would set it to -1 and 0 for flat.

              The question for flat is more involved. If you have exit orders for the specific entry signal then we can look to when that get orders get filled to then set the int variable to 0.

              Let me know if this was helpful
              Cal H.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by AaronKoRn, Yesterday, 09:49 PM
              0 responses
              11 views
              0 likes
              Last Post AaronKoRn  
              Started by carnitron, Yesterday, 08:42 PM
              0 responses
              10 views
              0 likes
              Last Post carnitron  
              Started by strategist007, Yesterday, 07:51 PM
              0 responses
              12 views
              0 likes
              Last Post strategist007  
              Started by StockTrader88, 03-06-2021, 08:58 AM
              44 responses
              3,982 views
              3 likes
              Last Post jhudas88  
              Started by rbeckmann05, Yesterday, 06:48 PM
              0 responses
              10 views
              0 likes
              Last Post rbeckmann05  
              Working...
              X