0

I have my strategy set however I would like to test entering trades when a candlestick crosses over the hma49 by a specific amount of ticks. Such as 4. Can I make this an input so I can adjust the amount of ticks above the hma49 ? This would be great for testing. I'm sure there must be a way to code this but I have googled and tried many times and can't figure it out. Any help on this one would be so awesome. I'm without a way to get there on my own.

//@version=4
strategy ("15MinChart400", overlay=true)

hma23 = hma(close, 23)
hma49 = hma(close, 49)
hma16 = hma(close, 16)
hma200 = hma(close, 200)
hma400 = hma(close, 400)
CO =  crossover(hma49, 4 * syminfo.mintick)  

long = CO and close >= hma49
exitLong = close <= hma49 

//Second Attempt and now in need of Candlestick lookback

hma49 = hma(close, 49)
ticks = input(4)
tickPrice = hma49 + ticks * syminfo.mintick
lookback = input(4, "Candlestick Lookback")
CL = close[lookback]

long = crossover(close,tickPrice) and crossover(close,hma49) and CL
exitLong = close <= hma49

This was my attempt but it doesn't work.

Any help would be greatly appreciated!

Big thanks,

Paul

Paul Cas
  • 39
  • 7
  • Ok I've got this far now I'm just in need of a candlestick lookback as the long condition is missing some entry opportunities! Ive got this far. Had to adjust the long position to make sure that the entry point is on a a bar crossing hma49 only. I have placed my progress on the code above in the original posted question. – Paul Cas Sep 06 '21 at 00:27
  • It's not necessary to use the crossover. You can also just use `open < hma49` instead of `crossover(close, hma49)`. If the bar opened below the hma and close goes above tickPrice, it has also done the crossover. It isn't really clear what you're trying to achieve with CL. The crossover() functions return a boolean (true/false), while CL is the closing price 4 bars back – rumpypumpydumpy Sep 06 '21 at 01:04

1 Answers1

0

With the crossover, you'll want to evaluate when the close price has crossed over the hma49 value + ticks.

ticks = input(4)

hma49 = hma(close, 49)

tickPrice = hma49 + ticks * syminfo.mintick

long = crossover(close, tickPrice)  
exitLong = close <= hma49

strategy.entry(id = "enter long", long = true, when = long)
strategy.close(id = "enter long", when = exitLong)

Or if you were looking at evaluating whether the price crossed over the hma + ticks during the bar, but closed anywhere above the hma you would use

long = open < tickPrice and high > tickPrice and close >= hma49
rumpypumpydumpy
  • 3,435
  • 2
  • 5
  • 10