Hi,
I’m having trouble getting my stop to be placed below the signal candle. Please can you tell me where i’m going wrong.
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// Conditions to enter long positions
c1 = (close > open)
indicator1 = Average[20](close)
c2 = (close > indicator1)
indicator2 = Average[20](close)
c3 = (low < indicator2)
IF c1 AND c2 AND c3 THEN
BUY 1 CONTRACT AT MARKET
ENDIF
slong = TRADEPRICE - low[0]
SET STOP LOSS slong
SET TARGET pPROFIT 100
If you put figures in you will see it? The heat today has switched my brain off, I will probably think what it should be when it gets cooler? 🙂
slong = 10000 – 9800
SET STOP LOSS 200
slong = TRADEPRICE - (TRADEPRICE - low[0])
SET STOP LOSS slong
Tradeprice is an absolute price / the price that the position was opened at. Thus you can’t reference LOW because LOW relates to a candle and not Tradeprice – I think. What you have to do is reference the LOW of the bar when it was opened. What i think your looking for is Tradeindex.
Forget my previous at #36725 (the heat really did addle my brain! :)).
You need to record / use the low at the time of the Trade so the definition of slong at time of Buy needs to be bounded by the If Endif statement as below.
Try it anyway and let us know please?
IF c1 AND c2 AND c3 THEN
BUY 1 CONTRACT AT MARKET
slong = TradePrice - Low
ENDIF
SET STOP pLOSS slong
Hello community,
I am looking for approximately the same request than Kage12 but instead of using the low of the signal candlestick as a stop, I would like to use the low of the day before the signal.
I tried to edit the code that Grahal sent but my version doesn’t seem to work as some orders are closed without touching the low of the day before the signal (please find attached a screenshot).
IF c1 THEN
BUY 1 CONTRACT AT MARKET
slong = TradePrice - Low[1]
ENDIF
SET STOP pLOSS slong
Please note that below the last line of my code, i’ve got some conditions to close my positions. The stop loss i’m asking would be used as a protective stop and to optimize my money management.
Also, i’v tried the original version that Grahal sent and the orders are closed the same day of the signal so if you also have a solution to fix that, l would be very interested to run some backtest.
Thank you in advance and have a great day !
Valentin
GraHal is right about IF..ENDIF.
But you should replace line 3 with
slong = close - Low
because
- TRADEPRICE will be known the next bar
- when you BUY/SELLSHORT at market the price will be the current one, that is CLOSE (+- some gap and/or slippage).
Assuming you are running on a Daily TF, does below work?
IF c1 THEN
BUY 1 CONTRACT AT MARKET
Sell at Low[1] Stop
ENDIF
Yes it will work, but keep in mind that:
- the STOP pending order will only last for 1 bar each time c1 is true
- Low[1] is the candle low at bar n-1, the bar before the c1 signal
Thank you a lot for your help Gentlemen! This is was I needed for few of my strategies.
Have a great day!