Untitled

 avatar
unknown
plain_text
7 months ago
1.4 kB
5
Indexable
//@version=5
indicator("Auto Trade on Line Cross", shorttitle="Trade on Line", overlay=true)

// Input variables
var priceLine = input.float(0, "Price Line", step=0.1) // Line to trigger trade
var tradeSize = input.float(1, "Trade Size", step=0.01) // Size of the trade
var stopLoss = input.float(0, "Stop Loss", step=0.1) // Stop loss level below entry
var takeProfit = input.float(0, "Take Profit", step=0.1) // Take profit level above entry

// Plot the price line
hline(priceLine, title="Trigger Line", color=color.red, linestyle=hline.style_dotted)

// Variables for tracking trades
var isTradeOpen = false
var entryPrice = na

// Check if the price crosses above the line
if not isTradeOpen and close > priceLine
    // Enter trade logic
    entryPrice := close
    isTradeOpen := true
    label.new(bar_index, high, "Buy", color=color.green, textcolor=color.white)

// Check Stop Loss and Take Profit conditions
if isTradeOpen
    if close <= entryPrice - stopLoss or close >= entryPrice + takeProfit
        // Exit trade logic
        isTradeOpen := false
        label.new(bar_index, low, "Exit", color=color.red, textcolor=color.white)

// Display trade details
bgcolor(isTradeOpen ? color.new(color.green, 90) : na)

alertcondition(close > priceLine, title="Price Line Cross", message="Price crossed above the trigger line!")
Editor is loading...
Leave a Comment