dca v 5 bot
dca v 5 bot
//------------------------------ MA ------------------------------
// GDCA Mode
if gdcaMode == 1
shortMulti := manualShortMulti
strongSellMulti := manualStrongSellMulti
sellMulti := manualSellMulti
buyMulti := manualBuyMulti
strongBuyMulti := manualStrongBuyMulti
longMulti := manualLongMulti
else if gdcaMode == 2
highestAuto = highest > maAutoFirstMAStrong ? highest : maAutoFirstMAStrong
highestStrongAuto = highest > maAutoFirstMAStrong ? maAutoFirstMAStrong :
maAutoFirst
//Sell
lenSell = len
srcSell = price
offsetSell = 0
//Strong Sell
offsetStrongSell = 0
maStrongSell = ta.sma(maSell*strongSellMulti, strongLen)
//plot(maStrongSell, color=#b2283380, title="Strong Sell", offset=offsetStrongSell,
linewidth=6,display=displayZone)
//Short
maShort = maStrongSell * shortMulti
plot(maShort, color=#80192280, title="Short",
linewidth=6,display=derivertiveDisplayZone)
//Buy
lenBuy = len
srcBuy = price
offsetBuy = 0
//maBuy = ta.sma(srcBuy*buyMulti, lenBuy)
maBuy = ta.sma(close*buyMulti, len)
plot(maBuy, color=#4caf5080, title="Buy", offset=offsetBuy,
linewidth=3,display=displayZone)
//Strong Buy
lenStrongBuy = strongLen
offsetStrongBuy = 0
maStrongBuy = ta.sma(maBuy*strongBuyMulti, lenStrongBuy)
//plot(maStrongBuy, color=#1b5e1f80, title="Strong Buy",
offset=offsetStrongBuy,linewidth=6,display=displayZone)
//Long
maLong = maStrongBuy * longMulti
//plot(maLong, color=#00332a80, title="Long",
linewidth=6,display=derivertiveDisplayZone)
//index
indexDerivertive = 0
indexDerivertive := maLong > 0 or maShort > 0 ? indexDerivertive[1]+1 : 0
indexStrong = 0
indexStrong := maStrongBuy > 0 or maStrongSell > 0 ? indexStrong[1]+1 : 0
index = 0
index := maBuy > 0 or maSell > 0 ? index[1]+1 : 0
//channel
higherSell = maSell > maStrongSell ? maSell : maStrongSell
lowerSell = maSell < maStrongSell ? maSell : maStrongSell
higherBuy = maBuy > maStrongBuy ? maBuy : maStrongBuy
lowerBuy = maBuy < maStrongBuy ? maBuy : maStrongBuy
//------------------------------------------ Calculate
----------------------------------------------
short = price > higherSell
sell = price > lowerSell and price < higherSell
halfBuy = price < lowerSell and price > higherBuy
buy = price < higherBuy and price > lowerBuy
long = price < lowerBuy
percent = 0
if(short)
percent := price > channelShort1 ? StartShortZone-
(percentPeriodOfZoneShort*1) :
price > channelShort2 ? StartShortZone-(percentPeriodOfZoneShort*2) :
StartShortZone-(percentPeriodOfZoneShort*10)
else if(sell)
percent := price > channelSell1 ? StartSellZone-(percentPeriodOfZoneSell*0) :
price > channelSell2 ? StartSellZone-(percentPeriodOfZoneSell*1) :
price > channelSell3 ? StartSellZone-(percentPeriodOfZoneSell*2) :
price > channelSell4 ? StartSellZone-(percentPeriodOfZoneSell*3) :
price > channelSell5 ? StartSellZone-(percentPeriodOfZoneSell*4) :
price > channelSell6 ? StartSellZone-(percentPeriodOfZoneSell*5) :
price > channelSell7 ? StartSellZone-(percentPeriodOfZoneSell*6) :
price > channelSell8 ? StartSellZone-(percentPeriodOfZoneSell*7) :
price > channelSell9 ? StartSellZone-(percentPeriodOfZoneSell*8) :
price > channelSell10 ? StartSellZone-(percentPeriodOfZoneSell*9) :
StartSellZone-(percentPeriodOfZoneSell*10)
else if(halfBuy)
percent := price > channelNormal1 ? StartNormalZone+
(percentPeriodOfZoneNormal*1) :
price > channelNormal2 ? StartNormalZone+
(percentPeriodOfZoneNormal*2) :
price > channelNormal3 ? StartNormalZone+
(percentPeriodOfZoneNormal*3) :
price > channelNormal4 ? StartNormalZone+
(percentPeriodOfZoneNormal*4) :
price > channelNormal5 ? StartNormalZone+
(percentPeriodOfZoneNormal*5) :
price > channelNormal6 ? StartNormalZone+
(percentPeriodOfZoneNormal*6) :
price > channelNormal7 ? StartNormalZone+
(percentPeriodOfZoneNormal*7) :
price > channelNormal8 ? StartNormalZone+
(percentPeriodOfZoneNormal*8) :
price > channelNormal9 ? StartNormalZone+
(percentPeriodOfZoneNormal*9) :
StartNormalZone+(percentPeriodOfZoneNormal*10)
else if(buy)
percent := price > channelBuy1 ? StartBuyZone+(percentPeriodOfZoneBuy*1) :
price > channelBuy2 ? StartBuyZone+(percentPeriodOfZoneBuy*2) :
price > channelBuy3 ? StartBuyZone+(percentPeriodOfZoneBuy*3) :
price > channelBuy4 ? StartBuyZone+(percentPeriodOfZoneBuy*4) :
price > channelBuy5 ? StartBuyZone+(percentPeriodOfZoneBuy*5) :
price > channelBuy6 ? StartBuyZone+(percentPeriodOfZoneBuy*6) :
price > channelBuy7 ? StartBuyZone+(percentPeriodOfZoneBuy*7) :
price > channelBuy8 ? StartBuyZone+(percentPeriodOfZoneBuy*8) :
price > channelBuy9 ? StartBuyZone+(percentPeriodOfZoneBuy*9) :
StartBuyZone+(percentPeriodOfZoneBuy*10)
else if(long)
percent := price > channelLong1 ? StartLongZone+(percentPeriodOfZoneLong*1) :
price > channelLong2 ? StartLongZone+(percentPeriodOfZoneLong*2) :
price > channelLong3 ? StartLongZone+(percentPeriodOfZoneLong*3) :
price > channelLong4 ? StartLongZone+(percentPeriodOfZoneLong*4) :
price > channelLong5 ? StartLongZone+(percentPeriodOfZoneLong*5) :
price > channelLong6 ? StartLongZone+(percentPeriodOfZoneLong*6) :
price > channelLong7 ? StartLongZone+(percentPeriodOfZoneLong*7) :
price > channelLong8 ? StartLongZone+(percentPeriodOfZoneLong*8) :
price > channelLong9 ? StartLongZone+(percentPeriodOfZoneLong*9) :
StartLongZone+(percentPeriodOfZoneLong*10)
//---------------------------------------------------------------------------------
------------------
//-------------------------------------------- Display
----------------------------------------------
labeltcolor = color.white
textLabel = buy ? 'Buy' : halfBuy ? "Normal Buy" : long ? "Long" : sell ? "Sell" :
"Short"
labelcolor = buy ? color.green : halfBuy ? color.orange : long ? color.green : sell
? color.red : color.red
reserve = 0.0
reserve := barstate.isfirst ? WaitingDCA : reserve[1]
amountBuy = 0.0
amountSell = 0.0
if(percent > 100)
amountBuy := (useReserve ? (reserve*(percent - 100)/100) : 0) + (DCA*100/100)
else
amountBuy := (DCA*percent/100)
if(percent < 0)
amountSell := ((Invested*(percent)/100))/price
else
amountSell := (Invested*(percent)/100)/price
if labelSwitch
// Update table
tableIndex = 0
if cdcActionSwitch
f_fillCell(panelTable, 0, tableIndex+0, "CDC Action Zone:",
cdcActionZoneBull ? "Bull" : "Bear",bgPanelColor, cdcActionZoneColor)
if useReserve
f_fillCell(panelTable, 0, tableIndex+5, "Reserve:", str.tostring(reserve)
+" "+ syminfo.currency, bgPanelColor, color.white)
//---------------------------------------------------------------------------------
------------------
//------------------------------------------ Strategy
-----------------------------------------------
qty = 0.0
shortSize = 0.0
shortSize := barstate.isfirst ? 0.0:shortSize[1]
longSize = 0.0
longSize := barstate.isfirst ? 0.0:longSize[1]
// plot(reserve,title="reserve",display=display.data_window)
// plot(qty,title="qty",display=display.data_window)
// plot(percent,title="percent",display=display.data_window)
// plot(amountBuy/price,title="amountBuy",display=display.data_window)
// plot(waitingAmount,title="waiting amount",display=display.data_window)
// plot(price,title="price",display=display.data_window)
// plot(indexStrong,title="indexStrong",display=display.data_window)
//Order
// Convert the input to timestamp
startDate = timestamp(startYear_input, startMonth_input, startDay_input)
endDate = timestamp(endYear_input, endMonth_input, endDay_input)
if(useDerivative)
if(bar and short and cdcActionZoneBear)
strategy.order(str.format("DCA Short {0}% = {1}
{2}",percent,qty,syminfo.basecurrency),strategy.short,qty=qty)
if(bar and long and cdcActionZoneBull)
strategy.order(str.format("DCA Long {0}% = {1}
{2}",percent,qty,syminfo.basecurrency),strategy.long,qty=qty)
else
if(bar and buy)
strategy.order(str.format("DCA Buy {0}% = {1}
{2}",percent,qty,syminfo.basecurrency),strategy.long,qty=qty)
else if(bar and halfBuy)
strategy.order(str.format("DCA Normal {0}% = {1}
{2}",percent,qty,syminfo.basecurrency),strategy.long,qty=qty)
else if(bar and sell)
strategy.order(str.format("DCA Sell {0}% = {1}
{2}",percent,qty,syminfo.basecurrency),strategy.short,qty=qty)
if(useDerivative)
if(bar and short)
strategy.order(str.format("DCA Short {0}% = {1}
{2}",percent,qty,syminfo.basecurrency),strategy.short,qty=qty)
if(bar and long)
strategy.order(str.format("DCA Long {0}% = {1}
{2}",percent,qty,syminfo.basecurrency),strategy.long,qty=qty)
//Exit Derivative
if(strategySwitch and useDerivative)
if(bar and halfBuy and shortSize > 0)
strategy.order(str.format("Exit
Short",percent,shortSize,syminfo.basecurrency),strategy.long,qty=shortSize)
shortSize := 0
if(bar and halfBuy and longSize > 0)
strategy.order(str.format("Exit
Long",percent,longSize,syminfo.basecurrency),strategy.short,qty=longSize)
longSize := 0
//END
if(last_bar)
if(closeAllHoldSwitch)
strategy.close_all()
if(predictFuturePrice)
line.new(firstTimeStampMAStrong, firstStrongSellPricePredict, time,
maStrongSell , xloc.bar_time, extend.both, #b22833, line.style_dashed, 2)
line.new(firstTimeStampMA, firstSellPricePredict, time, maSell ,
xloc.bar_time, extend.both, color.red, line.style_dashed, 2)
line.new(firstTimeStampMA, firstBuyPricePredict, time, maBuy ,
xloc.bar_time, extend.both, color.green, line.style_dashed, 2)
line.new(firstTimeStampMAStrong, firstStrongBuyPricePredict, time,
maStrongBuy , xloc.bar_time, extend.both, #1b5e20, line.style_dashed, 2)
if(useDerivative)
line.new(firstTimeStampMAStrong, firstShortPricePredict, time,
maShort , xloc.bar_time, extend.both, #801922, line.style_dashed, 2)
line.new(firstTimeStampMAStrong, firstLongPricePredict, time, maLong ,
xloc.bar_time, extend.both, #00332a, line.style_dashed, 2)
// HALVINGS
DT = 24*60*60*1000
//Halving
get_range(rh, time) =>
time >= rh - 3*DT and time <= rh + 3*DT
any_range_true = false
for i = 0 to array.size(rh_values) - 1
rh = array.get(rh_values, i)
rh_range = get_range(rh, time)
any_range_true := any_range_true or rh_range
//Half Halving
get_half_range(rh, rh_next, extendHalfOfHalving, time) =>
half_rh = (rh + rh_next) * 0.5 + extendHalfOfHalving * DT
time >= half_rh - 3 * DT and time <= half_rh + 3 * DT
any_half_range_true = false
for i = 0 to array.size(rh_values) - 2
rh = array.get(rh_values, i)
rh_next = array.get(rh_values, i + 1)
halfrh_range = get_half_range(rh, rh_next, extendHalfOfHalving, time)
any_half_range_true := any_half_range_true or halfrh_range