How to Execute Second position on Same Direction with StopLoss at Middle Point from first positon StopLoss and Current Price.
How to Execute Second position on Same Direction with StopLoss at Middle Point from first positon StopLoss and Current Price.
09 Feb 2024, 03:17
Hello, what i am trying to do is that once the Stop Lose Jump has been triggered on the current Open Position, the bot should now Open a new position on the same direction as the one that is already protected by the Stop Lose Jump. This is the code I made.
private void DoubleWinningPosition()
{
double? MidCalculation;
double? NewSL_Value;
foreach (Position P in Positions)
{
if (P.TradeType == TradeType.Sell)
{
if (StopJumpForSellWasTriggered && !DoublePosSellTriggered)
{
// Getting middle point from current open position and current buying price.
MidCalculation = (P.StopLosss.Value - Symbol.Ask) / 2;
// Subtracting difference from where the current position SL is.
NewSL_Value = P.StopLoss.Value - MidCalculation;
Print("Stop For Second Position: "+ NewSL_Value);
ExecuteMarketOrder(TradeType.Sell, Symbol.Name, (VolumeAmountInUnits * WinExVolMult), _label, NewSL_Value, GetTakeProfit(), "DoublePos");
DoublePosSellTriggered = true;
}
}
else
{
if (StopJumpForBuyWasTriggered && !DoublePosBuyTriggered)
{
// Getting middle point from current open position and current selling price.
MidCalculation = (Symbol.Bid - P.StopLoss.Value) / 2;
// Adding difference from where the current position SL is.
NewSL_Value = P.StopLoss.Value + MidCalculation;
Print("Stop For Second Position: "+ NewSL_Value);
ExecuteMarketOrder(TradeType.Buy, Symbol.Name, (VolumeAmountInUnits * WinExVolMult), _label, NewSL_Value, GetTakeProfit(), "DoublePos");
DoublePosBuyTriggered = true;
}
}
}
}
This is what the log prints.
I dont understand why in the log the value printed is the correct value but in the position execution is placing the stop where it shouldnt be.
Replies
garnak123
10 Feb 2024, 00:38
( Updated at: 10 Feb 2024, 07:55 )
RE: How to Execute Second position on Same Direction with StopLoss at Middle Point from first positon StopLoss and Current Price.
PanagiotisCharalampous said:
Hi there,
The stop loss parameter should be in pips, not in absolute price. So you need to calculate the relevant pips so that the stop loss is set at the correct price level.
Best regards,
Panagiotis
Thanks!!
@garnak123
garnak123
18 Feb 2024, 06:17
RE: How to Execute Second position on Same Direction with StopLoss at Middle Point from first positon StopLoss and Current Price.
PanagiotisCharalampous said:
Hi there,
The stop loss parameter should be in pips, not in absolute price. So you need to calculate the relevant pips so that the stop loss is set at the correct price level.
Best regards,
Panagiotis
For me to do this i dont have to just add “"" * Symbol.Pipzise “”” at the end?
NewSL_Value = (P.StopLoss.Value + MidCalculation) * Symbol.Pipzise;
@garnak123
PanagiotisCharalampous
18 Feb 2024, 06:57
RE: RE: How to Execute Second position on Same Direction with StopLoss at Middle Point from first positon StopLoss and Current Price.
garnak123 said:
PanagiotisCharalampous said:
Hi there,
The stop loss parameter should be in pips, not in absolute price. So you need to calculate the relevant pips so that the stop loss is set at the correct price level.
Best regards,
Panagiotis
For me to do this i dont have to just add “"" * Symbol.Pipzise “”” at the end?
NewSL_Value = (P.StopLoss.Value + MidCalculation) * Symbol.Pipzise;
No, you should first calculate the distance from the entry price and then divide by the pip size.
@PanagiotisCharalampous
PanagiotisCharalampous
09 Feb 2024, 06:46
Hi there,
The stop loss parameter should be in pips, not in absolute price. So you need to calculate the relevant pips so that the stop loss is set at the correct price level.
Best regards,
Panagiotis
@PanagiotisCharalampous