Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Setting different profit target for contracts bought by the same strategy

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

    Setting different profit target for contracts bought by the same strategy

    So, I want to create a strategy that buys two contracts of ES if something happens. Here is a code example.

    if XXX happens then

    EnterLong(1,"Long 1");
    EnterLong(1,"Long 2");

    if XXX happens then
    ExitLong(1,"Long Exit 1","Long 1");
    ExitLong(1,"Long Exit 2","Long 2");

    I have similar code for the short entry and exit. In 'Initialize' section of the script, I have the following:

    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.UniqueEntries;
    SetProfitTarget("Long 1", CalculationMode.Ticks, profittargetticks1);
    SetProfitTarget("Long 2", CalculationMode.Ticks, profittargetticks2);
    SetProfitTarget("Short 1", CalculationMode.Ticks, profittargetticks1);
    SetProfitTarget("Short 2", CalculationMode.Ticks, profittargetticks2);
    SetStopLoss(CalculationMode.Ticks, stoplossticks);

    The problem is that the strategy is taking a trade on every single bar. Can someone please help to figure out what is wrong here? Very much appreciate your help in advance.

    Thanks!

    #2
    What is EntriesPerDirection set to?

    What is profittargetticks1 profittargetticks2 set to? Were they filled before new entries?

    What is CalculateOnBarClose set to?

    Has profittargetticks1/2 happened before XXX?




    Originally posted by pandyav View Post
    So, I want to create a strategy that buys two contracts of ES if something happens. Here is a code example.

    if XXX happens then

    EnterLong(1,"Long 1");
    EnterLong(1,"Long 2");

    if XXX happens then
    ExitLong(1,"Long Exit 1","Long 1");
    ExitLong(1,"Long Exit 2","Long 2");

    I have similar code for the short entry and exit. In 'Initialize' section of the script, I have the following:

    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.UniqueEntries;
    SetProfitTarget("Long 1", CalculationMode.Ticks, profittargetticks1);
    SetProfitTarget("Long 2", CalculationMode.Ticks, profittargetticks2);
    SetProfitTarget("Short 1", CalculationMode.Ticks, profittargetticks1);
    SetProfitTarget("Short 2", CalculationMode.Ticks, profittargetticks2);
    SetStopLoss(CalculationMode.Ticks, stoplossticks);

    The problem is that the strategy is taking a trade on every single bar. Can someone please help to figure out what is wrong here? Very much appreciate your help in advance.

    Thanks!

    Comment


      #3
      In addition to sledge's input - I would remove the exit and scale in part and just test your entries for example, would they trigger as you would expect from the logic (your XXX)? Same would go then for the exit logic...another approach would just be drawing on the conditions happening, too - so you would have an evaluation of the core logic apart from any order submission / fill logic contributing here.
      BertrandNinjaTrader Customer Service

      Comment


        #4
        @Sledge, Here is the info
        What is EntriesPerDirection set to? : 1

        What is profittargetticks1 profittargetticks2 set to? Were they filled before new entries?
        profittargetticks is set to 8
        profittargetticks is set to 24, and they were not filled before new entries


        What is CalculateOnBarClose set to? : True

        Has profittargetticks1/2 happened before XXX? : Not sure what you mean here, but I am attaching a snapshot of trades taken by the strategy

        @Ninjatrader_Bertrand: The strategy works if I execute only one position, but when I add the logic for the second position it messes things up. All I want to do is to enter two long or short position in one direction, and exit the first one at the profit of 8 ticks while the second one at the profit of 24 ticks. Not sure why the logic is not working?

        Once again, very much appreciate your help in advance.
        Attached Files

        Comment


          #5
          pandyav, looks from the visuals as if this might be a Multiseries / Multitimeframe script? From which BarsInProgress do you submit the entries then?
          BertrandNinjaTrader Customer Service

          Comment


            #6
            @NinjaTrader_Bertrand, you're absolutely correct. I am using 2500 tick chart as my base chart and confirming the signals based on 10 min chart.

            Which barsinprogress should I submit the entries in this case? Right now, all i have is a simple statement like below at the beginning of the strategy:
            if current bar <0
            return;

            Many thanks

            Comment


              #7
              You chart the 2500tick as your base so I would start testing by submitting to this primary chart then, just add to your OnBarUpdate start statement then -

              if (CurrentBar < 0 || BarsInProgress != 0)
              return;
              BertrandNinjaTrader Customer Service

              Comment


                #8
                @NinjaTrader_Bertrand,
                Thank you for your continuous support.

                I still see the strategy taking trade on every single bar after making the changes you suggested. I am attaching the latest screenshot and below is the strategy.

                protected override void OnBarUpdate()
                {

                if (CurrentBar < 0 || BarsInProgress != 0)
                return;
                //Long Entry
                if (VsTWPColor(wave).Power5[0] >= 1
                && (VsTWPColor(wave).Power5[0] <= 2
                && AAATS_TrendWithPower(wave).TrendUp.ContainsValue(0 )
                && AAATS_TrendWithPower(BarsArray[1],highertimewave).TrendTicksCount[0]>=1
                && AAATS_TrendWithPower(BarsArray[1],highertimewave).TrendTendance[0]>=1
                && (ToTime(Time[0]) >= 83000 && ToTime(Time[0]) <= 150000)))
                EnterLong(1,"Long 1");
                EnterLong(1,"Long 2");

                //Long Exit

                if ((AAATS_TrendWithPower(wave).TrendUp.ContainsValue (1)
                && AAATS_TrendWithPower(wave).Choppy.ContainsValue(0) )
                || AAATS_TrendWithPower(wave).TrendDown.ContainsValue (0))
                //&& (Position.MarketPosition == MarketPosition.Long))
                ExitLong(1,"Long Exit 1","Long 1");
                ExitLong(1,"Long Exit 2","Long 2");

                //Short Entry

                if (VsTWPColor(wave).Power5[0] >= 1
                && (VsTWPColor(wave).Power5[0] <= 2
                && AAATS_TrendWithPower(wave).TrendDown.ContainsValue (0)
                && AAATS_TrendWithPower(BarsArray[1],highertimewave).TrendTicksCount[0]>=1
                && AAATS_TrendWithPower(BarsArray[1],highertimewave).TrendTendance[0]<=-1
                && (ToTime(Time[0]) >= 83000 && ToTime(Time[0]) <= 150000)))

                EnterShort(1,"Short 1");
                EnterShort(1,"Short 2");

                //Short Exit
                if ((AAATS_TrendWithPower(wave).TrendDown.ContainsVal ue(1)
                && (AAATS_TrendWithPower(wave).Choppy.ContainsValue(0 )))
                || AAATS_TrendWithPower(wave).TrendUp.ContainsValue(0 ))
                ExitShort(1,"Short Exit 1","Short 1");
                ExitShort(1,"Short Exit 2","Short 2");



                }


                Once again your help is much appreciated.
                Attached Files

                Comment


                  #9
                  pandyav, based on how your formulated that code I would actually expect that outcome.

                  Take this first condition as example -

                  if (VsTWPColor(wave).Power5[0] >= 1
                  && (VsTWPColor(wave).Power5[0] <= 2
                  && AAATS_TrendWithPower(wave).TrendUp.ContainsValue(0 )
                  && AAATS_TrendWithPower(BarsArray[1],highertimewave).TrendTicksCount[0]>=1
                  && AAATS_TrendWithPower(BarsArray[1],highertimewave).TrendTendance[0]>=1
                  && (ToTime(Time[0]) >= 83000 && ToTime(Time[0]) <= 150000)))
                  EnterLong(1,"Long 1");
                  EnterLong(1,"Long 2");

                  Here, the first EnterLong is processed only if the if () condition evaluates to 'true' - the second one is processed every bar - as when you want to include more than one action after your if's you would need to apply proper bracing i.e.

                  if (VsTWPColor(wave).Power5[0] >= 1
                  && (VsTWPColor(wave).Power5[0] <= 2
                  && AAATS_TrendWithPower(wave).TrendUp.ContainsValue(0 )
                  && AAATS_TrendWithPower(BarsArray[1],highertimewave).TrendTicksCount[0]>=1
                  && AAATS_TrendWithPower(BarsArray[1],highertimewave).TrendTendance[0]>=1
                  && (ToTime(Time[0]) >= 83000 && ToTime(Time[0]) <= 150000)))
                  {
                  EnterLong(1,"Long 1");
                  EnterLong(1,"Long 2");
                  }
                  BertrandNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by traderqz, Today, 12:06 AM
                  4 responses
                  7 views
                  0 likes
                  Last Post traderqz  
                  Started by Mongo, Today, 11:05 AM
                  0 responses
                  3 views
                  0 likes
                  Last Post Mongo
                  by Mongo
                   
                  Started by Tim-c, Today, 10:58 AM
                  0 responses
                  2 views
                  0 likes
                  Last Post Tim-c
                  by Tim-c
                   
                  Started by traderqz, Yesterday, 09:06 AM
                  3 responses
                  24 views
                  0 likes
                  Last Post NinjaTrader_ThomasC  
                  Started by f.saeidi, Today, 10:19 AM
                  1 response
                  5 views
                  0 likes
                  Last Post NinjaTrader_BrandonH  
                  Working...
                  X