Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi positions handling

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

    Multi positions handling

    Hi,

    I'm trying to handle each position with her own exit price.
    For each signal i have a different name.
    How can i control each signal with the SetProfitTarget/SetStopLoss ?

    I'm using this code but it's not working :

    SetProfitTarget("LoSig"+i,CalculationMode.Ticks,Ma xProfit);
    SetStopLoss("LoSig"+i,CalculationMode.Ticks,MaxLos s,false);

    Igal

    #2
    Hi Igal, what do you mean exactly by not working? So all positions are exited at the same price eventhough in OnBarUpdate() you set then different levels per each position? I understand correctly you scale in via unique signal names here?

    Comment


      #3
      Hi Bertrand,

      For Example :

      The entry for the first signal :

      if (dsRsi[0] < dRsiEntry )
      {
      openPrc = pRound(Close[0]- mOffset*TickSize);
      oLong = EnterLongLimit(iQty,openPrc,"LoSig"+i);
      SetStopLoss(CalculationMode.Ticks,30);
      SetProfitTarget(CalculationMode.Ticks,30);

      }

      The entry for the other signals:
      if (Pos_MarketPosition == MarketPosition.Flat && dsRsi[0] < dRsiEntry && dsRsi[0] < dsRsi[1])
      {
      openPrcNew = pRound(Close[0]- mOffset*TickSize);
      oLong2 = EnterLongLimit(iQty,openPrcNew,"LoSig"+i);
      SetStopLoss("LoSig"+i,CalculationMode.Ticks,30,fal se);
      SetProfitTarget("LoSig"+i,CalculationMode.Ticks,30 );

      }

      now if i want to handle every signal, for example only the first signal :
      if (oLong.Name == "LoSig1")
      {
      if (dsRsi[0] >= dRsiExit )
      {
      dTrgPrc = Math.Min(openPrc+(30*TickSize),Close[0] +(mextoffsetLoss*TickSize));
      TPMode = CalculationMode.Price;
      }
      SetProfitTarget(TPMode,dTrgPrc);
      SetStopLoss(CalculationMode.Ticks,iMaxLoss);
      }

      now if i want to handle all the signals that are after the first signal :

      if (oLong2.Name == "LoSig"+i)
      {
      if (dsRsi[0] >= dRsiExit)
      {
      dTrgPrc2 = Math.Min(openPrcNew+(30*TickSize),Close[0] +(mextoffsetLoss*TickSize));
      TPMode2 = CalculationMode.Price;
      }
      SetProfitTarget("LoSig"+i,TPMode2,dTrgPrc2);
      SetStopLoss("LoSig"+iCalculationMode.Ticks,iMaxLos s2,false);
      }

      now my problem that all the signals that are from "LogSig"+i dont exit with the new exit price.
      Last edited by igalml; 07-02-2014, 04:05 AM.

      Comment


        #4
        Thanks, what price do you see then used instead? Are the custom price target / stop prices you calculate hitting what you would expect? I wonder if you see an issue with this logic part below?

        if (oLong2.Name == "LoSig"+i)

        For a test, does it work differently if you explicitly for example reference the LoSig2?

        Comment


          #5
          Yes because if the signal is filled i increasing i :

          protected override void OnOrderUpdate(IOrder order)
          {

          if ((oLong != null && oLong == order) || oLong2 != null && oLong2 == order)
          {
          if ((order.OrderState == OrderState.Filled))
          i++;
          }
          }

          and when i'm flat so i = 1.
          if (Pos_MarketPosition == MarketPosition.Flat)
          {
          i = 1;

          }


          for ur first question the price that i see instead is the original MaxLoss,MaxProfit that are fixed.
          this is my condition :

          if (oLong2.Name == "LoSig"+i)
          {


          if (!btimetoexit2)
          {
          dTrgPrc2 = (int)(0.5+iUnderCount/i);
          TPMode2 = CalculationMode.Ticks;
          dLossPrc2 = (iMaxLossSig2);
          SLMode2 = CalculationMode.Ticks;
          }

          if (dsRsi[0] >= dRsiExit)
          {
          dTrgPrc2 = Math.Min(openPrcNew+(30*TickSize),Close[0] +(mextoffsetLoss*TickSize));
          TPMode2 = CalculationMode.Price;
          btimetoexit2 = true;
          DrawDiamond("MyDiamond"+ind, true, 0, dTrgPrc2, Color.Yellow);
          ind++;
          }



          SetProfitTarget("LoSig"+i,TPMode2,dTrgPrc2);
          SetStopLoss("LoSig"+i,SLMode2,dLossPrc2,false);




          }

          Comment


            #6
            Right Igal, that's what you codewise do and expect to work. However to isolate this scenario further out I would strongly confirm that via prints to your NT output window. If the exit levels are not update, then I feel either the condition to adjust would not get called in your code, or the calculated levels are off.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by charlesugo_1, 05-26-2026, 05:03 PM
            0 responses
            65 views
            0 likes
            Last Post charlesugo_1  
            Started by DannyP96, 05-18-2026, 02:38 PM
            1 response
            149 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by CarlTrading, 05-11-2026, 05:56 AM
            0 responses
            162 views
            0 likes
            Last Post CarlTrading  
            Started by CarlTrading, 05-10-2026, 08:12 PM
            0 responses
            99 views
            0 likes
            Last Post CarlTrading  
            Started by Hwop38, 05-04-2026, 07:02 PM
            0 responses
            286 views
            0 likes
            Last Post Hwop38
            by Hwop38
             
            Working...
            X