Topic: Manual StopLoss and TakeProfit

Hi,

i am struggling to get in run in Portfolio.

Each strategy has its own TP SL by code.

If i decide to have a stopLoss and takeProfit which i want for all strategies to use, can some coder help.

This my new input param:

input bool choose = true;
input double Stopl = 100;
input double Takep = 100;

Here i have made changes in OpenPosition

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OpenPosition(Signal &signal)
  {
   for(int attempt=0; attempt<TRADE_RETRY_COUNT; attempt++)
     {
      int    ticket     = 0;
      int    lastError  = 0;
      bool   modified   = false;
      int    command    = OrderDirectionToCommand(signal.Direction);
      double amount     = Entry_Amount;
      double stopLoss   = signal.StopLossPips>0 ? GetStopLoss(command, signal.StopLossPips) : 0;
      double takeProfit = signal.TakeProfitPips>0 ? GetTakeProfit(command, signal.TakeProfitPips) : 0;
      string comment    = IntegerToString(signal.MagicNumber);
      color  arrowColor = command==OP_BUY ? clrGreen : clrRed;
      double stopl = Stopl;
      double takep = Takep;

      if(IsTradeContextFree())
        {
         double price=MarketInfo(_Symbol,command==OP_BUY ? MODE_ASK : MODE_BID);
         if(setProtectionSeparately)
           {
            ticket=OrderSend(_Symbol,command,amount,price,10,0,0,comment,signal.MagicNumber,0,arrowColor);
            if(ticket>0 && (signal.StopLossPips>0 || signal.TakeProfitPips>0))
               modified=OrderModify(ticket,0,stopLoss,takeProfit,0,clrBlue);
           }
         else
           {
          [b] if(choose)
           {
            ticket=OrderSend(_Symbol,command,amount,price,10,stopl,takep,comment,signal.MagicNumber,0,arrowColor);
            lastError=GetLastError();
            if(ticket<=0 && lastError==130)
              {
               ticket=OrderSend(_Symbol,command,amount,price,10,0,0,comment,signal.MagicNumber,0,arrowColor);
               if(ticket>0 && (stopl>0 || stopl>0))
                  modified=OrderModify(ticket,0,stopl,takep,0,clrBlue);
               if(ticket>0 && modified)
                 {
                  setProtectionSeparately=true;
                  Print("Detected ECN type position protection.");
                 }
              }
            }
            else
           {
            ticket=OrderSend(_Symbol,command,amount,price,10,stopLoss,takeProfit,comment,signal.MagicNumber,0,arrowColor);
            lastError=GetLastError();
            if(ticket<=0 && lastError==130)
              {
               ticket=OrderSend(_Symbol,command,amount,price,10,0,0,comment,signal.MagicNumber,0,arrowColor);
               if(ticket>0 && (signal.StopLossPips>0 || signal.TakeProfitPips>0))
                  modified=OrderModify(ticket,0,stopLoss,takeProfit,0,clrBlue);
               if(ticket>0 && modified)
                 {
                  setProtectionSeparately=true;
                  Print("Detected ECN type position protection.");
                 }
              }
            }            [/b]
          
           }
        }

      if(ticket>0) break;

      lastError=GetLastError();

      if(lastError!=135 && lastError!=136 && lastError!=137 && lastError!=138) break;

      Sleep(TRADE_RETRY_WAIT);
      Print("Open Position retry no: "+IntegerToString(attempt+2));
     }
  }

So i have made an if.

if choose true than it use anoother OrderSend with my stopLoss and tp from input.
But not working

any idea how to get it run easily.

Re: Manual StopLoss and TakeProfit

Each strategy of the Portfolio Expert forms its entry and exit signals with two functions:
`CreateExitSignal` and `CreateEntrySignal` correspondingly.
The SL and TP values are hard-coded in the 3rd end 2nd params from the end.

Signal signal = CreateExitSignal(2, ind3long, ind3short, 61, 44, false);

Here StopLoss is 61  pips and TakeProfit is 44 pips.

The easiest way to make a common SL and TP is within these two functions. They are very similar, so I'll show the modification in `CreateEntrySignal` only.

Signal CreateEntrySignal(...) // AND CreateExitSignal (...)
{
   ...

   signal.StopLossPips   = stopLossPips;
   signal.TakeProfitPips = takeProfitPips;
   signal.IsTrailingStop = isTrailingStop;
   
   // The new code for overriding SL and TP
   if (useCommonSLTP) {
       signal.StopLossPips   = myStopLossPips;
       signal.TakeProfitPips = myTakeProfitPips;
   }

   return (signal);
}

Re: Manual StopLoss and TakeProfit

Popov wrote:

Each strategy of the Portfolio Expert forms its entry and exit signals with two functions:
`CreateExitSignal` and `CreateEntrySignal` correspondingly.
The SL and TP values are hard-coded in the 3rd end 2nd params from the end.

Signal signal = CreateExitSignal(2, ind3long, ind3short, 61, 44, false);

Here StopLoss is 61  pips and TakeProfit is 44 pips.

The easiest way to make a common SL and TP is within these two functions. They are very similar, so I'll show the modification in `CreateEntrySignal` only.

Signal CreateEntrySignal(...) // AND CreateExitSignal (...)
{
   ...

   signal.StopLossPips   = stopLossPips;
   signal.TakeProfitPips = takeProfitPips;
   signal.IsTrailingStop = isTrailingStop;
   
   // The new code for overriding SL and TP
   if (useCommonSLTP) {
       signal.StopLossPips   = myStopLossPips;
       signal.TakeProfitPips = myTakeProfitPips;
   }

   return (signal);
}

thank you.