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 Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            651 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            370 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            109 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            574 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            577 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X