//@version=5 strategy("KHARID_PELE", overlay=true, pyramiding=3, default_qty_type=strategy.cash,max_bars_back=1000,max_lines_count=500,max_labels_count=500) ENIDCATOR = ta.rsi(close,14) < 30 //==================== // INPUTS //==================== // text1 = input('"BTCUSDT"', "COIN NAME") text1 = ('6') text2 = ('8') text3 = ('10') text4 = ('12') text5 = ('14') text6 = ('16') text7 = ('18') text8 = ('20') text9 = ('22') text10 = ('24') text11 = ('26') text12 = ('28') text13 = ('30') text14 = ('32') text15 = ('34') text16 = ('36') text17 = ('38') text18 = ('40') text19 = ('42') text20 = ('44') usd_step1 = (6) usd_step2 = (8) usd_step3 = (10) usd_step4 = (12) usd_step5 = (14) usd_step6 = (16) usd_step7 = (18) usd_step8 = (20) usd_step9 = (22) usd_step10 = (24) usd_step11 = (26) usd_step12 = (28) usd_step13 = (30) usd_step14 = (32) usd_step15 = (34) usd_step16 = (36) usd_step17 = (38) usd_step18 = (40) usd_step19 = (42) usd_step20 = (44) tp_per1 = (0.1) tp_per2 = (0.08) tp_per3 = (0.07) tp_per4 = (0.06) tp_per5 = (0.05) tp_per6 = (0.04) tp_per7 = (0.03) tp_per8 = (0.03) // capital = (usd_step2*4) + usd_step1 fee_percent = (0.001 ) drop_percent2 = (0.01) drop_percent3 = (0.01) drop_percent4 = (0.02) drop_percent5 = (0.02) drop_percent6 = (0.02) drop_percent7 = (0.02) drop_percent8 = (0.02) drop_percent9 = (0.02) drop_percent10 = (0.03) drop_percent11 = (0.03) drop_percent12 = (0.03) drop_percent13 = (0.03) drop_percent14 = (0.03) drop_percent15 = (0.04) drop_percent16 = (0.04) drop_percent17 = (0.04) drop_percent18 = (0.05) drop_percent19 = (0.05) drop_percent20 = (0.05) //==================== // VARIABLES //==================== varip float total_usd = 0 varip float total_qty = 0 varip float PROFIT = 0 varip float percantt = 0 // STEP 1 varip bool step1_open = false // STEP 2 varip bool step2_open = false varip float step2_qty = 0 varip float step2a_qty = 0 varip float step2_price = na // STEP 3 varip bool step3_open = false varip float step3_qty = 0 varip float step3a_qty = 0 varip float step3_price = na // STEP 4 varip bool step4_open = false varip float step4_qty = 0 varip float step4a_qty = 0 varip float step4_price = na // STEP 5 varip bool step5_open = false varip float step5_qty = 0 varip float step5a_qty = 0 varip float step5_price = na // STEP 6 varip bool step6_open = false varip float step6_qty = 0 varip float step6a_qty = 0 varip float step6_price = na // STEP 7 varip bool step7_open = false varip float step7_qty = 0 varip float step7a_qty = 0 varip float step7_price = na // STEP 8 varip bool step8_open = false varip float step8_qty = 0 varip float step8a_qty = 0 varip float step8_price = na // STEP 9 varip bool step9_open = false varip float step9_qty = 0 varip float step9a_qty = 0 varip float step9_price = na // STEP 10 varip bool step10_open = false varip float step10_qty = 0 varip float step10a_qty = 0 varip float step10_price = na // STEP 11 varip bool step11_open = false varip float step11_qty = 0 varip float step11a_qty = 0 varip float step11_price = na // STEP 12 varip bool step12_open = false varip float step12_qty = 0 varip float step12a_qty = 0 varip float step12_price = na // STEP 13 varip bool step13_open = false varip float step13_qty = 0 varip float step13a_qty = 0 varip float step13_price = na // STEP 14 varip bool step14_open = false varip float step14_qty = 0 varip float step14a_qty = 0 varip float step14_price = na // STEP 15 varip bool step15_open = false varip float step15_qty = 0 varip float step15a_qty = 0 varip float step15_price = na // STEP 16 varip bool step16_open = false varip float step16_qty = 0 varip float step16a_qty = 0 varip float step16_price = na // STEP 17 varip bool step17_open = false varip float step17_qty = 0 varip float step17a_qty = 0 varip float step17_price = na // STEP 18 varip bool step18_open = false varip float step18_qty = 0 varip float step18a_qty = 0 varip float step18_price = na // STEP 19 varip bool step19_open = false varip float step19_qty = 0 varip float step19a_qty = 0 varip float step19_price = na // STEP 20 varip bool step20_open = false varip float step20_qty = 0 varip float step20a_qty = 0 varip float step20_price = na // STEP SL varip float stepsl_qty = 0 // varip int highestStep = 0 notorder1 = not step1_open and not step2_open and not step3_open and not step4_open and not step5_open and not step6_open and not step7_open and not step8_open and not step9_open and not step10_open and not step11_open and not step12_open and not step13_open and not step14_open and not step15_open and not step16_open and not step17_open and not step18_open and not step19_open and not step20_open //==================== // STEP 1 ENTRY //==================== if (strategy.position_size == 0) and notorder1 and highestStep == 0 and ENIDCATOR qty1 = (usd_step1 / close) - (fee_percent*(usd_step1 / close)) strategy.entry("BUY1", strategy.long, qty=qty1) highestStep := 1 step1_open := true total_usd := usd_step1 total_qty := qty1 step2_open := false step3_open := false alert(message= str.tostring(syminfo.ticker) +','+ " " +'BUY'+','+ " " + text1 + '$' +','+ " " +'MARKET'+','+ " "+'BINANCE_SPOT'+','+ " "+'zMUy2xibEhyxuqZ', freq=alert.freq_once_per_bar) //==================== // AVERAGE PRICE //==================== avg_price = total_qty > 0 ? total_usd / total_qty : na tppp = total_usd == usd_step1 ? tp_per1 : total_usd == (usd_step1 + usd_step2) ? tp_per2 : total_usd == (usd_step1 + usd_step2 + usd_step3) ? tp_per3 : total_usd == (usd_step1 + usd_step2 + usd_step3 + usd_step4) ? tp_per4 : total_usd == (usd_step1 + usd_step2 + usd_step3 + usd_step4 + usd_step5) ? tp_per5 : total_usd == (usd_step1 + usd_step2 + usd_step3 + usd_step4 + usd_step5 + usd_step6) ? tp_per6 : total_usd == (usd_step1 + usd_step2 + usd_step3 + usd_step4 + usd_step5 + usd_step6 + usd_step7) ? tp_per7 : total_usd > (usd_step1 + usd_step2 + usd_step3 + usd_step4 + usd_step5 + usd_step6 + usd_step7) ? tp_per8 : na tp_total = avg_price * (1 + (tppp + fee_percent)) //==================== // STEP 2 BUY //==================== cond_step2_buy = strategy.position_size > 0 and highestStep == 1 and step1_open and not step2_open and close <= avg_price * (1 - drop_percent2) and ENIDCATOR if (cond_step2_buy) step2_qty := (usd_step2 / close) - (fee_percent*(usd_step2 / close)) strategy.entry("BUY2", strategy.long, qty=step2_qty) highestStep := 2 step2_open := true total_usd += usd_step2 total_qty += step2_qty step2_price := close step1_open := true step2a_qty := 0 alert(message= str.tostring(syminfo.ticker) +','+ " " +'BUY'+','+ " " + text2 + '$' +','+ " " +'MARKET'+','+ " "+'BINANCE_SPOT'+','+ " "+'zMUy2xibEhyxuqZ', freq=alert.freq_once_per_bar) //==================== // STEP 3 BUY (based on step2) //==================== cond_step3_buy = highestStep == 2 and step2_open and not step3_open and close <= step2_price * (1 - drop_percent3) and ENIDCATOR if (cond_step3_buy) step3_qty := (usd_step3 / close) - (fee_percent*(usd_step3 / close)) strategy.entry("BUY3", strategy.long, qty=step3_qty) highestStep := 3 step3_open := true total_usd += usd_step3 total_qty += step3_qty step3_price := close step1_open := true step3a_qty := 0 alert(message= str.tostring(syminfo.ticker) +','+ " " +'BUY'+','+ " " + text3 + '$' +','+ " " +'MARKET'+','+ " "+'BINANCE_SPOT'+','+ " "+'zMUy2xibEhyxuqZ', freq=alert.freq_once_per_bar) //==================== // STEP 4 BUY (based on step3) //==================== cond_step4_buy = highestStep == 3 and step3_open and not step4_open and close <= step3_price * (1 - drop_percent4) and ENIDCATOR if (cond_step4_buy) step4_qty := (usd_step4 / close) - (fee_percent*(usd_step4 / close)) strategy.entry("BUY4", strategy.long, qty=step4_qty) highestStep := 4 step4_open := true total_usd += usd_step4 total_qty += step4_qty step4_price := close step1_open := true step4a_qty := 0 alert(message= str.tostring(syminfo.ticker) +','+ " " +'BUY'+','+ " " + text4 + '$' +','+ " " +'MARKET'+','+ " "+'BINANCE_SPOT'+','+ " "+'zMUy2xibEhyxuqZ', freq=alert.freq_once_per_bar) //==================== // STEP 5 BUY (based on step4) //==================== cond_step5_buy = highestStep == 4 and step4_open and not step5_open and close <= step4_price * (1 - drop_percent5) and ENIDCATOR if (cond_step5_buy) step5_qty := (usd_step5 / close) - (fee_percent*(usd_step5 / close)) strategy.entry("BUY5", strategy.long, qty=step5_qty) highestStep := 5 step5_open := true total_usd += usd_step5 total_qty += step5_qty step5_price := close step1_open := true step5a_qty := 0 alert(message= str.tostring(syminfo.ticker) +','+ " " +'BUY'+','+ " " + text5 + '$' +','+ " " +'MARKET'+','+ " "+'BINANCE_SPOT'+','+ " "+'zMUy2xibEhyxuqZ', freq=alert.freq_once_per_bar) //==================== // STEP 6 BUY (based on step5) //==================== cond_step6_buy = highestStep == 5 and step5_open and not step6_open and close <= step5_price * (1 - drop_percent6) and ENIDCATOR if (cond_step6_buy) step6_qty := (usd_step6 / close) - (fee_percent*(usd_step6 / close)) strategy.entry("BUY6", strategy.long, qty=step6_qty) highestStep := 6 step6_open := true total_usd += usd_step6 total_qty += step6_qty step6_price := close step1_open := true step6a_qty := 0 alert(message= str.tostring(syminfo.ticker) +','+ " " +'BUY'+','+ " " + text6 + '$' +','+ " " +'MARKET'+','+ " "+'BINANCE_SPOT'+','+ " "+'zMUy2xibEhyxuqZ', freq=alert.freq_once_per_bar) //==================== // STEP 7 BUY (based on step6) //==================== cond_step7_buy = highestStep == 6 and step6_open and not step7_open and close <= step6_price * (1 - drop_percent7) and ENIDCATOR if (cond_step7_buy) step7_qty := (usd_step7 / close) - (fee_percent*usd_step7 / close) strategy.entry("BUY7", strategy.long, qty=step7_qty) highestStep := 7 step7_open := true total_usd += usd_step7 total_qty += step7_qty step7_price := close step1_open := true step7a_qty := 0 alert(message= str.tostring(syminfo.ticker) +','+ " " +'BUY'+','+ " " + text7 + '$' +','+ " " +'MARKET'+','+ " "+'BINANCE_SPOT'+','+ " "+'zMUy2xibEhyxuqZ', freq=alert.freq_once_per_bar) //==================== // STEP 8 BUY (based on step7) //==================== cond_step8_buy = highestStep == 7 and step7_open and not step8_open and close <= step7_price * (1 - drop_percent8) and ENIDCATOR if (cond_step8_buy) step8_qty := (usd_step8 / close) - (fee_percent*(usd_step8 / close)) strategy.entry("BUY8", strategy.long, qty=step8_qty) highestStep := 8 step8_open := true total_usd += usd_step8 total_qty += step8_qty step8_price := close step1_open := true step8a_qty := 0 alert(message= str.tostring(syminfo.ticker) +','+ " " +'BUY'+','+ " " + text8 + '$' +','+ " " +'MARKET'+','+ " "+'BINANCE_SPOT'+','+ " "+'zMUy2xibEhyxuqZ', freq=alert.freq_once_per_bar) //==================== // STEP 9 BUY (based on step8) //==================== cond_step9_buy = highestStep == 8 and step8_open and not step9_open and close <= step8_price * (1 - drop_percent9) and ENIDCATOR if (cond_step9_buy) step9_qty := (usd_step9 / close) - (fee_percent*(usd_step9 / close)) strategy.entry("BUY9", strategy.long, qty=step9_qty) highestStep := 9 step9_open := true total_usd += usd_step9 total_qty += step9_qty step9_price := close step1_open := true step9a_qty := 0 alert(message= str.tostring(syminfo.ticker) +','+ " " +'BUY'+','+ " " + text9 + '$' +','+ " " +'MARKET'+','+ " "+'BINANCE_SPOT'+','+ " "+'zMUy2xibEhyxuqZ', freq=alert.freq_once_per_bar) //==================== // STEP 10 BUY (based on step9) //==================== cond_step10_buy = highestStep == 9 and step9_open and not step10_open and close <= step9_price * (1 - drop_percent10) and ENIDCATOR if (cond_step10_buy) step10_qty := (usd_step10 / close) - (fee_percent*(usd_step10 / close)) strategy.entry("BUY10", strategy.long, qty=step10_qty) highestStep := 10 step10_open := true total_usd += usd_step10 total_qty += step10_qty step10_price := close step1_open := true step10_open := true step10a_qty := 0 alert(message= str.tostring(syminfo.ticker) +','+ " " +'BUY'+','+ " " + text10 + '$' +','+ " " +'MARKET'+','+ " "+'BINANCE_SPOT'+','+ " "+'zMUy2xibEhyxuqZ', freq=alert.freq_once_per_bar) //==================== // STEP 11 BUY (based on step9) //==================== cond_step11_buy = highestStep == 10 and step10_open and not step11_open and close <= step10_price * (1 - drop_percent11) and ENIDCATOR if (cond_step11_buy) step11_qty := (usd_step11 / close) - (fee_percent*(usd_step11 / close)) strategy.entry("BUY11", strategy.long, qty=step11_qty) highestStep := 11 step11_open := true total_usd += usd_step11 total_qty += step11_qty step11_price := close step1_open := true step11a_qty := 0 alert(message= str.tostring(syminfo.ticker) +','+ " " +'BUY'+','+ " " + text11 + '$' +','+ " " +'MARKET'+','+ " "+'BINANCE_SPOT'+','+ " "+'zMUy2xibEhyxuqZ', freq=alert.freq_once_per_bar) //==================== // STEP 12 BUY (based on step12) //==================== cond_step12_buy = highestStep == 11 and step11_open and not step12_open and close <= step11_price * (1 - drop_percent12) and ENIDCATOR if (cond_step12_buy) step12_qty := (usd_step12 / close) - (fee_percent*(usd_step12 / close)) strategy.entry("BUY12", strategy.long, qty=step12_qty) highestStep := 12 step12_open := true total_usd += usd_step12 total_qty += step12_qty step12_price := close step1_open := true step12a_qty := 0 alert(message= str.tostring(syminfo.ticker) +','+ " " +'BUY'+','+ " " + text12 + '$' +','+ " " +'MARKET'+','+ " "+'BINANCE_SPOT'+','+ " "+'zMUy2xibEhyxuqZ', freq=alert.freq_once_per_bar) //==================== // STEP 13 BUY (based on step13) //==================== cond_step13_buy = highestStep == 12 and step12_open and not step13_open and close <= step12_price * (1 - drop_percent13) and ENIDCATOR if (cond_step13_buy) step13_qty := (usd_step13 / close) - (fee_percent*(usd_step13 / close)) strategy.entry("BUY13", strategy.long, qty=step13_qty) highestStep := 13 step13_open := true total_usd += usd_step13 total_qty += step13_qty step13_price := close step1_open := true step13a_qty := 0 alert(message= str.tostring(syminfo.ticker) +','+ " " +'BUY'+','+ " " + text13 + '$' +','+ " " +'MARKET'+','+ " "+'BINANCE_SPOT'+','+ " "+'zMUy2xibEhyxuqZ', freq=alert.freq_once_per_bar) //==================== // STEP 14 BUY (based on step14) //==================== cond_step14_buy = highestStep == 13 and step13_open and not step14_open and close <= step13_price * (1 - drop_percent14) and ENIDCATOR if (cond_step14_buy) step14_qty := (usd_step14 / close) - (fee_percent*(usd_step14 / close)) strategy.entry("BUY4", strategy.long, qty=step14_qty) highestStep := 14 step14_open := true total_usd += usd_step14 total_qty += step14_qty step14_price := close step1_open := true step14a_qty := 0 alert(message= str.tostring(syminfo.ticker) +','+ " " +'BUY'+','+ " " + text14 + '$' +','+ " " +'MARKET'+','+ " "+'BINANCE_SPOT'+','+ " "+'zMUy2xibEhyxuqZ', freq=alert.freq_once_per_bar) //==================== // STEP 15 BUY (based on step15) //==================== cond_step15_buy = highestStep == 14 and step14_open and not step15_open and close <= step14_price * (1 - drop_percent15) and ENIDCATOR if (cond_step15_buy) step15_qty := (usd_step15 / close) - (fee_percent*(usd_step15 / close)) strategy.entry("BUY15", strategy.long, qty=step15_qty) highestStep := 15 step15_open := true total_usd += usd_step15 total_qty += step15_qty step15_price := close step1_open := true step15a_qty := 0 alert(message= str.tostring(syminfo.ticker) +','+ " " +'BUY'+','+ " " + text15 + '$' +','+ " " +'MARKET'+','+ " "+'BINANCE_SPOT'+','+ " "+'zMUy2xibEhyxuqZ', freq=alert.freq_once_per_bar) //==================== // STEP 16 BUY (based on step16) //==================== cond_step16_buy = highestStep == 15 and step15_open and not step16_open and close <= step15_price * (1 - drop_percent16) and ENIDCATOR if (cond_step16_buy) step16_qty := (usd_step16 / close) - (fee_percent*(usd_step16 / close)) strategy.entry("BUY16", strategy.long, qty=step16_qty) highestStep := 16 step16_open := true total_usd += usd_step16 total_qty += step16_qty step16_price := close step1_open := true step16a_qty := 0 alert(message= str.tostring(syminfo.ticker) +','+ " " +'BUY'+','+ " " + text16 + '$' +','+ " " +'MARKET'+','+ " "+'BINANCE_SPOT'+','+ " "+'zMUy2xibEhyxuqZ', freq=alert.freq_once_per_bar) //==================== // STEP 17 BUY (based on step17) //==================== cond_step17_buy = highestStep == 16 and step16_open and not step17_open and close <= step16_price * (1 - drop_percent17) and ENIDCATOR if (cond_step17_buy) step17_qty := (usd_step17 / close) - (fee_percent*(usd_step17 / close)) strategy.entry("BUY17", strategy.long, qty=step17_qty) highestStep := 17 step17_open := true total_usd += usd_step17 total_qty += step17_qty step17_price := close step1_open := true step17a_qty := 0 alert(message= str.tostring(syminfo.ticker) +','+ " " +'BUY'+','+ " " + text17 + '$' +','+ " " +'MARKET'+','+ " "+'BINANCE_SPOT'+','+ " "+'zMUy2xibEhyxuqZ', freq=alert.freq_once_per_bar) //==================== // STEP 18 BUY (based on step18) //==================== cond_step18_buy = highestStep == 17 and step17_open and not step18_open and close <= step17_price * (1 - drop_percent18) and ENIDCATOR if (cond_step18_buy) step18_qty := (usd_step18 / close) - (fee_percent*(usd_step18 / close)) strategy.entry("BUY18", strategy.long, qty=step18_qty) highestStep := 18 step18_open := true total_usd += usd_step18 total_qty += step18_qty step18_price := close step1_open := true step18a_qty := 0 alert(message= str.tostring(syminfo.ticker) +','+ " " +'BUY'+','+ " " + text18 + '$' +','+ " " +'MARKET'+','+ " "+'BINANCE_SPOT'+','+ " "+'zMUy2xibEhyxuqZ', freq=alert.freq_once_per_bar) //==================== // STEP 19 BUY (based on step19) //==================== cond_step19_buy = highestStep == 18 and step18_open and not step19_open and close <= step18_price * (1 - drop_percent19) and ENIDCATOR if (cond_step19_buy) step19_qty := (usd_step19 / close) - (fee_percent*(usd_step19 / close)) strategy.entry("BUY19", strategy.long, qty=step19_qty) highestStep := 19 step19_open := true total_usd += usd_step19 total_qty += step19_qty step19_price := close step1_open := true step19a_qty := 0 alert(message= str.tostring(syminfo.ticker) +','+ " " +'BUY'+','+ " " + text19 + '$' +','+ " " +'MARKET'+','+ " "+'BINANCE_SPOT'+','+ " "+'zMUy2xibEhyxuqZ', freq=alert.freq_once_per_bar) //==================== // STEP 20 BUY (based on step19) //==================== cond_step20_buy = highestStep == 19 and step19_open and not step20_open and close <= step19_price * (1 - drop_percent20) and ENIDCATOR if (cond_step20_buy) step20_qty := (usd_step20 / close) - (fee_percent*(usd_step20 / close)) strategy.entry("BUY20", strategy.long, qty=step20_qty) highestStep := 20 step20_open := true total_usd += usd_step20 total_qty += step20_qty step20_price := close step1_open := true step20a_qty := 0 alert(message= str.tostring(syminfo.ticker) +','+ " " +'BUY'+','+ " " + text20 + '$' +','+ " " +'MARKET'+','+ " "+'BINANCE_SPOT'+','+ " "+'zMUy2xibEhyxuqZ', freq=alert.freq_once_per_bar) //==================== // FINAL TP (TOTAL) //==================== // tp_total = avg_price * (1 + (tp_percent+fee_percent)) if (strategy.position_size > 0 and close >= tp_total) strategy.close_all() alert(message= str.tostring(syminfo.ticker) +','+ " " +'SELL'+','+ " " + '100%' +','+ " " +'MARKET'+','+ " "+'BINANCE_SPOT'+','+ " "+'zMUy2xibEhyxuqZ', freq=alert.freq_once_per_bar) highestStep := 0 // PROFIT += sood // porcen = (PROFIT * 100) / capital step1_open := false step2_open := false step3_open := false step4_open := false step5_open := false step6_open := false step7_open := false step8_open := false step9_open := false step10_open := false step11_open := false step12_open := false step13_open := false step14_open := false step15_open := false step16_open := false step17_open := false step18_open := false step19_open := false step20_open := false step2a_qty := 0 step3a_qty := 0 step4a_qty := 0 step5a_qty := 0 step6a_qty := 0 step7a_qty := 0 step8a_qty := 0 step9a_qty := 0 step10a_qty := 0 step11a_qty := 0 step12a_qty := 0 step13a_qty := 0 step14a_qty := 0 step15a_qty := 0 step16a_qty := 0 step17a_qty := 0 step18a_qty := 0 step19a_qty := 0 step20a_qty := 0 total_usd := 0 total_qty := 0 //////////////