OPEN-SOURCE SCRIPT

Mahnam BTC with breake out

229
This strategy is designed and coded specifically for trading Bitcoin in the 15-minute timeframe.
Of course, those who are skilled in coding can use it in other timeframes and currencies by changing its codes and personalizing it.
Of course, it is strongly recommended that people who want to use it first perform the necessary backtests or test this strategy on demo sites and then trade on the Tetri platform.
In this strategy, it only checks the entry and exit conditions and connects to the exchange using the API code and trades completely automatically.
This strategy determines the stop loss and take profit points on the exchange at the same time as entering the transaction and sets them.

///////////////////////// Code ////////////////////////////////
//version=5
// Copyright (c) 2021-present, Alex Orekhov (everget)
//indicator('HalfTrend and TMA', overlay=true , max_lines_count = 500, max_labels_count = 500)
strategy(title='Mahnam BTC with breake out', overlay=true , max_bars_back=5000 , max_labels_count= 500 , max_boxes_count = 500,max_lines_count = 500, initial_capital=1000, currency = currency.USDT, default_qty_type=strategy.cash )
import PineCoders/Time/4

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

newyork = '0000-2400' // input.session(title='Session', defval='0000-2400')

time_newyork = time(timeframe.period, newyork)


///////////////////////////////////////////////////////////////////////////////////////////////////////////

// تعیین تاریخ شروع و پایان (بر حسب timestamp یونی‌کس)
// تنظیمات Input برای تاریخ شروع و پایان
startDate = input.time(timestamp('01 Jan 2025 00:00 UTC'), "📅 تاریخ شروع معاملات", inline="dateRange")
endDate = input.time(timestamp('31 Dec 2025 23:59 UTC'), "📅 تاریخ پایان معاملات", inline="dateRange")

// بررسی اینکه آیا زمان فعلی در بازه مجاز است یا خیر
isTradeEnabled = (time >= startDate) //and (time <= endDate)
///////////////////////////////////////////////////////////////////////////////////////////
// currentTime = time("15", "GMT+0")
// hourOfDay = hour(currentTime)
// notrade_hours1 = input.(12 , minval = 0 , maxval = 24 , title = "Hours Friday")
// notrade_hours2 = input.int(12 , minval = 0 , maxval = 24 , title = "Hours Monday")
////////////////////////////////////////////////////////////Holidays/////////////////////
// تعریف روزهای هفته
isSaturday = dayofweek == dayofweek.saturday //and hourOfDay > 12
isSunday = dayofweek == dayofweek.sunday
// isMonday = dayofweek == dayofweek.monday and hourOfDay < notrade_hours1
// isFriday = dayofweek == dayofweek.friday and hourOfDay > notrade_hours2


// رنگآمیزی پسزمینه برای شنبه (آبی کمرنگ) و یکشنبه (نارنجی کمرنگ)
bgcolor(isSaturday ? color.new(color.blue, 90) : isSunday ? color.new(color.orange, 90) : na)
//bgcolor(isMonday ? color.new(color.white, 90) : isFriday ? color.new(color.green, 90) : na)

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


//تنظیمات پوزیشن

leverage = input.int(defval = 10 , title = "leverage" , minval = 1 , maxval = 20,step = 5 , group="Posistion Settings==========================================")
quantity = input.float(defval = 500 , title = "quantity" , minval = 1, group="Posistion Settings==========================================")
sl_manager = input.float(defval = 0.5 , step = 0.1 , title = "Risk Percent Of Capital", group="Posistion Settings==========================================")
persent_fee = input.float(defval = 0.05 , title = "Persent Fee Eexchange" , minval = 0 , maxval = 1,step = 0.01 , group="Posistion Settings==========================================")
position_type = input.string(defval = "Buy_And_Sell" , title = "Position_type" , options = ["Buy" , "Sell" , "Buy_And_Sell"], group="Posistion Settings==========================================" )

r_r_long = input.float(defval = 2 , step = 0.1 , title = "R - R =>", group="Posistion Settings==========================================")
r_r_short = r_r_long // input.float(defval = 1.8 , step = 0.1 , title = "r_r Short =>")

//////////////////////////////////////////////////////// END ROC /////////////////////////////////////

day_of_week = input.bool(false , title = "Trade in 7 days", group="Posistion Settings==========================================")
show_tp_sl_ent = true // input.bool(defval=true, title= "Show Tp Sl Ent Box", group="Posistion Settings==========================================")
show_qty = true // input.bool(defval = true , title = "Show Qty Label", group="Posistion Settings==========================================")


//////////////////////////////////////////////////////// Information Position ////////////////////////////////////////////////////

var short_is_open = false
var long_is_open = false

//variant for sell position
var sl1 = 0.0
var tp1 = 0.0
var ent1 = 0.0
var equity1 = 0.0
var qty1 = ""

//variant for buy position
var sl3 = 0.0
var qty2 = ""
var tp3 = 0.0
var ent2 = 0.0
var equity2 = 0.0

symbol = str.tostring(syminfo.basecurrency + "-" + syminfo.currency )




////////////////////////////////////////////////////////////////////////////////////////////////////////

var long_condition = false
var short_condition = false

persent_candel = 0.7 // input.float(defval = 0.7 , step = 0.1 , title = "درصد حرکت آخرین کندل", group="CANDEL Settings==========================================")

////////////////////////////////////////////////////////////////////////////////////////////////////////

amplitude = 2 // input.int(title='Amplitude', defval=2)
channelDeviation =2 //input.int(title='Channel Deviation', defval=2)
showChannels =true // input.bool(title='Show Channels', defval=true)

var int trend = 0
var int nextTrend = 0
var float maxLowPrice = nz(low[1], low)
var float minHighPrice = nz(high[1], high)

var float up = 0.0
var float down = 0.0
float atrHigh = 0.0
float atrLow = 0.0
float arrowUp = na
float arrowDown = na
len_atr = 130 // input.int(130 , title = "Len Half Trend")
atr2 = ta.atr(len_atr) / 2
dev = channelDeviation * atr2

highPrice = high[math.abs(ta.highestbars(amplitude))]
lowPrice = low[math.abs(ta.lowestbars(amplitude))]
highma = ta.sma(high, amplitude)
lowma = ta.sma(low, amplitude)

if nextTrend == 1
maxLowPrice := math.max(lowPrice, maxLowPrice)

if highma < maxLowPrice and close < nz(low[1], low)
trend := 1
nextTrend := 0
minHighPrice := highPrice
minHighPrice
else
minHighPrice := math.min(highPrice, minHighPrice)

if lowma > minHighPrice and close > nz(high[1], high)
trend := 0
nextTrend := 1
maxLowPrice := lowPrice
maxLowPrice

if trend == 0
if not na(trend[1]) and trend[1] != 0
up := na(down[1]) ? down : down[1]
arrowUp := up - atr2
arrowUp
else
up := na(up[1]) ? maxLowPrice : math.max(maxLowPrice, up[1])
up
atrHigh := up + dev
atrLow := up - dev
atrLow
else
if not na(trend[1]) and trend[1] != 1
down := na(up[1]) ? up : up[1]
arrowDown := down + atr2
arrowDown
else
down := na(down[1]) ? minHighPrice : math.min(minHighPrice, down[1])
down
atrHigh := down + dev
atrLow := down - dev
atrLow





//////////////////////////////////////////////////////////////////////////////////////////////////////////
len_rsi = 14 // input.int(14, group = "RSI Setting=================================")
rsi = ta.rsi(close , len_rsi)



//////////////////////////////////////////////////////////////////////////////////
// محاسبات مربوط به تعیین خطوط حمایت و مقاومت و شکست آنها
show_ATR = input.bool(false)
lookback_15 = 4 // input.int(4, title = "====>Look Back 1H=====>", inline = "2", group = "Setting Pivot======================", tooltip = "Drawing support and resistance in time frame 15 min in selected look back")

pl60 = fixnan(ta.pivotlow( low , lookback_15 , lookback_15 ))
ph60 = fixnan(ta.pivothigh( high , lookback_15 , lookback_15 ))

plot(show_ATR ? pl60 : na , color = color.red)
plot(show_ATR ? ph60 : na , color = color.green)

//////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////
len_ema_fast_long = 2 // input.int(2)
sorce_tma_long = low // input.source(low)
ema_fast_long = ta.ema(sorce_tma_long , len_ema_fast_long)

len_ema_slow_long = 25 // input.int(25)
ema_slow_long = ta.ema(sorce_tma_long , len_ema_slow_long)

//**********************************
len_ema_fast_short = 2 // input.int(2)
sorce_tma_short = high // input.source(close)
ema_fast_short = ta.ema(sorce_tma_short , len_ema_fast_short)

len_ema_slow_short = 25 // input.int(25)
ema_slow_short = ta.ema(sorce_tma_short , len_ema_slow_short)



///////////////////////////////////////////////////////////////////////////////////////////////////////////

bars = 2 // input.int(9,title="Volume Previous bars to check")
//one_side = input.bool(false, title="Positive values only")
float volume_up = 0
float volume_down = 0
for i = 0 to bars
if (close>open)
volume_up:=volume_up+volume
else
volume_down:=volume_down+volume

total_up_down_vol= volume_up-volume_down
vol_bb = 8 // input.int(8)
vol_aa = 2 // input.int(2)
pivot_high_vol = fixnan(ta.pivothigh(total_up_down_vol , vol_bb , vol_aa ))
pivot_low_vol = fixnan(ta.pivotlow(total_up_down_vol , vol_bb , vol_aa ))


///////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////

CLOSE = close
LOW = low
HIGH = high




//////////////////////////////////////////////////////////////////////////////////
//
//reg_trend_on = input(true, 'Activate Reg Trend Line')
length_bull_bear = 4 // input.int(defval= 4, title='🔹 Length Reg Trend line=', minval=1)
//
BullTrend_hist = 0.0
BearTrend_hist = 0.0

BullTrend = (CLOSE - ta.lowest(LOW, length_bull_bear)) / (ta.sma(ta.tr(true), length_bull_bear ))
BearTrend = (ta.highest(HIGH, length_bull_bear) - CLOSE) / (ta.sma(ta.tr(true), length_bull_bear ))
BearTrend2 = -1 * BearTrend

Trend = BullTrend - BearTrend


// plot columun
if BullTrend < 2
BullTrend_hist := BullTrend - 2
BullTrend_hist

if BearTrend2 > -2
BearTrend_hist := BearTrend2 + 2
BearTrend_hist
//alexgrover-Regression Line Formula
x = bar_index
y = Trend
x_ = ta.sma(x, length_bull_bear)
y_ = ta.sma(y, length_bull_bear)
mx = ta.stdev(x, length_bull_bear)
my = ta.stdev(y, length_bull_bear)
c = ta.correlation(x, y, length_bull_bear)
slope = c * (my / mx)
inter = y_ - slope * x_
reg_trend = x * slope + inter


/////////////////////////////////////////////////
long2 = true
short2 = true

close_H = request.security("" , "" , close[1])
open_H = request.security("" , "" , open[1])
if close_H[1] > open_H[1] and close_H[2] > open_H[2]
short2 := false

if close_H[1] < open_H[1] and close_H[2] < open_H[2]
long2 := false

nnn = 1.4 // input.float(1.4 , step = 0.1)
long_1 = BullTrend > nnn and ta.sma(reg_trend , 4 ) > ta.sma(reg_trend , 8 )
short_1 = BearTrend2 < -nnn and ta.sma(reg_trend , 4 ) < ta.sma(reg_trend , 8 )
///////////////////////////////////////////////////

lensig_mdi = 8 // input.int(8, title="ADX Smoothing", minval=1)
len_mdi = 2 // input.int(2, minval=1, title="DI Length")
up_mdi = ta.change(high)
down_mdi = -ta.change(low)
plusDM = na(up_mdi) ? na : (up_mdi > down_mdi and up_mdi > 0 ? up_mdi : 0)
minusDM = na(down_mdi) ? na : (down_mdi > up_mdi and down_mdi > 0 ? down_mdi : 0)
trur_mdi = ta.rma(ta.tr, len_mdi)
plus_mdi = fixnan(100 * ta.rma(plusDM, len_mdi) / trur_mdi)
minus_mdi = fixnan(100 * ta.rma(minusDM, len_mdi) / trur_mdi)
sum = plus_mdi + minus_mdi
adx = 100 * ta.rma(math.abs(plus_mdi - minus_mdi) / (sum == 0 ? 1 : sum), lensig_mdi)
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// تنظیمات SuperTrend
atrPeriod = 28 // input(28, title="ATR Period Super Trend")
factor = 3 // input(3.0, title="Multiplier")
[supertrend, direction] = ta.supertrend(factor, atrPeriod)

// تعریف تایمفریمهای بالاتر
htf0 = "30" // input.timeframe("30", title="تایمفریم تأیید اول (1H)")
htf1 = "60" // input.timeframe("60", title=" ایمفریم تأیید دوم (1H)")
htf2 = "240" // input.timeframe("240", title="تایمفریم تأیید سوم (4H)")

// محاسبه SuperTrend در تایمفریمهای بالاتر
supertrend1 = request.security(syminfo.tickerid, htf0, supertrend)
direction1 = request.security(syminfo.tickerid, htf0, direction)


supertrend1H = request.security(syminfo.tickerid, htf1, supertrend )
direction1H = request.security(syminfo.tickerid, htf1, direction)

supertrend4H = request.security(syminfo.tickerid, htf2, supertrend )
direction4H = request.security(syminfo.tickerid, htf2, direction)

// شرایط ورود
Condition_supertrend_long = (direction1H > 0 or direction4H > 0 or direction1 > 0) and volume > fixnan(ta.pivotlow(volume , 16 , 2 ))
Condition_supertrend_short = (direction1H < 0 or direction4H < 0 or direction1 < 0) and volume > fixnan(ta.pivotlow(volume , 16 , 2 ))
//////////////////////////////////////////////////////////////////////////////////////////////////////////
open_4h = request.security("" , "240" , open[1])
close_4h = request.security("" , "240" , close[1])


//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
if day_of_week == false
if isTradeEnabled == true and time == time_newyork and not isSaturday and not isSunday //and not isFriday and not isMonday

long_condition := long_is_open == false and short_is_open == false and total_up_down_vol > pivot_low_vol and rsi > 51 and rsi < 80
and math.abs(close - open) < (persent_candel/100) * close and ema_fast_long > ema_slow_long and high > ph60 and open < ph60 and long_1 == true and long2 == true
and plus_mdi > minus_mdi and Condition_supertrend_long == true and high > close_4h and close > atrHigh


short_condition := long_is_open == false and short_is_open == false and total_up_down_vol > pivot_low_vol and rsi < 49 and rsi > 20
and math.abs(close - open) < (persent_candel/100) * close and ema_fast_short < ema_slow_short and low < pl60 and open > pl60 and short_1 == true and short2 == true
and plus_mdi < minus_mdi and Condition_supertrend_short == true and low < close_4h and close < atrLow




if day_of_week == true
if isTradeEnabled == true and time == time_newyork
long_condition := long_is_open == false and short_is_open == false and total_up_down_vol > pivot_low_vol and rsi > 51 and rsi < 80
and math.abs(close - open) < (persent_candel/100) * close and ema_fast_long > ema_slow_long and high > ph60 and open < ph60 and long_1 == true and long2 == true
and plus_mdi > minus_mdi and Condition_supertrend_long == true and high > close_4h and close > atrHigh


short_condition := long_is_open == false and short_is_open == false and total_up_down_vol > pivot_low_vol and rsi < 49 and rsi > 20
and math.abs(close - open) < (persent_candel/100) * close and ema_fast_short < ema_slow_short and low < pl60 and open > pl60 and short_1 == true and short2 == true
and plus_mdi < minus_mdi and Condition_supertrend_short == true and low < close_4h and close < atrLow




////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//تنظیمات استاپ سل پوزیشن شورت و لانگ بر اساس ATR

length_atr = 2 // input.int(title='Length', defval=2, minval=1, group = "StopLoss Setting=================================")

m = 0.9 // input.float(0.9,step = 0.1,title = 'Multiplier', group = "StopLoss Setting=================================")
show_atr = false // input.bool(false, group = "StopLoss Setting=================================")
src1_atr = high //input(high , title = "Stoploss Short")
src2_atr = low //input(low ,title = "Stoploss Long")



collong_atr = color.rgb(0,255,0,0)
colshort_atr = color.rgb(255,0,0,0)



a1 = (ta.sma(ta.tr(true), length_atr) * m) / 2 + (ta.wma(ta.tr(true), length_atr) * m) / 2

stop_loss_short = src1_atr + a1
stop_loss_long = src2_atr - a1

p1_atr1 = plot(show_atr ? stop_loss_long : na, title='ATR Short Stop Loss', color=colshort_atr, style=plot.style_circles)
p2_atr1 = plot(show_atr ? stop_loss_short : na, title='ATR Long Stop Loss', color=collong_atr, style=plot.style_circles)



/////////////////////////////////////////////////////////////////Start Stop Loss///////////////////////////////////////////////
/////////////////////////////////////////////////////////////////END Stop Loss///////////////////////////////////////////////
var total_long_trade = 0
var loss_long = 0
var profit_long = 0
var sood_pos_long = 0.00
var zarar_pos_long = 0.00
var kol_sood_long = 0.00

var total_short_trade = 0
var loss_short = 0
var profit_short = 0
var sood_pos_short = 0.00
var zarar_pos_short = 0.00
var kol_sood_short = 0.00
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


// ━━━━━━━━━━━━━━━━━━ تنظیمات ورودی ━━━━━━━━━━━━━━━━━━
var int candlesToWait = 12 // input.int(1, "تعداد کندل‌های انتظار پس از معامله", minval=1)

// ━━━━━━━━━━━━━━━━━━ شناسایی آخرین معامله ━━━━━━━━━━━━━━━━━━
var int lastTradeCloseBar = na
var bool isCoolDownOver = true

// اگر معامله‌ای بسته شد، شماره کندل آن را ذخیره کن
if strategy.closedtrades > 0 and (na(lastTradeCloseBar) or strategy.closedtrades != strategy.closedtrades[1])
lastTradeCloseBar := bar_index
isCoolDownOver := false

// بررسی آیا تعداد کندل‌های موردنظر گذشته است؟
if not na(lastTradeCloseBar) and (bar_index - lastTradeCloseBar) >= candlesToWait
isCoolDownOver := true

bgcolor(isCoolDownOver ? na : color.new(color.red, 90), title="Cooldown Status")
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// تنظیمات دستورات لازم برای ارسال به صرافی جهت پوزیشن لانگ
//ADD_quantity = 1.5 // input.float(2 , title = "در صورت واگرایی ماجین رو چند بابر کنم؟")
if position_type == "Buy" or position_type == "Buy_And_Sell"


if long_condition and isCoolDownOver


ent2 := close
sl3 :=stop_loss_long - (stop_loss_long * (0.5 / leverage) / 100 )
tp3 := ent2 + ((ent2 - sl3) * r_r_long)

number_coin = ((quantity * leverage * sl_manager) / ((ent2 - sl3) *100))
equity2 := math.round ((number_coin * close ) , 3)
if equity2 > quantity * leverage
equity2 := quantity * leverage





//////////////////////////////////////////////////////////////////////////////////

if show_qty
label.new(bar_index , low , str.tostring(equity2) + "$" , color = color.rgb(0, 255, 0,0) , size = size.normal , style = label.style_label_up)
strategy.entry(id="buy", direction = strategy.long , qty=(equity2/close) )
if close >= 10 and close < 500
qty2 := str.tostring(math.round(equity2/close , 2))
else
qty2 := str.tostring(math.round(equity2/close , 0))
if close > 500
qty2 := str.tostring(math.round(equity2/close , 3 ))
if symbol == "AAVEUSDT"
qty2 := str.tostring(math.round(equity2/close , 1))
// ================/ برای باز کردن پوزیشن از این مقدار استفاده میکند /======================
message1 = '{"symbol":"'+symbol+'","type":"MARKET", "side":"BUY", "positionSide": "LONG", "quantity":"'+qty2+'","leverage": "'+str.tostring(leverage)+'","marginMode": "Isolated","botmix-action":"open-market-order-v2"}'
// message1 = '{ "side":"Ask","symbol":"'+symbol+'","tradeType":"Market","entrustVolume":"'+qty1+'","action":"Open","marginMode":"Isolated","leverage":"'+str.tostring(leverage)+'", "takerProfitPrice":"'+str.tostring(tp1)+'","stopLossPrice":"'+str.tostring(sl1)+'","botmix-action":"open-market-order" }'
// message1 = '{ "batchOrders":[{"symbol":"'+symbol+'","side":"SELL","type":"Market","quantity":"'+qty1+'","marginMode":"Isolated","leverage":"'+str.tostring(leverage)+'"},{"symbol":"'+symbol+'","side":"BUY","type":"TAKE_PROFIT_MARKET","stopPrice":"'+str.tostring(tp1)+'","quantity":"'+qty1+'"},{"symbol":"'+symbol+'","side":"BUY","type":"STOP_MARKET","stopPrice":"'+str.tostring(sl1)+'","quantity":"'+qty1+'"}],"botmix-action":"open-multiple-order" }'
alert(message1 , alert.freq_once_per_bar)

message2 = '{"symbol":"'+symbol+'","type":"LIMIT","side":"SELL", "positionSide": "LONG","delay": 5 ,"quantity":"'+qty2+'","price": "'+str.tostring(tp3)+'", "botmix-action":"open-market-order-v2"}'
alert(message2 , alert.freq_once_per_bar)

message3 = '{"symbol":"'+symbol+'","type":"STOP_MARKET","side":"SELL","positionSide": "LONG","delay": 10 ,"quantity":"'+qty2+'","price": "'+str.tostring(sl3)+'", "stopPrice": "'+str.tostring(sl3)+'","botmix-action":"open-market-order-v2"}'
alert(message3 , alert.freq_once_per_bar)
long_is_open := true
if show_tp_sl_ent
line.new(bar_index, tp3, bar_index + 15, tp3, xloc= xloc.bar_index, color= color.rgb(0, 255, 0,0 ), width = 1)
box.new(bar_index , tp3 , bar_index + 15 , ent2 ,bgcolor = color.rgb(0, 255, 0 , 90) , border_color = color.rgb(0, 255, 0 , 80) )
line.new(bar_index, (tp3 - ((tp3 - ent2) /2)), bar_index + 15, (tp3 - ((tp3 - ent2) /2)), xloc= xloc.bar_index, color= color.rgb(0, 17, 255), width = 2 , style = line.style_dashed)

line.new(bar_index, sl3, bar_index + 15, sl3, xloc= xloc.bar_index, color= color.rgb(255, 0, 0,0), width = 1)
box.new(bar_index , sl3 , bar_index + 15 , ent2 ,bgcolor = color.rgb(255, 0, 0, 90) , border_color = color.rgb(255, 0, 0 , 80) )
line.new(bar_index , ent2 , bar_index + 15 , ent2 , color = color.rgb(255, 255, 0, 0))

/////////////////////////////////////////////////////////
total_long_trade := total_long_trade + 1

if low <= sl3 and long_is_open == true
loss_long := loss_long + 1
zarar_pos_long := zarar_pos_long + (((ent2 - sl3) / ent2) * equity2)

if high >= tp3 and long_is_open == true
profit_long := profit_long + 1
sood_pos_long := sood_pos_long +(((tp3 - ent2) / ent2) * equity2)

kol_sood_long := sood_pos_long - zarar_pos_long

/////////////////////////////////////////////////////////////
if (low <= sl3 or high >= tp3) and long_is_open == true
long_is_open := false

strategy.exit( id = "buy" , from_entry = "buy" , limit = tp3 , stop = sl3 , qty_percent = 100 , comment_profit = "tp" , comment_loss = "sl" )


color_kol_pos_long = kol_sood_long >0 ? color.rgb(0,255,0) : color.rgb(255,0,0)
// //////////////////////LONG___ENNNDD//////////////////////////////////////////////////////////
// تظیمات دستورات لازم برای ارسال به صرافی جهت پوزیشن شورت


if position_type == "Sell" or position_type == "Buy_And_Sell"
if short_condition and isCoolDownOver


ent1 := close
sl1 :=stop_loss_short + (stop_loss_short * (0.5 / leverage) / 100 )
tp1 := ent1 - ((sl1 - ent1 ) * r_r_short)

number_coin = ((quantity * leverage * sl_manager) / ((sl1 - ent1) *100))

equity1 := math.round ((number_coin * close ) , 3)

if equity1 > quantity * leverage
equity1 := quantity * leverage



/////////////////////////////////////////////////////////////////////////////////////////
if show_qty
label.new(bar_index , high , str.tostring(equity1) + "$" , color = color.rgb(255, 0, 0,0) , size = size.normal , style = label.style_label_down)


strategy.entry(id="sell", direction = strategy.short, qty=(equity1/close) )
if close >= 10 and close < 500
qty1 := str.tostring(math.round(equity1/close , 2))
else
qty1 := str.tostring(math.round(equity1/close , 0))
if close > 500
qty1 := str.tostring(math.round(equity1/close , 3))
if symbol == "AAVEUSDT"
qty1 := str.tostring(math.round(equity1/close , 1))
// ================/ برای باز کردن پوزیشن از این مقدار استفاده میکند /======================
message1 = '{"symbol":"'+symbol+'","type":"MARKET", "side":"SELL", "positionSide": "SHORT", "quantity":"'+qty1+'","leverage": "'+str.tostring(leverage)+'","marginMode": "Isolated","botmix-action":"open-market-order-v2"}'
// message1 = '{ "side":"Ask","symbol":"'+symbol+'","tradeType":"Market","entrustVolume":"'+qty1+'","action":"Open","marginMode":"Isolated","leverage":"'+str.tostring(leverage)+'", "takerProfitPrice":"'+str.tostring(tp1)+'","stopLossPrice":"'+str.tostring(sl1)+'","botmix-action":"open-market-order" }'
// message1 = '{ "batchOrders":[{"symbol":"'+symbol+'","side":"SELL","type":"Market","quantity":"'+qty1+'","marginMode":"Isolated","leverage":"'+str.tostring(leverage)+'"},{"symbol":"'+symbol+'","side":"BUY","type":"TAKE_PROFIT_MARKET","stopPrice":"'+str.tostring(tp1)+'","quantity":"'+qty1+'"},{"symbol":"'+symbol+'","side":"BUY","type":"STOP_MARKET","stopPrice":"'+str.tostring(sl1)+'","quantity":"'+qty1+'"}],"botmix-action":"open-multiple-order" }'
alert(message1 , alert.freq_once_per_bar)

message2 = '{"symbol":"'+symbol+'","type":"LIMIT","side":"BUY", "positionSide": "SHORT","delay": 5 ,"quantity":"'+qty1+'","price": "'+str.tostring(tp1)+'", "botmix-action":"open-market-order-v2"}'
alert(message2 , alert.freq_once_per_bar)

message3 = '{"symbol":"'+symbol+'","type":"STOP_MARKET","side":"BUY","positionSide": "SHORT","delay": 10 ,"quantity":"'+qty1+'","price": "'+str.tostring(sl1)+'", "stopPrice": "'+str.tostring(sl1)+'","botmix-action":"open-market-order-v2"}'
alert(message3 , alert.freq_once_per_bar)
short_is_open := true
if show_tp_sl_ent
line.new(bar_index, tp1, bar_index + 15, tp1, xloc= xloc.bar_index, color= color.rgb(0, 255, 0,0 ), width = 1)
box.new(bar_index , tp1 , bar_index + 15 , ent1 ,bgcolor = color.rgb(0, 255, 0 , 90) , border_color = color.rgb(0, 255, 0 , 80) )
line.new(bar_index, (tp1+((ent1 - tp1)/2)), bar_index + 15, (tp1+((ent1 - tp1)/2)), xloc= xloc.bar_index, color= color.rgb(4, 0, 255), width = 2 , style= line.style_dashed)

line.new(bar_index, sl1, bar_index + 15, sl1, xloc= xloc.bar_index, color= color.rgb(255, 0, 0,50), width = 1)
box.new(bar_index , sl1 , bar_index + 15 , ent1 ,bgcolor = color.rgb(255, 0, 0, 90) , border_color = color.rgb(255, 0, 0 , 80) )

line.new(bar_index , ent1 , bar_index + 15 , ent1 , color = color.rgb(255, 255, 0,0))


////////////////////////////////////////////////////////////////////////////////////
total_short_trade := total_short_trade + 1

if high >= sl1 and short_is_open == true
loss_short := loss_long + 1
zarar_pos_short := zarar_pos_short + (((sl1 - ent1) / ent1) * equity1)


if low <= tp1 and short_is_open == true
profit_short := profit_short + 1
sood_pos_short := sood_pos_short +(((ent1 - tp1) / ent1) * equity1)

kol_sood_short := sood_pos_short - zarar_pos_short

///////////////////////////////////////////////////////////////////////////////////
if (high >= sl1 or low <= tp1 ) and short_is_open == true
short_is_open := false


strategy.exit( id = "sellext1" , from_entry = "sell" , limit = tp1 , stop = sl1 , qty_percent = 100 , comment_profit = "tp" , comment_loss = "sl" )


color_kol_pos_short = kol_sood_short > 0 ? color.rgb(0,255,0) : color.rgb(255,0,0)


////////////////////////////////////////////////////////////////////////////////////////////
kol_trade = loss_short + loss_long + profit_long + profit_short

/////////////////////SHORT___ENNNDD//////////////////////////////////////////////////////
closed_trades = (loss_short + loss_long + profit_long + profit_short) // strategy.closedtrades
kolfee = (closed_trades * quantity * leverage * persent_fee) / 100
net_profit = math.round((kol_sood_short + kol_sood_long) , 2 ) - kolfee
net_percent = math.round((net_profit / quantity) * 100 , 2)
win_rate = math.round(((profit_long + profit_short) / kol_trade) * 100 , 2) //math.round((strategy.wintrades / strategy.closedtrades) * 100 , 2)
ending = math.round((quantity + net_profit) , 2)
profit_factor = math.round((sood_pos_long + sood_pos_short) / math.abs(zarar_pos_long + zarar_pos_short) , 2)
drow_down = math.round((strategy.max_drawdown / quantity) * 100, 2 )




show_reportTabel = input.bool(true)

if show_reportTabel

table_color = color.rgb(0, 0, 0)
var table result_table = table.new(position.top_right, 30, 40, bgcolor=color.rgb(255,255,255,0), frame_color=color.rgb(0, 0, 0,0), frame_width=1, border_width=2)

table.cell(result_table , column = 0 , row = 0 , text = "TEST BTC with breake out:\n" + str.tostring(kol_trade) , bgcolor = table_color , text_color = color.rgb(255,255,255,0))

table.cell(result_table , column = 1 , row = 0 , text = "starting:\n" + str.tostring(quantity) + "$" , bgcolor = table_color, text_color = color.rgb(255,255,255,0))

table.cell(result_table , column = 2 , row = 0 , text = "Net Profit:\n" + str.tostring(net_profit) + "$:\n" + " fee = " + str.tostring(kolfee) , bgcolor = table_color, text_color = net_profit > 0 ? color.rgb(0,255,0,0) : color.rgb(255,0,0,0))

table.cell(result_table , column = 0 , row = 1 , text = "Win Rate:\n" + str.tostring(win_rate) + "%" , bgcolor = table_color, text_color = color.rgb(255,255,255,0))

table.cell(result_table , column = 1 , row = 1 , text = "Ending:\n" + str.tostring(ending) + "$" , bgcolor = table_color, text_color = color.rgb(255,255,255,0))

table.cell(result_table , column = 2 , row = 1 , text = "Profit Factor:\n" + str.tostring(profit_factor) , bgcolor = table_color, text_color = color.rgb(255,255,255,0))

table.cell(result_table , column = 3 , row = 0 , text = "Net Percent:\n" + str.tostring(net_percent) + "%" , bgcolor = table_color, text_color = net_percent > 0 ? color.rgb(0,255,0,0) : color.rgb(255,0,0,0))

table.cell(result_table , column = 3 , row = 1 , text = "Draw Down:\n" + str.tostring(drow_down) + "%" , bgcolor = table_color, text_color = color.rgb(255,255,255,0))

table.cell(result_table , column = 4 , row = 0 , text = "Stop:\n" + "Short =" + str.tostring(loss_short)+ "\n" +"Long =" + str.tostring(loss_long) , bgcolor = table_color, text_color = color.rgb(255,0,0,0))

table.cell(result_table , column = 4 , row = 1 , text = "TP:\n" + "Short =" + str.tostring(profit_short)+ "\n" +"Long =" + str.tostring(profit_long) , bgcolor = table_color, text_color = color.rgb(0,255,0,0))

table.cell(result_table , column = 5 , row = 0 , text = "Short:\n" + "sood =" + str.tostring(math.round(sood_pos_short,2)) + "\n" + "Zarar =" + str.tostring(math.round(zarar_pos_short,2)) , bgcolor = table_color, text_color = color.rgb(0,255,0,0))

table.cell(result_table , column = 5 , row = 1 , text = "Long:\n" + "sood =" + str.tostring(math.round(sood_pos_long,2)) + "\n" + "Zarar =" + str.tostring(math.round(zarar_pos_long,2)) , bgcolor = table_color, text_color = color.rgb(0,255,0,0))

table.cell(result_table , column = 6 , row = 0 , text = "Kol Sood Short:\n" + "Short =" + str.tostring(math.round(kol_sood_short,2)) , bgcolor = table_color, text_color = color_kol_pos_short)

table.cell(result_table , column = 6 , row = 1 , text = "Kol Sood Long:\n" + "LONG =" + str.tostring(math.round(kol_sood_long,2)) , bgcolor = table_color, text_color = color_kol_pos_long)

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// //////////////////////////////////////////////////////////////////////////////////////////////////////

// // ********** تنظیمات **********
// show_monthly_Report = input.bool(false, "نمایش گزارش ماهیانه")
// exchange_fee_percent = 0.05 / 100 // input.float(0.05, "کارمزد صرافی (%)", step=0.01) / 100
// indicator_name = 'BTC with breake out' // input.string("تحلیلگر حرفه ای - گزارش ماهیانه", "عنوان اندیکاتور")
// show_total_row = true // input.bool(true, "نمایش سطر جمع کل")

// // ********** ایجاد جدول **********
// var table monthlyReport = table.new(position = position.top_right, columns = 6,rows = 21,bgcolor = color.rgb(33, 33, 33),
// border_width = 2,border_color = color.rgb(80, 80, 80),frame_width = 1,frame_color = color.rgb(50, 50, 50))

// // ********** متغیرهای ماهیانه **********
// var int currentMonth = na
// var int monthTrades = 0
// var int monthWinningTrades = 0
// var float totalFees = 0.0
// var float monthNetProfit = 0.0

// // ********** متغیرهای جمع کل **********
// var float totalAllTrades = 0.0
// var float totalAllFees = 0.0
// var float totalAllNetProfit = 0.0
// var int totalAllWinningTrades = 0
// var int totalAllMonths = 0

// // ********** تشخیص تغییر ماه **********
// isNewMonth = ta.change(month) or ta.change(year)

// // ********** محاسبات معاملات **********
// tradeClosed = strategy.closedtrades > strategy.closedtrades[1]
// if tradeClosed
// lastTradeIndex = strategy.closedtrades - 1
// tradeSize = math.abs(strategy.closedtrades.size(lastTradeIndex) * strategy.closedtrades.exit_price(lastTradeIndex))
// tradeFee = tradeSize * exchange_fee_percent
// totalFees := totalFees + tradeFee

// tradeProfit = strategy.closedtrades.profit(lastTradeIndex)
// monthNetProfit := monthNetProfit + tradeProfit

// monthTrades := monthTrades + 1
// if tradeProfit > 0
// monthWinningTrades := monthWinningTrades + 1

// // ********** مدیریت گزارش ماهیانه **********
// if isNewMonth and show_monthly_Report and not na(currentMonth)
// // محاسبات ماهانه
// grossProfit = monthNetProfit
// netProfit = grossProfit - totalFees
// winRate = monthTrades > 0 ? (monthWinningTrades/monthTrades)*100 : 0

// // به روزرسانی جمع کل
// totalAllTrades := totalAllTrades + monthTrades
// totalAllFees := totalAllFees + totalFees
// totalAllNetProfit := totalAllNetProfit + netProfit
// totalAllWinningTrades := totalAllWinningTrades + monthWinningTrades
// totalAllMonths := totalAllMonths + 1

// // نمایش در جدول
// row = (month[1] % 12 == 0 ? 12 : month[1] % 12) + 2 // +2 برای جا دادن سطرهای عنوان
// monthName = str.tostring(year[1]) + "-" + str.tostring(month[1], "00")

// table.cell(monthlyReport, 0, row, monthName, text_color=color.white)
// table.cell(monthlyReport, 1, row, str.tostring(monthTrades), text_color=color.white)
// table.cell(monthlyReport, 2, row, str.tostring(grossProfit, "0.00") + " $")
// table.cell(monthlyReport, 3, row, str.tostring(totalFees, "0.00") + " $")
// table.cell(monthlyReport, 4, row, str.tostring(netProfit, "0.00") + " $")
// table.cell(monthlyReport, 5, row, str.tostring(winRate, "1.0") + "%")

// // رنگ آمیزی سود/زیان
// textColor = netProfit >= 0 ? color.rgb(0, 200, 0) : color.rgb(200, 0, 0)
// for i = 2 to 5
// table.cell_set_text_color(monthlyReport, i, row, textColor)

// // ********** سطر جمع کل **********
// if show_monthly_Report and show_total_row and totalAllMonths > 0
// totalWinRate = totalAllTrades > 0 ? (totalAllWinningTrades/totalAllTrades)*100 : 0
// table.cell(monthlyReport, 0, 15, "جمع کل (" + str.tostring(totalAllMonths) + " ماه)",
// text_color=color.yellow,
// bgcolor=color.rgb(50, 50, 50),
// width=6)

// table.cell(monthlyReport, 1, 15, str.tostring(totalAllTrades),
// text_color=color.yellow,
// bgcolor=color.rgb(50, 50, 50))

// table.cell(monthlyReport, 2, 15, str.tostring(totalAllNetProfit + totalAllFees, "0.00") + " $",
// text_color=color.yellow,
// bgcolor=color.rgb(50, 50, 50))

// table.cell(monthlyReport, 3, 15, str.tostring(totalAllFees, "0.00") + " $",
// text_color=color.yellow,
// bgcolor=color.rgb(50, 50, 50))

// table.cell(monthlyReport, 4, 15, str.tostring(totalAllNetProfit, "0.00") + " $",
// text_color = totalAllNetProfit >= 0 ? color.green : color.red,
// bgcolor=color.rgb(50, 50, 50))

// table.cell(monthlyReport, 5, 15, str.tostring(totalWinRate, "1.0") + "%",
// text_color=color.yellow,
// bgcolor=color.rgb(50, 50, 50))

// // ********** ریست ماهیانه **********
// if isNewMonth
// currentMonth := month
// monthTrades := 0
// monthWinningTrades := 0
// totalFees := 0.0
// monthNetProfit := 0.0

// // ********** عنوان‌های جدول **********
// if barstate.isfirst and show_monthly_Report
// // عنوان اصلی (یکپارچه در سطر اول)
// table.cell(
// monthlyReport,
// column = 4, // ستون شروع (0 = اولین ستون)
// row = 0, // ردیف 0 (اولین ردیف)
// text = indicator_name,
// bgcolor = color.rgb(0, 0, 0),
// text_size = size.small,
// text_color = color.rgb(255,255,0),
// width = 12, // گسترش روی تمام 6 ستون
// height = 4 // ارتفاع بیشتر برای وضوح بهتر
// )

// // عنوان ستون‌ها (در ردیف دوم)
// headers = array.from("ماه", "تعداد", "سود ناخالص", "کارمزد", "سود خالص", "نرخ برد")
// for i = 0 to 5
// table.cell(
// monthlyReport,
// column = i,
// row = 1, // ردیف بعد از عنوان اصلی
// text = array.get(headers, i),
// text_color = color.white,
// bgcolor = color.rgb(60, 60, 60),
// width = 1 // عرض معمولی برای هر ستون
// )

Declinazione di responsabilità

Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.