একাধিক সূচক মুভিং এভারেজের অগ্রগতির DCA গতিশীল মুনাফা গ্রহণ কৌশল নিশ্চিত করে

EMA RSI MACD BB DCA HTF
সৃষ্টির তারিখ: 2025-04-11 11:09:00 অবশেষে সংশোধন করুন: 2025-04-11 11:09:00
অনুলিপি: 1 ক্লিকের সংখ্যা: 341
2
ফোকাস
319
অনুসারী

একাধিক সূচক মুভিং এভারেজের অগ্রগতির DCA গতিশীল মুনাফা গ্রহণ কৌশল নিশ্চিত করে একাধিক সূচক মুভিং এভারেজের অগ্রগতির DCA গতিশীল মুনাফা গ্রহণ কৌশল নিশ্চিত করে

ওভারভিউ

মাল্টি-ইনডিকেটর কনফার্মেশন ইক্যুয়ালাইন ব্রেকিং ডিসিএ ডায়নামিক স্টপ কৌশলটি একটি উচ্চতর শর্ট-লাইন ট্রেডিং সিস্টেম যা প্রযুক্তিগত বিশ্লেষণ এবং ডলারের ব্যয় গড়ের সাথে মিলিত হয়। এই কৌশলটি সম্ভাব্য প্রবেশের পয়েন্টগুলি নিশ্চিত করার জন্য ইএমএ 48, আরএসআই 14, এমএসিডি এবং ব্রিনের ব্যান্ডের মতো একাধিক প্রযুক্তিগত সূচক ব্যবহার করে এবং কাঠামোগত পজিশন ম্যানেজমেন্ট পদ্ধতি এবং একটি পূর্বনির্ধারিত ঝুঁকি নিয়ন্ত্রণ ব্যবস্থা বাস্তবায়ন করে। কৌশলটির কেন্দ্রবিন্দু হল দাম এবং ইএমএর ক্রসপয়েন্টগুলি সনাক্ত করা এবং আরএসআই, এমএসিডি এবং ব্রিনের ব্যান্ডের সাথে নিশ্চিতকরণ ব্যবহার করা, উচ্চ সময় ফ্রেম বিশ্লেষণের সাথে মিথ্যার সংকেত এড়ানো, তিন স্তরের ডিসিএ কৌশল ব্যবহার করে পজিশন বাড়ানো এবং লাভের সুরক্ষার জন্য একাধিক স্তরযুক্ত স্টপ এবং ডায়নামিক স্টপ লস।

কৌশল নীতি

এই কৌশলটি মূলত নিম্নলিখিত মূল উপাদানগুলি সহ একাধিক প্রযুক্তিগত সূচকগুলির সমন্বয় ভিত্তিক।

  1. প্রবেশের শর্তাবলী

    • মূল্য অবশ্যই ৪৮ চক্রের EMA অতিক্রম করতে হবে, যদি এটি শীর্ষে থাকে তবে এটি উর্ধ্বমুখী হতে হবে এবং খালি থাকলে এটি নীচে যেতে হবে
    • আরএসআইকে অবশ্যই দিকনির্দেশের শক্তি নিশ্চিত করতে হবে (মাল্টিহেড> 60 এবং খালি হেড < 40)
    • MACD লাইনটি অবশ্যই সিগন্যাল লাইনের মধ্য দিয়ে যেতে হবে, গতির দিকনির্দেশ নিশ্চিত করতে
    • দাম অবশ্যই পূর্বের সমর্থন / প্রতিরোধের অঞ্চলের কাছাকাছি হতে হবে
    • আরএসআই ৫ম পিক/ভ্যালি থেকে বিপরীত সিগন্যাল দেখায়
    • উচ্চ সময় ফ্রেম নিশ্চিত করুন যে এই দ্বিতীয় বেস অবস্থান
  2. ডায়নামিক পজিশন ব্যবস্থাপনা

    • প্রাথমিক ঝুঁকি অ্যাকাউন্টের ১-৩% এর মধ্যে সীমাবদ্ধ
    • পজিশনের আকার 1-2-6 এর DCA অনুপাত অনুসরণ করে পজিশনের উপর চাপ দেওয়া হয়
    • প্রথম স্টপ লস এন্ট্রি পয়েন্টের ১-৩% স্থানে, মুদ্রার পরিমাণে
    • সমস্ত ডিসিএ মোতায়েন করার পরে, স্টপ লস আপডেট করুন এন্ট্রি পয়েন্টের 1.3% অবস্থান
  3. স্মার্ট মুনাফা ব্যবস্থা

    • ০.৫% মুনাফা পেলে ২৫% পজিশন বন্ধ করুন
    • যখন দাম ১% মুনাফা পায়, তখন ৫০% পজিশন বন্ধ করুন
    • দ্বিতীয় মুনাফার পরে, স্টপ লস মূলধন অবস্থানে চলে যায়

কোডের গভীরতার বিশ্লেষণে দেখা গেছে যে এই কৌশলটিতে একটি স্মার্ট পিক ভ্যালি সনাক্তকরণ সিস্টেমও রয়েছে যা দাম এবং আরএসআইয়ের সাম্প্রতিক 5 টি পয়েন্টের অস্থিরতা অনুসরণ করে প্যাটার্ন থেকে বিচ্ছিন্নতা সনাক্ত করতে পারে। উচ্চ টাইম ফ্রেম নিশ্চিতকরণ সিস্টেমটি ডায়ালাইন চার্টে সমর্থন এবং প্রতিরোধের অবস্থান বিশ্লেষণ করে নিম্ন টাইম ফ্রেমে মিথ্যা সংকেত এড়াতে পারে।

কৌশলগত সুবিধা

এই কৌশলটির কোডের গভীর বিশ্লেষণে, আমরা নিম্নলিখিত উল্লেখযোগ্য সুবিধাগুলির কথা বলতে পারিঃ

  1. মাল্টি-লেভেল নিশ্চিতকরণ সিস্টেম: একাধিক প্রযুক্তিগত সূচকগুলির সমন্বয়মূলক কার্যকারিতার মাধ্যমে, মিথ্যা সংকেতের সম্ভাবনা ব্যাপকভাবে হ্রাস করা হয়েছে, ৷ ইএমএ, আরএসআই, এমএসিডি এবং ব্রিনের ব্যান্ডের সমন্বয় ব্যবহারের ফলে প্রবেশের পয়েন্টের উচ্চমানের গুণমান নিশ্চিত করা হয়েছে৷

  2. স্মার্ট অর্থ ব্যবস্থাপনা১-২-৬ ডিসিএ অনুপাতের পদ্ধতিটি বাজারের অস্থির গড় ব্যয়কে কাজে লাগায় এবং সামগ্রিক ঝুঁকির গর্তকে সীমাবদ্ধ করে। প্রাথমিক ঝুঁকিটি অ্যাকাউন্টের ১-৩% এর মধ্যে সীমাবদ্ধ থাকে, যা নিশ্চিত করে যে এমনকি সবচেয়ে খারাপ পরিস্থিতিতেও বিপর্যয়কর ক্ষতি হবে না।

  3. গতিশীল ক্ষতি প্রতিরোধ: ট্রেডিংয়ের সাথে সাথে স্টপ লস মেকানিজমকে সামঞ্জস্য করা হয়, বিশেষত যখন মুনাফার কিছু অংশ পাওয়ার পর স্টপ লসকে মূলধন পজিশনে স্থানান্তরিত করা হয়, যা মুনাফা রক্ষার এবং ট্রেডিংয়ের জন্য শ্বাসকষ্টের অনুমতি দেওয়ার প্রয়োজনীয়তার কার্যকরভাবে ভারসাম্য বজায় রাখে।

  4. ধাপে ধাপে লাভের কৌশল০.৫% এবং ১% মুনাফা পয়েন্টে ২৫% এবং ৫০% পজিশন বন্ধ করে, কৌশলটি লাভের কিছু অংশ লক করতে সক্ষম হয়, তবে বিপুল বাজার চলাচলকে ধরতে এবং ঝুঁকি ও লাভের ভারসাম্য বজায় রাখতে পজিশন ধরে রাখে।

  5. উচ্চ সময়সীমা নিশ্চিতকরণ: উচ্চতর সময় ফ্রেমের সমর্থন এবং প্রতিরোধের বিট ব্যবহার করে ট্রেডিং সংকেতগুলি ফিল্টার করা হয়, যা নিম্ন সময়ের ফ্রেমে ঘন ঘন গোলমাল এবং মিথ্যা বিরতির প্রভাবকে হ্রাস করে।

কৌশলগত ঝুঁকি

যদিও এই কৌশলটি অত্যন্ত সুনির্দিষ্টভাবে তৈরি করা হয়েছে, তবুও কয়েকটি ঝুঁকিপূর্ণ বিষয় রয়েছে যা সম্পর্কে সতর্ক হওয়া দরকারঃ

  1. পরামিতি সংবেদনশীলতা: কৌশলটির কার্যকারিতা বেশ কয়েকটি প্যারামিটার সেটিংয়ের উপর নির্ভরশীল, যার মধ্যে রয়েছে ইএমএ চক্র, আরএসআই থ্রেশহোল্ড এবং ডিসিএ স্তর। এই প্যারামিটারগুলির সামান্য পরিবর্তনগুলি ট্রেডিংয়ের ফলাফলের উল্লেখযোগ্য পার্থক্য সৃষ্টি করতে পারে, যার জন্য যত্ন সহকারে অপ্টিমাইজেশন এবং পুনরাবৃত্তি প্রয়োজন।

  2. বিপুল অস্থিরতা: ডিসিএ ব্যবস্থা সত্ত্বেও, বাজারের তীব্র ওঠানামা চলাকালীন, দামগুলি দ্রুত সমস্ত সেট করা স্টপ লস পয়েন্টগুলি অতিক্রম করতে পারে, যার ফলে প্রত্যাশার চেয়ে বেশি প্রকৃত ক্ষতি হয়। এই ঝুঁকির জন্য, আরও কঠোর প্রাথমিক পজিশন আকার ব্যবহার করা বা উচ্চ ওঠানামা চলাকালীন ব্যবসায়ের বিরতি দেওয়া বিবেচনা করা যেতে পারে।

  3. ধারাবাহিক ক্ষতির ওভারল্যাপিং প্রভাব: এমনকি যদি একক লেনদেনের ঝুঁকি সীমিত হয়, তবে ধারাবাহিক ক্ষতির ফলে তহবিলের বক্ররেখা উল্লেখযোগ্যভাবে হ্রাস পেতে পারে। অতিরিক্ত সামগ্রিক ঝুঁকি নিয়ন্ত্রণের পরামর্শ দেওয়া হয়, যেমন দৈনিক বা সাপ্তাহিক সর্বাধিক ক্ষতির সীমা।

  4. আরএসআই সনাক্তকরণের জটিলতা: কোডের মধ্যে আরএসআই বিপর্যয় সনাক্তকরণ historicalতিহাসিক তথ্যের নির্ভুলতার উপর নির্ভর করে এবং কিছু বাজার অবস্থার অধীনে যথেষ্ট নির্ভরযোগ্য নাও হতে পারে। বিপর্যয় সংকেত নিশ্চিত করার জন্য আরও উন্নত পরিসংখ্যানগত পদ্ধতি ব্যবহার করা বিবেচনা করা যেতে পারে।

  5. বাজারের তরলতার উপর নির্ভরশীল: কম তরল বাজারে, প্রচুর পরিমাণে ডিসিএ অর্ডারগুলি স্লাইড পয়েন্ট সমস্যার মুখোমুখি হতে পারে, যা কৌশলটির সামগ্রিক কার্যকারিতা প্রভাবিত করে। এই কৌশলটি উচ্চ তরল বাজারে ব্যবহার করা উচিত।

কৌশল অপ্টিমাইজেশনের দিকনির্দেশনা

কোডের গভীর বিশ্লেষণের উপর ভিত্তি করে, এই কৌশলটি আরও উন্নত করার কয়েকটি উপায় রয়েছেঃ

  1. গতিশীল প্যারামিটার সমন্বয়: বাজারের অস্থিরতার উপর ভিত্তি করে একটি গতিশীল প্যারামিটার সমন্বয় ব্যবস্থা চালু করা যেতে পারে। উদাহরণস্বরূপ, উচ্চ অস্থিরতার সময় স্বয়ংক্রিয়ভাবে আরএসআই-এর হ্রাসের প্রয়োজনীয়তা বাড়ানো বা বিভিন্ন বাজার চক্রের সাথে খাপ খাইয়ে নেওয়ার জন্য ইএমএ দৈর্ঘ্যকে সামঞ্জস্য করা যায়। এই ধরনের স্ব-অনুকূলিতকরণ ব্যবস্থা বিভিন্ন বাজার পরিবেশে কৌশলগুলির স্থায়িত্ব বাড়িয়ে তুলতে পারে।

  2. বর্ধিত বৈপরীত্য: বর্তমান RSI-এর বিচ্যুতি সনাক্তকরণ তুলনামূলকভাবে সহজ, এবং আরো জটিল অ্যালগরিদম প্রবর্তন করে সঠিকতা বাড়ানো যেতে পারে, যেমন ফিশার রূপান্তর RSI ব্যবহার করা বা ট্র্যাফিক নিশ্চিতকরণ যোগ করা। এটি ভুল সংকেত হ্রাস করবে এবং কৌশলটির সঠিকতা বাড়িয়ে তুলবে।

  3. স্মার্ট মুনাফা অপ্টিমাইজেশানবর্তমান স্থির মুনাফা বাজারের অস্থিরতার উপর ভিত্তি করে একটি গতিশীল মুনাফায় পরিবর্তিত হতে পারে। উদাহরণস্বরূপ, বাজারের অবস্থার পরিবর্তনের সাথে সামঞ্জস্য রেখে উচ্চ অস্থিরতার সময় উচ্চ মুনাফা লক্ষ্য নির্ধারণ করা এবং নিম্ন অস্থিরতার সময় লক্ষ্য হ্রাস করা।

  4. তহবিল ব্যবস্থাপনাDCA এর অনুপাত এবং ট্রিগার পয়েন্টগুলি বাজারের কাঠামো এবং বর্তমান প্রবণতা শক্তির গতিশীলতার সাথে সামঞ্জস্য করে অপ্টিমাইজ করা যেতে পারে। উদাহরণস্বরূপ, একটি শক্তিশালী প্রবণতার সময় একটি আরও কঠোর DCA অনুপাত ব্যবহার করা হয়, যখন একটি দুর্বল প্রবণতা সময় এটি আরও রক্ষণশীল হয়।

  5. ট্রেডিং সময় অপ্টিমাইজেশান: লেনদেনের ভলিউম এবং অস্থিরতার উপর ভিত্তি করে সময় ফিল্টার চালু করা, কম কার্যকলাপের সময় লেনদেন এড়ানো। এটি ঐতিহাসিক তথ্য বিশ্লেষণ করে সর্বোত্তম লেনদেনের সময় উইন্ডো নির্ধারণের মাধ্যমে করা যেতে পারে।

সারসংক্ষেপ

মাল্টি-ইনডিকেটর কনফার্মেশন ইভেনিয়েন্স ব্রেকিং ডায়নামিক স্টপ স্ট্র্যাটেজি ডিসিএ হল একটি সুনির্দিষ্টভাবে ডিজাইন করা শর্ট লাইন ট্রেডিং সিস্টেম যা একাধিক প্রযুক্তিগত বিশ্লেষণ সরঞ্জামকে উন্নত তহবিল পরিচালনার প্রযুক্তির সাথে একত্রিত করে। ইএমএ, আরএসআই, এমএসিডি এবং ব্রিনব্যান্ডের মতো সূচকগুলির সাথে সমন্বয় করে কাজ করে, কৌশলটি উচ্চ-সম্ভাব্যতা প্রবেশের পয়েন্টগুলি সনাক্ত করতে সক্ষম হয় এবং একই সাথে একটি কাঠামোগত ডিসিএ পদ্ধতি এবং গতিশীল স্টপ লস / স্টপ মেকানিজম ব্যবহার করে ঝুঁকি পরিচালনা এবং মুনাফা লক করতে পারে।

যদিও এই কৌশলটির সুস্পষ্ট সুবিধা রয়েছে, যার মধ্যে রয়েছে কঠোর ঝুঁকি নিয়ন্ত্রণ, বহু স্তরের নিশ্চিতকরণ ব্যবস্থা এবং স্মার্ট লাভের ব্যবস্থা, ব্যবহারকারীদের এখনও প্যারামিটার সংবেদনশীলতা এবং বাজারের তীব্র ওঠানামা থেকে উদ্ভূত ঝুঁকির বিষয়ে সতর্ক থাকতে হবে। প্রস্তাবিত অপ্টিমাইজেশান ব্যবস্থা যেমন গতিশীল প্যারামিটার সমন্বয়, বর্ধিত বিপর্যয় সনাক্তকরণ এবং স্মার্ট লাভের অপ্টিমাইজেশনের বাস্তবায়নের মাধ্যমে এই কৌশলটির স্থিতিশীলতা এবং লাভজনকতা আরও বাড়ার সম্ভাবনা রয়েছে।

ব্যবসায়ীদের জন্য, এই কৌশলটি পর্যাপ্ত তরলতার সাথে বাজারে প্রয়োগের জন্য সবচেয়ে উপযুক্ত এবং ব্যবহারের আগে পর্যাপ্ত ইতিহাসের পুনরুদ্ধার এবং প্যারামিটার অপ্টিমাইজেশন করা উচিত। সতর্কতার সাথে বাস্তবায়ন এবং ক্রমাগত পর্যবেক্ষণের সাথে সামঞ্জস্য রেখে, এই বহুমুখী ট্রেডিং সিস্টেমটি শর্ট লাইন ব্যবসায়ীদের সরঞ্জাম বাক্সে একটি শক্তিশালী অস্ত্র হতে পারে।

কৌশল সোর্স কোড
/*backtest
start: 2024-04-11 00:00:00
end: 2025-04-10 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"ETH_USDT"}]
*/

//@version=6
strategy("Scalping Strategy with DCA - V2", overlay=true, margin_long=100, margin_short=100)

// Input parameters
emaLength = input.int(48, title="EMA Length", minval=1, group="Main Indicators")
rsiLength = input.int(14, title="RSI Length", minval=1, group="Main Indicators")
macdShortLength = input.int(12, title="MACD Short Length", minval=1, group="Main Indicators")
macdLongLength = input.int(30, title="MACD Long Length", minval=1, group="Main Indicators")
macdSignalLength = input.int(9, title="MACD Signal Length", minval=1, group="Main Indicators")
bbLength = input.int(20, title="Bollinger Bands Length", group="Main Indicators")
bbMult = input.float(2.0, title="Bollinger Bands Multiplier", group="Main Indicators")

// Risk management parameters
initialRiskPercent = input.float(1.0, title="Initial Risk % of Account", minval=0.1, maxval=3.0, step=0.1, group="Risk Management")
stopLossPercent = input.float(1.5, title="Stop Loss % (Unboosted)", minval=0.5, maxval=3.0, step=0.1, group="Risk Management")
fixedSLPercent = input.float(1.3, title="Fixed SL % after full DCA", minval=0.1, maxval=5.0, step=0.1, group="Risk Management")
takeProfitPercent1 = input.float(0.5, title="First Take Profit % (25% Volume)", minval=0.1, group="Risk Management")
takeProfitPercent2 = input.float(1.0, title="Second Take Profit % (50% Volume)", minval=0.1, group="Risk Management")

// DCA parameters
enableDCA = input.bool(true, title="Enable DCA", group="DCA Settings")
dcaLevel1 = input.float(1.0, title="DCA Level 1 % Drop", minval=0.1, group="DCA Settings")
dcaLevel2 = input.float(2.0, title="DCA Level 2 % Drop", minval=0.1, group="DCA Settings")

// Higher Timeframe parameters
higherTF = input.timeframe("D", title="Higher Timeframe for Confirmation", group="Advanced Settings")
useHTFConfirmation = input.bool(true, title="Use Higher Timeframe Confirmation", group="Advanced Settings")

// Debug parameters
showLabels = input.bool(true, title="Show Entry/Exit Labels", group="Visual")
showSL = input.bool(true, title="Show Stop Loss Lines", group="Visual")
showTP = input.bool(true, title="Show Take Profit Lines", group="Visual")

// Calculate indicators
ema = ta.ema(close, emaLength)
rsi = ta.rsi(close, rsiLength)
[macdLine, signalLine, _] = ta.macd(close, macdShortLength, macdLongLength, macdSignalLength)
[middle, upper, lower] = ta.bb(close, bbLength, bbMult)

// Variables for tracking peaks and troughs
var priceHighs = array.new_float(0)
var priceLows = array.new_float(0)
var rsiHighs = array.new_float(0)
var rsiLows = array.new_float(0)

// Track last 5 peaks and troughs for both price and RSI
pivot_high = ta.pivothigh(high, 2, 2)
if not na(pivot_high)
    array.push(priceHighs, pivot_high)
    if array.size(priceHighs) > 5
        array.shift(priceHighs)

pivot_low = ta.pivotlow(low, 2, 2)
if not na(pivot_low)
    array.push(priceLows, pivot_low)
    if array.size(priceLows) > 5
        array.shift(priceLows)

rsi_pivot_high = ta.pivothigh(rsi, 2, 2)
if not na(rsi_pivot_high)
    array.push(rsiHighs, rsi_pivot_high)
    if array.size(rsiHighs) > 5
        array.shift(rsiHighs)

rsi_pivot_low = ta.pivotlow(rsi, 2, 2)
if not na(rsi_pivot_low)
    array.push(rsiLows, rsi_pivot_low)
    if array.size(rsiLows) > 5
        array.shift(rsiLows)

// Check for RSI divergence
rsiDivergenceBullish = array.size(priceLows) >= 5 and array.size(rsiLows) >= 5 and array.get(priceLows, array.size(priceLows) - 1) < array.get(priceLows, array.size(priceLows) - 5) and array.get(rsiLows, array.size(rsiLows) - 1) > array.get(rsiLows, array.size(rsiLows) - 5)

rsiDivergenceBearish = array.size(priceHighs) >= 5 and array.size(rsiHighs) >= 5 and array.get(priceHighs, array.size(priceHighs) - 1) > array.get(priceHighs, array.size(priceHighs) - 5) and array.get(rsiHighs, array.size(rsiHighs) - 1) < array.get(rsiHighs, array.size(rsiHighs) - 5)

// Check if price is near previous high/low (Rule #4)
isNearPrevHigh = array.size(priceHighs) >= 2 and math.abs(high - array.get(priceHighs, array.size(priceHighs) - 2)) / array.get(priceHighs, array.size(priceHighs) - 2) < 0.01
isNearPrevLow = array.size(priceLows) >= 2 and math.abs(low - array.get(priceLows, array.size(priceLows) - 2)) / array.get(priceLows, array.size(priceLows) - 2) < 0.01

// Higher timeframe confirmation (Rule #10)
// Get pivot points from higher timeframe
htf_is_pivot_low = request.security(syminfo.tickerid, higherTF, not na(ta.pivotlow(low, 2, 2)), barmerge.gaps_off, barmerge.lookahead_off)
htf_is_pivot_high = request.security(syminfo.tickerid, higherTF, not na(ta.pivothigh(high, 2, 2)), barmerge.gaps_off, barmerge.lookahead_off)

// Count pivots in higher timeframe to check if this is the 2nd pivot
var htf_pivot_low_count = 0
var htf_pivot_high_count = 0

if htf_is_pivot_low
    htf_pivot_low_count := htf_pivot_low_count + 1
    htf_pivot_low_count := math.min(htf_pivot_low_count, 10)  // Prevent unlimited counting

if htf_is_pivot_high
    htf_pivot_high_count := htf_pivot_high_count + 1
    htf_pivot_high_count := math.min(htf_pivot_high_count, 10)  // Prevent unlimited counting

// Reset counts after a while to maintain relevance
if not htf_is_pivot_low and not htf_is_pivot_high and bar_index % 100 == 0
    htf_pivot_low_count := 0
    htf_pivot_high_count := 0

// Check if this is the 2nd pivot in higher timeframe
isHTFSecondPivotLow = htf_is_pivot_low and htf_pivot_low_count == 2
isHTFSecondPivotHigh = htf_is_pivot_high and htf_pivot_high_count == 2

// Check crossing of Bollinger Bands
crossUpperBand = ta.crossover(close, upper)
crossLowerBand = ta.crossunder(close, lower)

// Entry conditions refined with higher timeframe confirmation
longCondition = close > ema and close[1] <= ema[1] and rsi > 60 and macdLine > signalLine and isNearPrevLow and rsiDivergenceBullish and (not useHTFConfirmation or isHTFSecondPivotLow)
shortCondition = close < ema and close[1] >= ema[1] and rsi < 40 and macdLine < signalLine and isNearPrevHigh and rsiDivergenceBearish and (not useHTFConfirmation or isHTFSecondPivotHigh)

// Additional entry conditions when price crosses Bollinger Bands (Rule #11)
longBBCondition = crossLowerBand and rsi < 30
shortBBCondition = crossUpperBand and rsi > 70

// Calculate position sizes for DCA
initialSize = strategy.equity * initialRiskPercent / 100 / 9  // Initial sizing according to the 1-2-6 rule
dca1Size = initialSize * 2
dca2Size = initialSize * 6

// Calculate SL in money terms (Rule #3)
slMoneyAmount = strategy.equity * initialRiskPercent / 100 * stopLossPercent / 100

// Variables to track DCA levels
var float longEntryPrice = 0.0
var float shortEntryPrice = 0.0
var int longDCACount = 0
var int shortDCACount = 0
var float stopLossLevel = 0.0
var float takeProfit1Level = 0.0
var float takeProfit2Level = 0.0
var float slMoneyValue = 0.0

// Close partial positions at take profit levels
if strategy.position_size > 0
    if close >= takeProfit1Level and takeProfit1Level > 0 and strategy.position_size == initialSize + (longDCACount > 0 ? dca1Size : 0) + (longDCACount > 1 ? dca2Size : 0)
        strategy.order("Long TP1", strategy.short, qty=strategy.position_size * 0.25)
        if showLabels
            label.new(bar_index, high, "TP1 (25%)", color=color.green, textcolor=color.white, style=label.style_label_down)
    
    if close >= takeProfit2Level and takeProfit2Level > 0 and strategy.position_size > initialSize * 0.25
        strategy.order("Long TP2", strategy.short, qty=strategy.position_size * 0.5)
        stopLossLevel := longEntryPrice  // Move SL to breakeven after TP2
        if showLabels
            label.new(bar_index, high, "TP2 (50%) & SL→BE", color=color.green, textcolor=color.white, style=label.style_label_down)

if strategy.position_size < 0
    if close <= takeProfit1Level and takeProfit1Level > 0 and math.abs(strategy.position_size) == initialSize + (shortDCACount > 0 ? dca1Size : 0) + (shortDCACount > 1 ? dca2Size : 0)
        strategy.order("Short TP1", strategy.long, qty=math.abs(strategy.position_size) * 0.25)
        if showLabels
            label.new(bar_index, low, "TP1 (25%)", color=color.red, textcolor=color.white, style=label.style_label_up)
    
    if close <= takeProfit2Level and takeProfit2Level > 0 and math.abs(strategy.position_size) > initialSize * 0.25
        strategy.order("Short TP2", strategy.long, qty=math.abs(strategy.position_size) * 0.5)
        stopLossLevel := shortEntryPrice  // Move SL to breakeven after TP2
        if showLabels
            label.new(bar_index, low, "TP2 (50%) & SL→BE", color=color.red, textcolor=color.white, style=label.style_label_up)

// DCA Logic
if enableDCA and strategy.position_size > 0 and longDCACount < 2
    if close < longEntryPrice * (1 - dcaLevel1/100) and longDCACount == 0
        strategy.entry("Long DCA1", strategy.long, qty=dca1Size)
        longDCACount := 1
        if showLabels
            label.new(bar_index, low, "DCA1", color=color.blue, textcolor=color.white, style=label.style_label_up)
    
    if close < longEntryPrice * (1 - dcaLevel2/100) and longDCACount == 1
        strategy.entry("Long DCA2", strategy.long, qty=dca2Size)
        longDCACount := 2
        // Update SL to fixed percentage after full DCA (Rule #6)
        stopLossLevel := longEntryPrice * (1 - fixedSLPercent/100)
        if showLabels
            label.new(bar_index, low, "DCA2 & SL Update", color=color.blue, textcolor=color.white, style=label.style_label_up)

if enableDCA and strategy.position_size < 0 and shortDCACount < 2
    if close > shortEntryPrice * (1 + dcaLevel1/100) and shortDCACount == 0
        strategy.entry("Short DCA1", strategy.short, qty=dca1Size)
        shortDCACount := 1
        if showLabels
            label.new(bar_index, high, "DCA1", color=color.purple, textcolor=color.white, style=label.style_label_down)
    
    if close > shortEntryPrice * (1 + dcaLevel2/100) and shortDCACount == 1
        strategy.entry("Short DCA2", strategy.short, qty=dca2Size)
        shortDCACount := 2
        // Update SL to fixed percentage after full DCA (Rule #6)
        stopLossLevel := shortEntryPrice * (1 + fixedSLPercent/100)
        if showLabels
            label.new(bar_index, high, "DCA2 & SL Update", color=color.purple, textcolor=color.white, style=label.style_label_down)

// Entry with initial position
if longCondition or longBBCondition
    strategy.close("Short")
    strategy.entry("Long", strategy.long, qty=initialSize)
    longEntryPrice := close
    longDCACount := 0
    shortDCACount := 0
    
    // Set SL based on money value (not percentage)
    slMoneyValue := slMoneyAmount
    // Convert to price level - simplified version
    stopLossLevel := close * (1 - stopLossPercent/100)
    
    takeProfit1Level := close * (1 + takeProfitPercent1/100)
    takeProfit2Level := close * (1 + takeProfitPercent2/100)
    if showLabels
        label.new(bar_index, low, "LONG", color=color.green, textcolor=color.white, style=label.style_label_up)

if shortCondition or shortBBCondition
    strategy.close("Long")
    strategy.entry("Short", strategy.short, qty=initialSize)
    shortEntryPrice := close
    longDCACount := 0
    shortDCACount := 0
    
    // Set SL based on money value (not percentage)
    slMoneyValue := slMoneyAmount
    // Convert to price level - simplified version
    stopLossLevel := close * (1 + stopLossPercent/100)
    
    takeProfit1Level := close * (1 - takeProfitPercent1/100)
    takeProfit2Level := close * (1 - takeProfitPercent2/100)
    if showLabels
        label.new(bar_index, high, "SHORT", color=color.red, textcolor=color.white, style=label.style_label_down)

// Stop Loss
if strategy.position_size > 0 and low <= stopLossLevel
    strategy.close("Long")
    if showLabels
        label.new(bar_index, low, "SL", color=color.red, textcolor=color.white, style=label.style_label_up)

if strategy.position_size < 0 and high >= stopLossLevel
    strategy.close("Short")
    if showLabels
        label.new(bar_index, high, "SL", color=color.red, textcolor=color.white, style=label.style_label_down)

// Market cap and holder % check can't be done directly in TradingView, but we display a reminder
if strategy.position_size != 0 and bar_index % 100 == 0
    label.new(bar_index, close, "Remember: Only trade coins with large market cap and >7% holder ratio", 
              color=color.yellow, textcolor=color.black, style=label.style_label_left)

// Plot indicators - these must be at the global scope in Pine Script v6
plot(ema, color=color.blue, title="48 EMA")
plot(upper, color=color.red, title="Upper BB")
plot(lower, color=color.green, title="Lower BB")
plot(middle, color=color.yellow, title="Middle BB")

// Plot stop loss and take profit levels - conditions need to be part of the plot function in v6
plotSL = showSL and stopLossLevel > 0 ? stopLossLevel : na
plot(plotSL, color=color.red, style=plot.style_circles, linewidth=2, title="Stop Loss")

// TP for long positions
plotTP1Long = showTP and strategy.position_size > 0 and takeProfit1Level > 0 ? takeProfit1Level : na
plot(plotTP1Long, color=color.green, style=plot.style_circles, linewidth=1, title="TP1 Long")

plotTP2Long = showTP and strategy.position_size > 0 and takeProfit2Level > 0 ? takeProfit2Level : na
plot(plotTP2Long, color=color.green, style=plot.style_circles, linewidth=2, title="TP2 Long")

// TP for short positions
plotTP1Short = showTP and strategy.position_size < 0 and takeProfit1Level > 0 ? takeProfit1Level : na
plot(plotTP1Short, color=color.green, style=plot.style_circles, linewidth=1, title="TP1 Short")

plotTP2Short = showTP and strategy.position_size < 0 and takeProfit2Level > 0 ? takeProfit2Level : na
plot(plotTP2Short, color=color.green, style=plot.style_circles, linewidth=2, title="TP2 Short")

// Additional table with strategy information
if barstate.islastconfirmedhistory
    var table infoTable = table.new(position=position.top_right, columns=2, rows=5, bgcolor=color.new(color.black, 70), frame_width=1)
    
    table.cell(infoTable, 0, 0, "Strategy:", bgcolor=color.new(color.blue, 90), text_color=color.white)
    table.cell(infoTable, 1, 0, "Scalping with DCA", text_color=color.white)
    
    table.cell(infoTable, 0, 1, "Initial Risk:", bgcolor=color.new(color.blue, 90), text_color=color.white)
    table.cell(infoTable, 1, 1, str.tostring(initialRiskPercent, "#.##") + "% of account", text_color=color.white)
    
    table.cell(infoTable, 0, 2, "DCA Ratio:", bgcolor=color.new(color.blue, 90), text_color=color.white)
    table.cell(infoTable, 1, 2, "1-2-6", text_color=color.white)
    
    table.cell(infoTable, 0, 3, "SL After DCA:", bgcolor=color.new(color.blue, 90), text_color=color.white)
    table.cell(infoTable, 1, 3, str.tostring(fixedSLPercent, "#.##") + "%", text_color=color.white)
    
    table.cell(infoTable, 0, 4, "REMINDERS:", bgcolor=color.new(color.red, 90), text_color=color.white)
    table.cell(infoTable, 1, 4, "Only trade coins with market cap and >7% holder ratio", text_color=color.white)