
এই কৌশলটি দুটি সূচকীয় চলমান গড় (ইএমএ) এর ক্রস ব্যবহার করে একটি ক্রয়-বিক্রয় সংকেত হিসাবে। যখন সংক্ষিপ্ত সময়ের ইএমএ নীচে থেকে উপরে দীর্ঘ সময়ের ইএমএ অতিক্রম করে, তখন একটি ক্রয় সংকেত উত্পন্ন হয়; বিপরীতভাবে, যখন সংক্ষিপ্ত সময়ের ইএমএ উপরে থেকে নীচে দীর্ঘ সময়ের ইএমএ অতিক্রম করে, তখন একটি বিক্রয় সংকেত উত্পন্ন হয়। একই সাথে, কৌশলটি বিচার করে যে ক্রস পয়েন্টটি সাম্প্রতিক 10 টি ট্রেডিং চক্রের মধ্যে সর্বোচ্চ বা সর্বনিম্ন দাম কিনা, যাতে প্রবণতার শক্তি নিশ্চিত করা যায়। যদি ক্রস পয়েন্টটি সর্বোচ্চ হয় তবে দামটি পটভূমিতে সবুজ দেখানো হবে; যদি সর্বনিম্ন হয় তবে লাল দেখানো হবে।
এই কৌশলটি সূচকীয় চলমান গড়ের ক্রসকে কেন্দ্রীয় লজিক হিসাবে গ্রহণ করে এবং ক্রস পয়েন্টের দামের সাম্প্রতিক সময়ের তুলনামূলক অবস্থানগুলির সাথে মিলিত হয় যাতে প্রবণতার শক্তি বিচার করা যায়। সামগ্রিকভাবে, কৌশলটির যুক্তি পরিষ্কার এবং সুবিধাগুলি সুস্পষ্ট, তবে কিছু সীমাবদ্ধতা এবং ঝুঁকিও রয়েছে। আরও সহায়ক বিচারক সূচক প্রবর্তন করে, যুক্তিসঙ্গত ঝুঁকি নিয়ন্ত্রণ ব্যবস্থা স্থাপন করে এবং মূল প্যারামিটারগুলি অপ্টিমাইজ করে কৌশলটির স্থায়িত্ব এবং লাভজনকতা আরও বাড়ানো যায়।
/*backtest
start: 2024-02-01 00:00:00
end: 2024-02-29 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ZenAndTheArtOfTrading
// @version=5
strategy("ema giao nhau", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100)
// Get user input
emaLength1 = input.int(title="EMA #1 Length", defval=5)
emaLength2 = input.int(title="EMA #2 Length", defval=10)
// Get MAs
ema1 = ta.ema(close, emaLength1)
ema2 = ta.ema(close, emaLength2)
// Draw MAs
plot(ema1, color=color.blue, title="EMA 1")
plot(ema2, color=color.red, title="EMA 2")
// Detect crossovers
bool crossOver = ta.crossover(ema1, ema2)
bool crossUnder = ta.crossunder(ema1, ema2)
bool cross = crossOver or crossUnder
//float crossPrice = ta.valuewhen(cross, close, 0)
float crossPrice = cross ? close : na
// Check if the crossover price is the highest price over the past 10 bars
bool highestPrice = crossOver
for i = 1 to 10
if crossPrice <= close[i]
highestPrice := false
break
// Check if the crossover price is the lowest price over the past 10 bars
bool lowestPrice = crossUnder
for i = 1 to 10
if crossPrice >= close[i]
lowestPrice := false
break
// Flag the bar if it is a high/low close
bgcolor(highestPrice ? color.new(color.green, 50) : na)
bgcolor(lowestPrice ? color.new(color.red, 50) : na)
// Display crossover price
if cross
highestEmaPrice = ema1 > ema2 ? ema1 : ema2
label myLabel = label.new(bar_index, highestEmaPrice, "CrossPrice=" + str.tostring(crossPrice), color=color.white)
if highestPrice and strategy.position_size == 0
strategy.entry(id="Buy", direction=strategy.long)
if lowestPrice and strategy.position_size == 0
strategy.entry(id="Sell", direction=strategy.short)
// Exit trades when short-term EMA is breached
if strategy.position_size > 0 and crossUnder
strategy.close("Buy")
if strategy.position_size < 0 and crossOver
strategy.close("Sell")