Hi,
I’m starting to use probacktest, I can’t find a way to put the stop loss below the candle where a long position is opened, or above the candle of a short position.
Thanks for the help!
Dave
There you go:
IF Not OnMarket THEN
// LONG entry
IF MyLongConditions THEN
BUY 1 CONTRACT AT MARKET
SET STOP PRICE (low - 1*PipSize)
ENDIF
// SHORT entry
IF MyShortConditions THEN
SELLSHORT 1 CONTRACT AT MARKET
SET STOP PRICE (high + 1*PipSize)
ENDIF
ENDIF
JSParticipant
Senior
Maybe as a supplement…
A (classic) “Set Stop Loss” is always calculated from the (average) price at which the position is opened…
Set Stop pLoss 10 will place a stop loss of 10 points/pips below the purchase price of your “long” position or 10 points/pips above the purchase price of your “short” position…
If you don’t want to use points/pips but prefer a price level, you can use “Set Stop Price”…
Set Stop Price Low will place a stop loss on the price level of the “Low” of the previous candle…
Set Stop Price High will place a stop loss at the price level of the “High” of the previous candle…
Thank you for both messages! Now it’s clear.
I would also like to understand how to set a take profit order when a certain price level is touched and not after the bar/candle is closed.
For example, I would like to set the take profit order as soon as the MA20 is touched.
Just use: “set plimit X” for a profit limit order.
One thing to keep in mind tho, if you trade in IG ther are minimum stopp loss and trailing stopp so if you use “Low” and its to close to tradeprice the order will be rejected.
Hi Niklas, thanks for your answer.
IG minimum distance for the stop order isn’t a problem so far since I’m only using probacktest to test strategies, I do not use automatic trading now.
So, can you make an example on how to use “set plimit X” with an indicator, as an example the MA20?
Also, if possible I’d like to experiment with targets which are multiples of the stop loss. For a long position that would be, assuming I enter on the close of the bar, CLOSE-LOW. How the formula would be written in the code?