0

Please, I need some advice about the strategy to follow, commands to use, etc. . . to get the minimum value of a set (for example 3) of japanese candles around a crossover of moving averages in order to set there my stop-loss and indicate somehow the candle in which this minimum value is given: https://imgur.com/a/qjltm6T

This is the code I am developing at the moment. This is a small part of a bigger one: https://i.stack.imgur.com/bvLg5.jpg

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Dark_Trader-x01
 
//@version=4
strategy("SL_around_cross", overlay=true)
 
 
// DECLARACION DE VARIABLES
var float sl = na
 
 
// EMAs
EMA_9 = ema(close, 9)
EMA_21 = ema(close, 21)
EMA_100 = ema(close, 100)
 
 
// CONDICION CRUCE EMAs
cruce_BUY = crossover(EMA_9, EMA_21)
cruce_SELL = crossunder(EMA_9, EMA_21)
 
 
// STOP-lOSS
if cruce_BUY
    sl := lowest(close, 3) 
 
 
// TAKE PROFIT
 
 
// ESTRATEGIA
/// ALCISTA
//strategy.entry("BUY", true, 2000, when = candle_BUY_activada)
//strategy.close("BUY", when = cruce_SELL)
/// BAJISTA
//strategy.entry("SELL", false, 2000, when = candle_SELL_activada)
//strategy.close("SELL", when = cruce_BUY)
 
 
// PLOTS
plotshape(cruce_BUY, style=shape.arrowup, text="cruce_BUY", location=location.belowbar, color=color.green)
plotshape(cruce_SELL, style=shape.arrowdown, text="cruce_SELL", location=location.abovebar, color=color.red)

Any advice will be welcome!

Thank you in advance!

1 Answers1

0
//@version=4
strategy("My Strategy", overlay=true, margin_long=100, margin_short=100)

ema10 = ema(close, 10)
ema20 = ema(close, 20)
cross = crossover(ema10, ema20)

plotchar(cross, "*")

With this cross you can get minimum values with lowest() function, e.g.

var float sl = na 
if cross
    sl := lowest(close, 3) 

to get min value of close 3 bars back before crossover.

Starr Lucky
  • 1,578
  • 1
  • 7
  • 8