Calculate stoploss

Hello everyone,
I am having a hard time coding an API trading strategy with a stock company. I have coded buy and sell orders and additional buying and selling points according to the trend.
For example: When the trend reverses, there will be a buy/sell order with 5 contracts. After that, if the conditions are met, I will add buy/sell orders with 1 contract/2 contracts. However, for hedging, I want to create a stoploss order for the extra buy/sell part (not included). includes the first buy/sell orders of the trend)
I determined to be able to calculate:
1. the number of orders/buys/sells according to the up/down trend (calculated from the first buy/sell signal)
2.Average buying/selling price = (Purchase/selling price + buying/selling fee) x number of contracts/Number of contracts
3. Stoploss price = if closing price </> average price

Thanks everyone

//----------------------Dat them 2 HD------------------//

DK_Buy_2HD=BarsBuy<BarsSell AND ((Tem5>=0.6 AND V<Vp1) OR (Tem5<0.6 AND Tem5>=0.3  AND DK_Vol)) AND NOT Notrade AND Ref(Tem5,-1)<0.6 AND NOT Buy;
DK_Sell_2HD=BarsBuy>BarsSell AND ((Tem5<=-0.6 AND V<Vp1) OR (Tem5>-0.6 AND Tem5<=-0.3 AND DK_Vol)) AND NOT Notrade AND Ref(Tem5,-1)>-0.6 AND NOT Sell;
BuyPrice_2HD = ValueWhen(DK_Buy_2HD,C,1);
SellPrice_2HD = ValueWhen(DK_Sell_2HD,C,1);

BarsDKBuy2HD=BarsSince(DK_Buy_2HD);
BarsDKSell2HD=BarsSince(DK_Sell_2HD);

//----------------------Dat them 3 HD/5HD------------------//
DK_Buy_5HD=BarsBuy<BarsSell AND (Tem5>=0.6 AND V>Vp1) AND NOT Notrade AND NOT Buy AND Ref(Tem5,-1)<0.6;
DK_Sell_5HD=BarsBuy>BarsSell AND (Tem5<=-0.6 AND V>Vp1)AND NOT Notrade AND NOT Sell AND Ref(Tem5,-1)>-0.6;
BuyPrice_5HD = ValueWhen(DK_Buy_5HD,C,1);
SellPrice_5HD = ValueWhen(DK_Sell_5HD,C,1);


PlotShapes(IIf(DK_Buy_2HD, shapeUpArrow, shapeNone),colorYellow, 0,Low,-15);
PlotShapes(IIf(DK_Sell_2HD, shapeDownArrow, shapeNone),colorYellow, 0,High,-15);
PlotShapes(IIf(DK_Buy_5HD, shapeUpArrow, shapeNone),colorBlue, 0,Low,-15);
PlotShapes(IIf(DK_Sell_5HD, shapeDownArrow, shapeNone),colorTurquoise, 0,High,-15);

AlertIF( (DK_Buy_2HD OR DK_Buy_5HD) , "SOUND C:\\Windows\\Media\\Ring08.wav", "Audio alert", 1, 15, 1 );
AlertIF( (DK_Sell_2HD OR DK_Sell_5HD), "SOUND C:\\Windows\\Media\\Ring08.wav", "Audio alert", 2, 15, 1 );



//Dat lenh Buy/Sell Entrade///////
if (Buy[BarCount-2]==True)
{
ih =
InternetOpenURL("http://localhost:6868/api/trade?symbol=VN30F1M&side=NB&clientId=-1" ); 
InternetClose(ih);
}
if (Sell[BarCount-2]==True)
{
ih =
InternetOpenURL("http://localhost:6868/api/trade?symbol=VN30F1M&side=NS&clientId=-1" );
InternetClose(ih);
}

if (DK_Buy_2HD[BarCount-2]==True)
{
ih =
InternetOpenURL("http://localhost:6868/api/trade?symbol=VN30F1M&side=NB&clientId=-1" ); 
InternetClose(ih);
}
if (DK_Sell_2HD[BarCount-2]==True)
{
ih =
InternetOpenURL("http://localhost:6868/api/trade?symbol=VN30F1M&side=NS&clientId=-1" );
InternetClose(ih);
}

if (DK_Buy_5HD[BarCount-2]==True)
{
ih =
InternetOpenURL("http://localhost:6868/api/trade?symbol=VN30F1M&side=NB&clientId=-1" ); 
InternetClose(ih);
}
if (DK_Sell_5HD[BarCount-2]==True)
{
ih =
InternetOpenURL("http://localhost:6868/api/trade?symbol=VN30F1M&side=NS&clientId=-1" );
InternetClose(ih);
}

Screenshot 2022-03-02 115723

Help me,please!!! Thanks so much!

You would have better chances to get the answer if the post was gramatically correct. Frankly I don't have slightest idea what this sentence is supposed to mean:

Please follow this advice: How to ask a good question

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.