0% found this document useful (0 votes)
36 views1 page

Infinity Grid Trading Bot Script

Uploaded by

Helio Lopes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views1 page

Infinity Grid Trading Bot Script

Uploaded by

Helio Lopes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

//@version=5

strategy("Infinity Grid Trading Bot", overlay=true)

// Define strategy parameters


capital = strategy.equity
gridSize = 0.01 // Grid size as a percentage of the asset price
takeProfit = 0.01 // Take profit as a percentage of the asset price
stopLoss = 0.01 // Stop loss as a percentage of the asset price
riskPerTrade = 0.01 // Risk per trade as a percentage of the capital

// Calculate grid levels


gridLevels = math.ceil(1 / gridSize)
gridStep = 1 / gridLevels

// Calculate position size based on risk per trade


positionSize = riskPerTrade * capital / stopLoss

// Calculate target profit and stop loss levels


targetProfit = close * (1 + takeProfit)
stopLossLevel = close * (1 - stopLoss)

// Calculate the current grid level


currentGridLevel = math.floor((close - close[1]) / gridStep)

// Check if a new grid level is reached


isNewGridLevel = currentGridLevel != currentGridLevel[1]

// Buy condition: price crosses above the target profit level


buyCondition = crossover(close, targetProfit) and isNewGridLevel

// Sell condition: price crosses below the stop loss level


sellCondition = crossunder(close, stopLossLevel) and isNewGridLevel

// Place buy and sell orders


if buyCondition
strategy.entry("Buy", strategy.long, qty=positionSize)
if sellCondition
strategy.close("Buy")

// Plot grid levels


plotshape(isNewGridLevel, title="Grid Level", location=location.belowbar,
color=color.green, style=shape.labelup, text="Grid Level")

// Plot target profit and stop loss levels


plot(targetProfit, title="Target Profit", color=color.green, linewidth=2)
plot(stopLossLevel, title="Stop Loss", color=color.red, linewidth=2)

You might also like