Please tell me, when closing an order for StopLoss, I need to open an order in the opposite direction with the same parameters, but once. I.e. if the first order was closed for SL, then for subsequent closed orders for SL, do not open an order in the opposite direction.
Share
barabashkakvn
No, you can’t.
miron_like
Please tell me, what can I do based on my code, so as not to rewrite it?
nektomk
instead of (together) SL, enter a pending order with the same (or different) parameters, at the desired level. By the way, SL is not allowed everywhere, and in general, you should forget about such order parameters as TakeProfit and StopLoss – treat them as independent transactions and happiness will remain.
barabashkakvn
To get started, just take an example and remove all the extra stuff – what you don’t need.
miron_like
if (Total==0 && Opn_B==true){
TP=Bid + SizeTP*Point;
SL=Bid - SizeSL*Point;
Ticket=OrderSend(Symbol(),OP_BUY,Lts,Ask,5,SL,TP,NULL,0,0,clrBlue);
if (Ticket > 0){
if(!OrderSelect(Ticket)){
//Opening a position in the opposite direction with the same parameters
}
}
}
barabashkakvn
No, it’s not right. You caught a transaction with the TRADE_TRANSACTION_DEAL_ADD type – this is adding a transaction to the history, please note that there is no mention of an order here. Forget about the orders. There are only positions.
Next, see that the transaction must have the DEAL_REASON_SL property – again, the transaction, orders do not even smell.
Now it remains to open a position:
Forum on trading, automated trading systems and testing of trading strategies
Opening an order in the opposite direction
Vladimir Karputov, 2017.07.27 14:05
And for an example of opening a position (namely, a position, and not placing a pending order), see the same code that I gave (the OpenBuy and OpenSell functions).
To begin with, just write the code in which it opens a position after you find the trade that appeared as a result of the Stop loss trigger – then, when I see your code, I will tell you further.
miron_like
a little misunderstood, i.e. it should look like this?
long deal_reason =-1;
deal_reason=HistoryDealGetInteger(trans.deal,DEAL_REASON);
if(deal_reason==DEAL_REASON_SL){
if(!OrderSelect(ticket)){
//Opening an order
}
}
barabashkakvn
Yes. That’s right.
prostotrader
Make a check for the existence of an order
if(!OrderSelect(ticket))
{
//Setting an order
}
Added
In fact, everything is a little more complicated, to answer unambiguously, you need to see the code…
miron_like
Can you tell me how to open an order in the opposite direction? And only once, and not every time when closing an order for SL
barabashkakvn
Example of how to catch a 100% guaranteed trade as a result of triggering the Stop Loss code Stop Loss Take Profit – in OnTradeTransaction, catch a trade that is closed as a result of the Stop loss trigger (the DEAL_REASON_SL property of the trade).
After you have caught a closed trade as a result of the Stop Loss trigger, you can already do what you need.