Strategy example

Breakout Strategy v2

Readonly source from tests/EasyLanguage/dorian-draper-learning, generated Pine Script v6, and an expiry-free example EX5.

Original EasyLanguage

  1. {-------------------------------------------------------------------
  2. Breakout v2
  3. Description:
  4. - Improve legibility and semantic intention of Breakout v1
  5. - Prepare code for future extensions (filters, risk management, post-analysis)
  6. -------------------------------------------------------------------}
  7. Inputs:
  8. LongPrice(High),
  9. LongLen(8),
  10. ShortPrice(Low),
  11. ShortLen(8),
  12. EntryBuffer(.02);
  13. Vars:
  14. LongBreakout(0),
  15. ShortBreakout(0);
  16. {🧮 Cálculo de niveles de ruptura}
  17. LongBreakout = Highest(LongPrice, LongLen) + EntryBuffer;
  18. ShortBreakout = Lowest(ShortPrice, ShortLen) - EntryBuffer;
  19. {🚀 Setup de entrada}
  20. Buy ("Brk LE") Next Bar at LongBreakout Stop;
  21. SellShort ("Brk SE") Next Bar at ShortBreakout Stop;

Generated Pine Script v6

  1. //@version=6
  2. strategy("Breakout_v2", overlay=true)
  3. longprice = input.source(high, "longprice")
  4. longlen = input.float(8.0, "longlen")
  5. shortprice = input.source(low, "shortprice")
  6. shortlen = input.float(8.0, "shortlen")
  7. entrybuffer = input.float(.02, "entrybuffer")
  8. var float longbreakout = 0
  9. var float shortbreakout = 0
  10. __el_call1 = ta.highest(longprice, int(longlen))
  11. __el_call2 = ta.lowest(shortprice, int(shortlen))
  12. if bar_index >= 7
  13. longbreakout := __el_call1 + entrybuffer
  14. shortbreakout := __el_call2 - entrybuffer
  15. strategy.entry("Brk LE", strategy.long, stop=longbreakout)
  16. strategy.entry("Brk SE", strategy.short, stop=shortbreakout)

Compiled MetaTrader 5 example

The EX5 uses the original script filename stem and has no PineAnywhere expiration guard.

Download Breakout_v2.ex5
An unexpected error occurred. Reload×

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.