I am wanting to enter the stop loss, entry (limit) and take profit prices into a strategy.
I have plotted the above 3 markers out to start with:
float shortStopLoss = 1.065
float shortEntry = 1.064
float shortTakeProfit = 1.061
plot(shortStopLoss, "Stop", color.red, 2, plot.style_linebr)
plot(shortEntry, "Entry 1", color.white, 2, plot.style_linebr)
plot(shortTakeProfit, "Limit 1", color.green, 2, plot.style_linebr)
The markers show the correct positions on the chart.
The price of the markers, however, are slightly different to the values outputted in the logs (shown above):
Using the same three variables (shortStopLoss
, shortEntry
, shortTakeProfit
) within:
strategy.entry("Enter short LH", strategy.short, limit = shortEntry, qty = 1)
strategy.exit("Exit Short LH", from_entry = "Enter short LH", stop = shortStopLoss, profit = shortTakeProfit)
They're completely misaligned on the chart, i.e. wrong stop loss position, take profit position etc:
Why is this? Thank you for your help.
Your use of profit
in strategy.exit()
is incorrect. You are specifying price value, however, profit
expects values in ticks
. This causes your trades to be closed immediately because being 1 tick in profit is very likely to happen on the next bar.
You should be using the limit
argument, instead.
Secondly, you should double check your usage of limit
in strategy.entry()
. You might want to use stop
instead. Or a combination of both. Or just the limit
. Just check that based on your requirements.