TradingView
Peter_O
7 de Jul. de 2021 11:52

Moving Stop-Loss mechanism + alerts to MT4/MT5 

Euro Fx/U.S. DollarFXCM

Descripción

"How to code moving stop-loss mechanism", is one of the most often repeating questions in private messages I receive, so just to focus on this mechanism, I made a spin-off from my previous script: TradingView-Alerts-to-MT4-MT5-dynamic-variables-NON-REPAINTING.

The logic here moves the stop-loss each time a trade is running and a new pivot high/low is detected. When such event occurs (UpdateLongStopLoss or UpdateShortStopLoss), stoploss_long or stoploss_short mutable variable is modified. And it needs to be coded inside strategy.exit() line as "stop=stoploss_long" or "stop=stoploss_short". Entries are pretty straightforward - on Stoch crosses.

Last lines of the script show how to wrap information about such updates and send send alerts to MetaTrader via TradingConnector for execution in Forex/indices/commodities/crypto markets via MetaTrader. Please note that "tradeid=" variable must be passed with each alert, to let MetaTrader know which trade to modify. SLMOD, TPMOD are recently added commands, along with BE (as in "move stop-loss to breakeven" - but that's another topic).

Please disregard strategy backtest results, as this script is for coding education purposes only. However, it seems with the stop-loss mechanism enabled, the results are even better, than in original version of the script :)

Notas de prensa

Thanks to the recent update of TradingConnectorEA to version 1.35, some functionalities and syntax of TradingConnector got simplified, and that's why I'm posting this update. To be exact:

If you're using Moving StopLoss mechanism ('slmod' command) and trading only 1 position at a time (no pyramiding), you don't need to use tradeid= parameter anymore. So it was removed from this script. Tradeid= functionality still exists and performs well - used to point which position exactly has to modified or closed - but is unnecessary coding overhead in single-position-trading. Previously it was required.

P.S. There are further new features, like multiple take-profit levels, breakeven exit, delay or separating from TradingConnector-dedicated alerts from all the others - these features will be covered in other publications soon.
Comentarios
incredibleinvention
Great work mate, this strategy is a gem. Is there a way to setup a stop losses to not exceed certain level, because as it is now loosing trades are way greater than the winning ones eating a profit away. I had tried many things but can’t find a way to do it, I am just starting with pine.
MasBart
can we use the Stop Loss for breakout ? for example if we are long, to use the short S/L as breakout?
Peter_O
@MasBart, for sure, but this would be completely different logic
intellisense
Girdiğin komisyon 0.00003 değil, emir başına binance : %0.04 :)) bu şekilde girince çıkan sonucu yayınla
Peter_O
@intellisense, For trading Forex with my broker, it is ok.
murat131
@intellisense, eğitim amaçlı hazırlanmış, stokastik de 13,3,4 değerlerini kullanmış, 13 gün ( 2 hafta) için seçilen değerler yanlış, yine 13 günlük momentle hareket ediyorsan en az 7 gün elinde tutmak zorundasın, o zamanda oraya 80 yukardan aşağıya girilmez, komisyon oranını binde4 yapsanda yapmasanda bisey kazandırmaz. Olaya eğitim için yazılmış olarak bakmak gerekiyor. ( en basta söylemiş zaten )
Más