Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

I need two different stop loss/profit targets on the same strategy

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

    I need two different stop loss/profit targets on the same strategy

    Ok my strategy so far only enters trades from 9:55am to 3:55pm with this code
    if ((ToTime(Time[0]) >= 095500 && ToTime(Time[0]) < 155500))

    I have a profit target set to 26 ticks for this time frame in the "protected override void Initialize() and its

    SetProfitTarget("", CalculationMode.Ticks, myInput4);
    SetStopLoss("", CalculationMode.Ticks, myInput5, false);

    What I need is the time frame divided up into 9:55 to lets say 11:30am and then 11:30am to 3:55pm. I need the earlier time to have a different stop loss/profit than the 11:30 to 3:55pm time frame.

    Would I have to basically divide up my entire strategy into two separate parts for each time frame? And where do I put the profit target and stop loss codes, at the moment its a global parameter. I can post most of it in psudo code if that would help.

    #2
    Hello olingerc,

    Set statements will use the last value submitted. You can conditionally set them using OnBarUpdate(). If you're setting conditionally like this, you should replace the input you're using currently with a hard coded value or private variable.

    if ((ToTime(Time[0]) >= 095500 && ToTime(Time[0]) < 113000))
    //Set as 1 value here.


    if ((ToTime(Time[0]) >= 113100 && ToTime(Time[0]) < 155500))
    //Set as another value here.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Where do I put my two different profit targets then? Do I put it within the if statement for each time frame?

      Comment


        #4
        Yes, you can adjust both stop loss and profit targets in the same block. If you have more than one line you wanted actioned after an if statement, place all lines within curly brackets {}

        if ((ToTime(Time[0]) >= 095500 && ToTime(Time[0]) < 113000))
        {
        SetProfitTarget("", CalculationMode.Ticks, myInput4);
        SetStopLoss("", CalculationMode.Ticks, myInput5, false);
        }
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Ok thanks I will give this a try to see if it all works.

          Comment


            #6
            Where do I put my two different profit targets then?
            Don't do it like this. Just run two strategies. Each with its own SL&PT.

            Comment


              #7
              I will try both. I do not know the code to flatten all current positions though. I have it to flatten all at end of trading cessions. But how do I flatten everything at lets say 11:30am?

              Comment


                #8
                You could only exit positions that are currently held by your individual strategy, just check for a certain time (Time property) and then call ExitLong() and ExitShort() as needed.
                BertrandNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by carnitron, Today, 08:42 PM
                0 responses
                4 views
                0 likes
                Last Post carnitron  
                Started by strategist007, Today, 07:51 PM
                0 responses
                6 views
                0 likes
                Last Post strategist007  
                Started by StockTrader88, 03-06-2021, 08:58 AM
                44 responses
                3,969 views
                3 likes
                Last Post jhudas88  
                Started by rbeckmann05, Today, 06:48 PM
                0 responses
                5 views
                0 likes
                Last Post rbeckmann05  
                Started by rhyminkevin, Today, 04:58 PM
                4 responses
                58 views
                0 likes
                Last Post dp8282
                by dp8282
                 
                Working...
                X