Set Stop Loss and POSITIONPRICE not working ?
Forums › ProRealTime English forum › ProOrder support › Set Stop Loss and POSITIONPRICE not working ?
- This topic has 14 replies, 5 voices, and was last updated 1 year ago by JC_Bywan.
-
-
04/16/2023 at 1:05 PM #213349
hi
I do this small code, Do you know pls why my stop loss is executed when the price is not even reached and why a partial exit and not total?
that is the code :
123456789101112myMACD = MACD[12,26,9](close)long = myMACD crosses over 0IF long THENBUY 1 CONTRACTS AT MARKETENDIF//Stop for the whole ordersSet Stop Loss 20*pipsizeGraph PositionPrice AS "PositionPrice"Graph PositionPrice - 20*pipsize AS "SL"you can see on the photo :
Long-1 = 142,978
Long-2 = 142,914
So PositionPrice is = (142,978 + 142,914) / 2 = 142,946 Round by PRT to 142,947
PositionPrice = 142,947
SL = PositionPrice – 20 pips = 142,947 – 0,20 = 142,747
SL = 142,747
Exit 1 Shares = 142,778
you can see the SL is not reached but I have an exit at 142,778 ? and they sell only 1 shares, why not 2 shares (Totaly exit)tks in advance for all your light 😃
04/16/2023 at 4:18 PM #213359Hi ZeroCafeine,
The Stop Loss is added to each individual order…
Long Order 1: 142,978
Stop Loss: 142.978 – 0.20 = 142.778
Exit first long at: 142,778
Long order2: 142,914
Stop Loss: 142,914 – 0,20 = 142,714
Exit second order at: 142,714
1 user thanked author for this post.
04/16/2023 at 7:11 PM #213370ok ok understand, so it’s better to get the tradeprice (or positionprice) and to create a Sell Stop Order at the price of TradePrice – SL*pipsize ? or somethink like that ?
or they have other solution ?
04/16/2023 at 9:08 PM #213373Hi,
I think this is best used:
Sell at PositionPrice-20*pipsize STOP
2 users thanked author for this post.
04/17/2023 at 9:10 AM #213392or use the new instruction:
SET STOP PRICE PositionPrice-20*pipsize
2 users thanked author for this post.
04/17/2023 at 11:08 AM #213397Tks for you too, I will do some test and post here the result,
how to if I want to control the quantity of selling in your case with this code ?, exemple I want to sell at stop the half quantity or 10 or 90% ?
04/17/2023 at 12:00 PM #213398ok tks you, So I tested you 2 solution and it’s working fine,
the @JS solution, I am executed as a Sell (Normal sell at Stop Price), small triangle on the graph, I was able to control the quantity like this :
1Sell CountOfPosition Shares at PositionPrice-20*pipsize STOP // JSthe @Nicolas solution, I am executed as an Stop Loss, small cross on the graph, How can the quantity be controlled in this case?
Both solutions I suppose @Nicolas’ solution is safer as it will take me out of the market anyway? Or am I wrong?
As for JS’s solution, is it possible that for X reason I won’t be executed and I’ll end up with open lines again at the next candle? Or am I wrong?
04/17/2023 at 12:11 PM #213399In any case, I would prefer using SET STOP PRICE as it should act as a “real” stoploss regarding the IG server (such as the classic SET STOP LOSS).
It is not possible to close partially with any of these instructions, you need a MARKET order to do that.
1 user thanked author for this post.
04/17/2023 at 1:06 PM #213402ok tks you, so with SET STOP PRICE it’s better andI I will be executed at the market but normally I will also have priority over the other pending limit orders in the broker’s order list ?
Is it better to sell a limit order below the market price at the moment T and that way at least I will be executed quickly at the market below the current price but not at any price (as the lowest of the wick 😅 ), I don’t know if I am clear enough in my explanation?
and also it is not possible to select the quantity in the case of SET STOP PRICE right ?
04/18/2023 at 3:04 PM #213443it’s great the programming, I think to a question and I find the answer by myself but at the same time I find myself with a new question 🤣
Why do I have buys and sells in the same candle?
I understand that in order to avoid this problem you have to create a stop loss order only when the buy condition is true like the following example:
1234567myMACD = MACD[12,26,9](close)long = myMACD crosses over 0IF long THENBUY 1 CONTRACTS AT Close LimitSET STOP PRICE PositionPrice-10*pipsize // NicoENDIFon the other hand when the Stop is out of the IF condition as in the example above, you can see on the picture that I have a problem only in the point B and C but not on A :
12345678myMACD = MACD[12,26,9](close)long = myMACD crosses over 0IF long THENBUY 1 CONTRACTS AT Close LimitENDIFSET STOP PRICE PositionPrice-10*pipsize // Nicotks you
1 user thanked author for this post.
04/20/2023 at 3:51 PM #213555Start going crazy with this candle by candle programming 😂,
I notice now that if my StopLoss order is executed candle by candle then I have a better execution for my exit, if I understand correctly the program will not consider the close of the current candle to execute my stop loss but it will check the price on smaller time units,
Whereas if my stop loss is only executed when the buy condition is true, in this case I notice that the StopLoss sale is only executed in the next candle when the Close of the previous candle is lower than my StopLoss price
So far I don’t have a problem understanding it, but I hope I’m not talking nonsense,
But what still bothers me is why I had an entry and an exit on the same candle?
04/20/2023 at 4:54 PM #213559entry and an exit on the same candle?
Entry Conditions = True and Exit Conditions = True … both in the same candle?
Very likely to occur with a Stop at 10 pips only?
04/20/2023 at 7:30 PM #213562what is the true Exit condition that you see pls ?,
Maybe you have a different eyes then me ?
Also the 10pips it’s just for the exemple, you can see in the photo just below inside the circle the both of entry and exit price are the same
I stopped from my bicycle for answer you 🤣🤣🤣, tks again for your answer 😊
04/20/2023 at 7:43 PM #213564Also the 10pips it’s just for the exemple
So what code are we discussing then
The screenshot with the circle shows entry and exit at the same price of 37120 … is that what we are discussing? If Yes, what code was driving that trade entry and exit?
Good bike, lovely evening, nice tree-lined avenue! 🙂
1 user thanked author for this post.
04/20/2023 at 8:40 PM #213565Hi,
if you use positionprice in the “set stop price” instruction sent at same time the buy order is sent, with no other ongoing long (as this code cumulates order) then your positionprice doesn’t exist yet (graph it you’ll see it at 0, and 0-10=-10), it will only exist after the buy is executed at open of next candle.
You can try this modification in the way you set the stop in your code:
if longonmarket then
SET STOP PRICE PositionPrice-10*pipsize
else
set stop price close-10*pipsize
endifAlso, you didn’t ask (and this is not related to the entry-exit in same candle query), but are you sure you want to send a pending order “at close limit”? Assuming this is for IG, if using pending order rather than at market order, you’d have to take into account minimum distance between price and pending order level for given asset…
2 users thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on