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.