if long sectionLongs := sectionLongs + 1 sectionShorts := 0
if short sectionLongs := 0 sectionShorts := sectionShorts + 1
// ピラミッティングの設定値 pyrl = input(1, "Pyramiding less than") // If your count is less than this number pyre = input(0, "Pyramiding equal to") // If your count is equal to this number pyrg = input(1000000, "Pyramiding greater than") // If your count is greater than this number
// シグナルとピラミッティングの制限を確認 longCondition = long and sectionLongs <= pyrl or long and sectionLongs >= pyrg or long and sectionLongs == pyre shortCondition = short and sectionShorts <= pyrl or short and sectionShorts >= pyrg or short and sectionShorts == pyre
// エントリーの価格を記録する last_open_longCondition = na last_open_shortCondition = na last_open_longCondition := longCondition ? close : nz(last_open_longCondition[1]) last_open_shortCondition := shortCondition ? close : nz(last_open_shortCondition[1])
// エントリー後の最高値、最安値などの記録 last_high = na last_low = na last_high_short = na last_low_short = na last_high := not in_longCondition ? na : in_longCondition and (na(last_high[1]) or high > nz(last_high[1])) ? high : nz(last_high[1]) last_high_short := not in_shortCondition ? na : in_shortCondition and (na(last_high[1]) or high > nz(last_high[1])) ? high : nz(last_high[1]) last_low := not in_shortCondition ? na : in_shortCondition and (na(last_low[1]) or low < nz(last_low[1])) ? low : nz(last_low[1]) last_low_short := not in_longCondition ? na : in_longCondition and (na(last_low[1]) or low < nz(last_low[1])) ? low : nz(last_low[1])
// トレーリングストップの設定 ////
// 設定 isTS = input(false, "Trailing Stop") tsi = input(0, "Activate Trailing Stop Price") / qty ts = input(0, "Trailing Stop") / qty // 判断 long_ts = isTS and not na(last_high) and crossunder(low, last_high - ts) and longCondition == 0 and high >= (last_open_longCondition + tsi) short_ts = isTS and not na(last_low) and crossover(high, last_low + ts) and shortCondition == 0 and low <= (last_open_shortCondition - tsi) // 描画 tsColor = isTS and in_longCondition and last_high >= (last_open_longCondition + tsi) ? blue : isTS and in_shortCondition and last_low <= (last_open_shortCondition - tsi) ? blue : white tsiColor = isTS and in_longCondition and last_high >= (last_open_longCondition + tsi) ? white : isTS and in_shortCondition and last_low <= (last_open_shortCondition - tsi) ? white : blue plot(isTS and in_longCondition ? last_open_longCondition + tsi : na, "Long Trailing", tsiColor, style=3, linewidth=2) plot(isTS and in_shortCondition ? last_open_shortCondition - tsi : na, "Short Trailing", tsiColor, style=3, linewidth=2) plot(isTS and in_longCondition and last_high >= (last_open_longCondition + tsi) ? last_high - ts : na, "Long Trailing", tsColor, style=2, linewidth=2) plot(isTS and in_shortCondition and last_low <= (last_open_shortCondition - tsi) ? last_low + ts : na, "Short Trailing", tsColor, style=2, linewidth=2)
// 利益確定の設定 ////
// 設定 isTP = input(false, "Take Profit") tp = input(0, "Take Profit") / qty // シグナル long_tp = isTP and crossover(high, last_open_longCondition + tp) and longCondition == 0 short_tp = isTP and crossunder(low, last_open_shortCondition - tp) and shortCondition == 0 // 描画 tpColor = isTP and in_longCondition ? purple : isTP and in_shortCondition ? purple : white plot(isTP and in_longCondition and last_high < last_open_longCondition + tp ? last_open_longCondition + tp : na, "Long TP", tpColor, style=3, linewidth=2) plot(isTP and in_shortCondition and last_low > last_open_shortCondition - tp ? last_open_shortCondition - tp : na, "Short TP", tpColor, style=3, linewidth=2)
// ロスカットの設定 ////
// 設定 isSL = input(false, "Stop Loss") sl = input(0, "Stop Loss") / qty // 判断 long_sl = isSL and crossunder(low, last_open_longCondition - sl) and longCondition == 0 short_sl = isSL and crossover(high, last_open_shortCondition + sl) and shortCondition == 0 // 描画 slColor = isSL and in_longCondition and last_low_short > last_open_longCondition - sl ? red : isSL and in_shortCondition and last_high_short < last_open_shortCondition + sl ? red : white plot(isSL and in_longCondition ? last_open_longCondition - sl : na, "Long SL", slColor, style=3, linewidth=2) plot(isSL and in_shortCondition ? last_open_shortCondition + sl : na, "Short SL", slColor, style=3, linewidth=2)
// 仮想マージンコール ////
isMargin = input(false, "Margin Call") leverage = input(1, "Leverage") long_call = last_open_longCondition - (0.8 + 0.2 * (1/leverage)) / leverage * last_open_longCondition short_call = last_open_shortCondition + (0.78 + 0.2 * (1/leverage)) / leverage * last_open_shortCondition long_call_signal = isMargin and crossunder(low, long_call) short_call_signal = isMargin and crossunder(high, short_call) marginColor = isMargin and in_longCondition and last_low_short > long_call ? black : isMargin and in_shortCondition and last_high_short < short_call ? black : white plot(isMargin and in_longCondition ? long_call : na, "Long Margin", marginColor, style=3, linewidth=2) plot(isMargin and in_shortCondition ? short_call : na, "Short Margin", marginColor, style=3, linewidth=2)
// 利益・損失幅の描画 longProfit = averageLongs > 0 and close >= averageLongs ? green : red shortProfit = averageShorts > 0 and close <= averageShorts ? green : red plot1 = plot(averageLongs > 0 ? averageLongs : na, color=white) plot2 = plot(close, color=white) plot3 = plot(averageShorts > 0 ? averageShorts : na, color=white) fill(plot1, plot2, color=longProfit, transp=50) fill(plot2, plot3, color=shortProfit, transp=50)
//Enable this to double your order size every time your pyramid on top of an existing position. (Martingale strategy) // useMartin = input(true, "Martingale")
// // Check to see if this is our first order, set the order qty to 1 // if longCondition and sectionLongConditions == 1 // longMartin := longMartin + 1 // shortMartin := 0 // if shortCondition and sectionShortConditions == 1 // longMartin := 0 // shortMartin := shortMartin + 1
// confirm that this order is being added to an existing order // if longCondition and sectionLongConditions > 1 // longMartin := longMartin * 2 // if shortCondition and sectionShortConditions > 1 // shortMartin := shortMartin * 2
// 決済シグナルの判断(利確 or 損切り or トレーリングストップ or 途転) ////
long_close = long_tp or long_sl or long_ts or long_call_signal ? 1 : 0 short_close = short_tp or short_sl or short_ts or short_call_signal ? 1 : 0
// 決済時間の記録 last_long_close = na last_short_close = na last_long_close := long_close ? time : nz(last_long_close[1]) last_short_close := short_close ? time : nz(last_short_close[1])
// エントリーと決済の時間を確認 if long_close and last_long_close[1] > last_longCondition long_close := 0 if short_close and last_short_close[1] > last_shortCondition short_close := 0
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.