I asked chatgpt to create a strategy for me based on the three strike lines. He did it without any problem, but then I get stuck because the strategy doesn't take buy and sell orders. On the indications in the form of triangles, after several attempts I can't find a prompt to correct the problem with chatGPT. Does someone on the forum have a solution, because I've spent hours on this with no result.
//@version=5
strategy("Backtest 3 Line Strike Strategy", overlay=true)
// Variables for tracking position status
var bool isLongPositionOpen = na
var bool isShortPositionOpen = na
// Entry and exit rules based on green and red arrows
longCondition = ta.crossover(close, open)
shortCondition = ta.crossunder(close, open)
// Function to close all open positions
closeAllPositions() =>
strategy.close("Long", comment="Exit Long")
strategy.close("Short", comment="Exit Short")
// Update status of open positions
if longCondition
isLongPositionOpen := true
if shortCondition
isShortPositionOpen := true
// Check entry and exit conditions
if longCondition and not isLongPositionOpen
strategy.entry("Long", strategy.long)
isLongPositionOpen := true
isShortPositionOpen := false // Close any short position when entering a long position
strategy.order("sell", strategy.short) // Place a sell order to exit any short position
if shortCondition and not isShortPositionOpen
strategy.entry("Short", strategy.short)
isShortPositionOpen := true
isLongPositionOpen := false // Close any long position if you enter a short position
strategy.order("buy", strategy.long) // Place a buy order to exit any long position
// Exit all open positions if an opposite arrow appears
if (longCondition and isShortPositionOpen) or (shortCondition and isLongPositionOpen)
closeAllPositions()
isLongPositionOpen := false
isShortPositionOpen := false
// Plot green and red arrows on graph
plotshape(longCondition, style=shape.triangleup, color=color.green, location=location.belowbar, size=size.small, title="3s-Bull")
plotshape(shortCondition, style=shape.triangledown, color=color.red, location=location.abovebar, size=size.small, title="3s-Bear")