set stoploss from tradeprice to the lowest of 5 candles plus spread
Forums › ProRealTime English forum › ProOrder support › set stoploss from tradeprice to the lowest of 5 candles plus spread
- This topic has 5 replies, 2 voices, and was last updated 3 years ago by
robertogozzi.
-
-
03/02/2021 at 2:06 AM #162911
hi,
i am trying to add a stop loss when going long when the candle crosses the 200ma. the stop loss is meant to be under the lowest of the last 5 candles when i have gone long. somehow it is not placing any stop loss.
12345678910111213141516indicator1 = Average[200](close)longc1 = (low CROSSES UNDER indicator1)longc2 = (close CROSSES UNDER indicator1)bullcandle = (open<close)period = 5for a = 0 to period -1IF (longc1[a] or longc2[a]) and not onmarket[a] thenif bullcandle and close crosses over indicator1 thenbuy 1 contracts at marketlongstoploss = (tradeprice - lowest[5](low) + 0.002)*pipsizeset stop ploss longstoplossendifbreakENDIFnext03/02/2021 at 2:23 AM #162912Replace TRADEPRICE with CLOSE in line 11, since it takes a whole candle for it to be known. Using CLOSE may not exactly the same, due to slippage (if any), but it’s thfe only known entry price at that moment. TRADEPRICE is either 0 (if it’s the first trade) or the exit price of the prior trade.
Next candle, if you want to be more accurate, you can recalculate your SL. But this is usually not necessary.
03/02/2021 at 2:28 AM #162913i changed the tradeprice to close and whenever i open a position it is closing immediately
03/02/2021 at 2:36 AM #162914longstoploss is always zero but when i check the individual values of close, and lowest[5](low) and do the math myself, its not equal to zero.
03/02/2021 at 8:14 AM #162915i solve it. line 11 replace with
1longstoploss = (close - lowest[5](low)+0.0002)*10000it was pipsize command. i thought it converts the number in the bracket to pips.
03/02/2021 at 8:46 AM #162918Yes, you are right. You have to divide by PipSize:
1longstoploss = (tradeprice - lowest[5](low) + 0.002)/pipsize -
AuthorPosts
Find exclusive trading pro-tools on