آل راؤنڈ خودکار ٹریڈنگ حرکت پذیر اوسط اندردخش حکمت عملی


تخلیق کی تاریخ: 2023-11-13 10:44:41 آخر میں ترمیم کریں: 2023-11-13 10:44:41
کاپی: 0 کلکس کی تعداد: 611
1
پر توجہ دیں
1617
پیروکار

آل راؤنڈ خودکار ٹریڈنگ حرکت پذیر اوسط اندردخش حکمت عملی

جائزہ

آٹومیٹک ٹریڈنگ کی ایک جامع حکمت عملی ایک عام ملٹی ٹائم پیریڈ چلتی اوسط رینبو حکمت عملی ہے۔ یہ 12 مختلف ادوار کی چلتی اوسط کا استعمال کرتا ہے ، جس میں حرکت پذیر اوسط کی ترتیب اور قیمت کے تعلقات کی طرف سے مارکیٹ کی سمت کا تعین کرنے کے لئے ، اور پوزیشن ، اسٹاپ نقصان اور اسٹاپ کی شرائط کا تعین کرنے کے لئے ، خود کار طریقے سے تجارت کرنے کے لئے۔ حکمت عملی اس رجحان کو خود بخود پہچان سکتی ہے ، اور اس میں خطرے کو کنٹرول کرنے کے لئے ایک بہتر اسٹاپ نقصان کا طریقہ کار موجود ہے۔

اصول

اس حکمت عملی میں 12 چلتی اوسط کا استعمال کیا جاتا ہے ، جس میں 3 دور ، 5 دور ، 8 دور تک 55 دور شامل ہیں ، اور چلتی اوسط کی اقسام کو ای ایم اے ، ایس ایم اے ، آر ایم اے وغیرہ منتخب کیا جاسکتا ہے۔ حکمت عملی پہلے مختصر مدت اور طویل مدت کے چلنے والی اوسط ((1-4 دورانیہ لائنز اور 5-8 دورانیہ لائنز) کے ترتیباتی تعلقات کا فیصلہ کرتی ہے ، اگر مختصر مدت اوپر ہے تو اس کا فیصلہ عروج پر ہے ، اگر مختصر مدت نیچے ہے تو اس کا فیصلہ نیچے کی طرف ہے۔

ایک بڑھتے ہوئے رجحان میں ، اگر قیمت پچھلے نچلے نقطہ کے موازنہ میں چلنے والی اوسط سے ٹوٹ جاتی ہے تو ، اس کو پوزیشن لگانے کے اشارے کے مطابق سمجھا جاتا ہے ، اور اس سے زیادہ کام کیا جاتا ہے۔ اسٹاپ نقصان پچھلے نچلے نقطہ کے موازنہ میں چلنے والی اوسط پر ہوتا ہے ، اور اس کا اسٹاپ فاصلہ نقصان کا 1.6 گنا ہوتا ہے۔ ایک گرنے والے رجحان میں ، اگر قیمت پچھلے اعلی نقطہ کے موازنہ میں چلنے والی اوسط سے ٹوٹ جاتی ہے تو ، اس کو پوزیشن لگانے کے اشارے کے مطابق سمجھا جاتا ہے ، اور اس سے زیادہ کام کیا جاتا ہے۔

اس حکمت عملی میں ٹرینڈ ریورس کا پتہ لگانے کی بھی خصوصیات ہیں۔ پوزیشن کے دوران ، اگر قلیل مدتی حرکت پذیر اوسط میں ترتیب میں تبدیلی آتی ہے ، اور قیمت حالیہ اونچائی یا نچلے حصے سے تجاوز کر جاتی ہے تو ، اس کا فیصلہ کیا جاتا ہے کہ رجحان کا رخ موڑنے کا امکان ہے ، اس وقت موجودہ پوزیشن سے باہر نکلیں اور اس کے برعکس پوزیشن میں تبدیل ہوجائیں ، نئی اونچائی یا نچلے حصے کے ساتھ اسٹاپ اور اسٹاپ پوزیشن۔

فوائد

  1. اس حکمت عملی میں ایک سے زیادہ ٹائم سائیکل تجزیہ کا استعمال کیا گیا ہے تاکہ رجحانات کی سمت کا اندازہ لگایا جا سکے۔

  2. حکمت عملی میں حرکت پذیر اوسط کے ساتھ الٹا سیدھ میں لگانے کے فیصلے شامل ہیں ، تاکہ مارکیٹ کے جھٹکے سے گمراہ نہ ہوں۔

  3. اس حکمت عملی میں اسٹاپ نقصان کا ایک مکمل طریقہ کار ہے جس سے انفرادی تجارت کے خطرات کو مؤثر طریقے سے کنٹرول کیا جاسکتا ہے۔

  4. اس حکمت عملی میں رجحان الٹ کا پتہ لگانے کی خصوصیت ہے ، جو بروقت رجحان الٹ کے مواقع کو پکڑ سکتی ہے اور نظاماتی خطرے کو کم کرسکتی ہے۔

  5. اس حکمت عملی کے پیرامیٹرز کی ترتیب لچکدار ہے اور اس کی قسم اور اس کی مدت اپنی مرضی کے مطابق ہوسکتی ہے۔

  6. اس حکمت عملی میں ٹریکنگ سٹاپ نقصان کا استعمال کیا گیا ہے تاکہ زیادہ سے زیادہ منافع کو لاک کیا جا سکے۔

خطرات

  1. ایک سے زیادہ منتقل اوسط مجموعہ حکمت عملی ، پیرامیٹرز کی ترتیبات حکمت عملی کی کارکردگی کو متاثر کرتی ہیں ، جس میں اصلاحی جانچ کی ضرورت ہوتی ہے۔

  2. ایک ہلچل کی صورت میں، ایک حرکت پذیری اوسط غلط سگنل دے گا، اور پیرامیٹرز کو مناسب طریقے سے ایڈجسٹ کیا جانا چاہئے یا عارضی طور پر تجارت نہیں کرنا چاہئے.

  3. کچھ تاخیر ہے اور رجحان کے نقطہ نظر کے قریب ایک موقع ضائع کرنے کا خطرہ ہوسکتا ہے.

  4. دیگر تکنیکی اشارے پر توجہ دیں اور اہم معاونت کے قریب کم کھولی ہوئی پوزیشنوں کو خالی کرنے سے گریز کریں۔

  5. سسٹم کے خطرے پر دھیان دینا ضروری ہے ، اور ریورس ٹیسٹنگ کا طریقہ کار اس خطرے کو مکمل طور پر دور نہیں کرسکتا ہے۔

  6. واپسی کنٹرول کے لئے اضافی طریقہ کار شامل کرنے کی ضرورت ہے ، متحرک پوزیشن مینجمنٹ کو شامل کرنے پر غور کیا جاسکتا ہے۔

اصلاح کی سمت

  1. مختلف قسم کے چلتی اوسط اور پیرامیٹرز کی ترتیبات کو آزمائیں اور بہترین مجموعہ تلاش کریں۔

  2. ریورسنگ کا پتہ لگانے کے طریقہ کار کو بہتر بنانا ، ریورسنگ ٹرگر شرائط کو زیادہ درست بنانا۔

  3. متحرک پوزیشن مینجمنٹ میکانزم میں شمولیت اختیار کریں ، جب پوزیشنوں کو بہت زیادہ واپس لے لیا جائے تو ان کو کم کریں۔

  4. مشین لرننگ الگورتھم کو شامل کرنے پر غور کریں ، جس میں بڑے اعداد و شمار کی تربیت کا استعمال کرتے ہوئے کلیدی مقامات کا تعین کیا جاسکتا ہے۔

  5. دوسرے اشارے کے اشاروں کے ساتھ مل کر جامع فیصلے کریں ، اور فیصلہ سازی کی درستگی کو بہتر بنائیں۔

  6. غیر متعلقہ تعلقات کا استعمال کرتے ہوئے خطرے کو پھیلانے کے لئے ایک کثیر قسم کے ٹریڈنگ پورٹ فولیو کی تعمیر.

خلاصہ کریں۔

مجموعی طور پر ایک مضبوط رجحان کی پیروی کرنے والی حکمت عملی ہے ، جس میں رجحانات کی شناخت کی مضبوط صلاحیت اور خطرے پر قابو پانے کی صلاحیت ہے۔ پیرامیٹرز کی اصلاح ، متحرک پوزیشن مینجمنٹ وغیرہ کو شامل کرکے مزید اصلاحات کے ذریعہ ، یہ ایک بہت ہی عملی مقداری تجارتی حکمت عملی بن سکتی ہے۔ حکمت عملی کی سوچ واضح اور سمجھنے میں آسان ہے ، اور اس میں کچھ لچک بھی ہے ، جو گہری تحقیق اور استعمال اور مستقل اصلاح کے قابل ہے۔

حکمت عملی کا ماخذ کوڈ
/*backtest
start: 2023-10-13 00:00:00
end: 2023-11-12 00:00:00
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/
// © AugustoErni

//@version=5
strategy('Moving Average Rainbow (Stormer)', overlay=true)

maType                        = input.string('EMA', title='Moving Average Type/Tipo de Média Móvel', options=['EMA', 'SMA', 'RMA', 'WMA', 'HMA', 'VWMA'], tooltip='This option is to select the type of Moving Average that the Rainbow will use./Esta opção é para selecionar o tipo de Média Móvel que o Rainbow utilizará.', group='Moving Averages/Médias Móveis')
maLengthFirst                 = input.int(3, title='MA #1', minval=1, step=1, tooltip='First MA length./Comprimento da primeira MA.', group='Moving Averages/Médias Móveis')
maLengthSecond                = input.int(5, title='MA #2', minval=1, step=1, tooltip='Second MA length./Comprimento da segunda MA.', group='Moving Averages/Médias Móveis')
maLengthThird                 = input.int(8, title='MA #3', minval=1, step=1, tooltip='Third MA length./Comprimento da terceira MA.', group='Moving Averages/Médias Móveis')
maLengthFourth                = input.int(13, title='MA #4', minval=1, step=1, tooltip='Fourth MA length./Comprimento da quarta MA.', group='Moving Averages/Médias Móveis')
maLengthFifth                 = input.int(20, title='MA #5', minval=1, step=1, tooltip='Fifth MA length./Comprimento da quinta MA.', group='Moving Averages/Médias Móveis')
maLengthSixth                 = input.int(25, title='MA #6', minval=1, step=1, tooltip='Sixth MA length./Comprimento da sexta MA.', group='Moving Averages/Médias Móveis')
maLengthSeventh               = input.int(30, title='MA #7', minval=1, step=1, tooltip='Seventh MA length./Comprimento da sétima MA.', group='Moving Averages/Médias Móveis')
maLengthEighth                = input.int(35, title='MA #8', minval=1, step=1, tooltip='Eighth MA length./Comprimento da oitava MA.', group='Moving Averages/Médias Móveis')
maLengthNineth                = input.int(40, title='MA #9', minval=1, step=1, tooltip='Nineth MA length./Comprimento da nona MA.', group='Moving Averages/Médias Móveis')
maLengthTenth                 = input.int(45, title='MA #10', minval=1, step=1, tooltip='Tenth MA length./Comprimento da décima MA.', group='Moving Averages/Médias Móveis')
maLengthEleventh              = input.int(50, title='MA #11', minval=1, step=1, tooltip='Eleventh MA length./Comprimento da décima primeira MA.', group='Moving Averages/Médias Móveis')
maLengthTwelveth              = input.int(55, title='MA #12', minval=1, step=1, tooltip='Twelveth MA length./Comprimento da décima segunda MA.', group='Moving Averages/Médias Móveis')
targetFactor                  = input.float(1.6, title='Target Take Profit/Objetivo de Lucro Alvo', minval=0.1, step=0.1, tooltip='Calculate the take profit factor when entry position./Calcula o fator do alvo lucro ao entrar na posição.', group='Risk Management/Gerenciamento de Risco')
verifyTurnoverTrend           = input.bool(true, title='Verify Turnover Trend/Verificar Tendência de Rotatividade', tooltip='This option checks for a supposedly turnover trend and setup new target (for long is the highest high and for short is the lowest low identified)./Esta opção verifica uma suposta tendência de rotatividade e estabelece um novo objetivo (para long é a máxima mais alta, para short é a mínima mais baixa identificados).', group='Turnover Trend/Rotatividade Tendência')
verifyTurnoverSignal          = input.bool(false, title='Verify Turnover Signal/Verificar Sinal de Rotatividade', tooltip='This option checks for a supposedly turnover signal, closing the current position and opening a new one (for long it will close and open a new for short, for short it will close and open a new for long)./Essa opção verifica um sinal de possível reversão, fechando a posição atual e abrindo uma nova (para long fechará e abrirá uma nova para short, para short fechará e abrirá uma nova para long).', group='Turnover Signal/Rotatividade Sinal')
verifyTurnoverSignalPriceExit = input.bool(false, title='Verify Price Exit Turnover Signal/Verificar Saída de Preço Sinal de Rotatividade', tooltip='This option complements "turnover signal" by veryfing the price if profitable before exiting the current position./Esta opção complementa o "sinal de rotatividade" verificando o preço do lucro antes de sair da posição atual.', group='Turnover Signal/Rotatividade Sinal')

mas(maType, maLengthFirst, maLengthSecond, maLengthThird, maLengthFourth, maLengthFifth, maLengthSixth, maLengthSeventh, maLengthEighth, maLengthNineth, maLengthTenth, maLengthEleventh, maLengthTwelveth) =>
    if (maType == 'SMA')
        [ta.sma(close, maLengthFirst), ta.sma(close, maLengthSecond), ta.sma(close, maLengthThird), ta.sma(close, maLengthFourth), ta.sma(close, maLengthFifth), ta.sma(close, maLengthSixth), ta.sma(close, maLengthSeventh), ta.sma(close, maLengthEighth), ta.sma(close, maLengthNineth), ta.sma(close, maLengthTenth), ta.sma(close, maLengthEleventh), ta.sma(close, maLengthTwelveth)]
    else if (maType == 'RMA')
        [ta.rma(close, maLengthFirst), ta.rma(close, maLengthSecond), ta.rma(close, maLengthThird), ta.rma(close, maLengthFourth), ta.rma(close, maLengthFifth), ta.rma(close, maLengthSixth), ta.rma(close, maLengthSeventh), ta.rma(close, maLengthEighth), ta.rma(close, maLengthNineth), ta.rma(close, maLengthTenth), ta.rma(close, maLengthEleventh), ta.rma(close, maLengthTwelveth)]
    else if (maType == 'WMA')
        [ta.wma(close, maLengthFirst), ta.wma(close, maLengthSecond), ta.wma(close, maLengthThird), ta.wma(close, maLengthFourth), ta.wma(close, maLengthFifth), ta.wma(close, maLengthSixth), ta.wma(close, maLengthSeventh), ta.wma(close, maLengthEighth), ta.wma(close, maLengthNineth), ta.wma(close, maLengthTenth), ta.wma(close, maLengthEleventh), ta.wma(close, maLengthTwelveth)]
    else if (maType == 'HMA')
        [ta.hma(close, maLengthFirst), ta.hma(close, maLengthSecond), ta.hma(close, maLengthThird), ta.hma(close, maLengthFourth), ta.hma(close, maLengthFifth), ta.hma(close, maLengthSixth), ta.hma(close, maLengthSeventh), ta.hma(close, maLengthEighth), ta.hma(close, maLengthNineth), ta.hma(close, maLengthTenth), ta.hma(close, maLengthEleventh), ta.hma(close, maLengthTwelveth)]
    else if (maType == 'VWMA')
        [ta.vwma(close, maLengthFirst), ta.vwma(close, maLengthSecond), ta.vwma(close, maLengthThird), ta.vwma(close, maLengthFourth), ta.vwma(close, maLengthFifth), ta.vwma(close, maLengthSixth), ta.vwma(close, maLengthSeventh), ta.vwma(close, maLengthEighth), ta.vwma(close, maLengthNineth), ta.vwma(close, maLengthTenth), ta.vwma(close, maLengthEleventh), ta.vwma(close, maLengthTwelveth)]
    else
        [ta.ema(close, maLengthFirst), ta.ema(close, maLengthSecond), ta.ema(close, maLengthThird), ta.ema(close, maLengthFourth), ta.ema(close, maLengthFifth), ta.ema(close, maLengthSixth), ta.ema(close, maLengthSeventh), ta.ema(close, maLengthEighth), ta.ema(close, maLengthNineth), ta.ema(close, maLengthTenth), ta.ema(close, maLengthEleventh), ta.ema(close, maLengthTwelveth)]

[ma1, ma2, ma3, ma4, ma5, ma6, ma7, ma8, ma9, ma10, ma11, ma12] = mas(maType, maLengthFirst, maLengthSecond, maLengthThird, maLengthFourth, maLengthFifth, maLengthSixth, maLengthSeventh, maLengthEighth, maLengthNineth, maLengthTenth, maLengthEleventh, maLengthTwelveth)

maTouchPriceTrend(ma1, ma2, ma3, ma4, ma5, ma6, ma7, ma8, ma9, ma10, ma11, ma12, trend) =>
    var float touchPrice = na
    if (trend == 'UPTREND')
        if (low <= ma1 and low >= ma2)
            touchPrice := ma2
        else if (low <= ma2 and low >= ma3)
            touchPrice := ma3
        else if (low <= ma3 and low >= ma4)
            touchPrice := ma4
        else if (low <= ma4 and low >= ma5)
            touchPrice := ma5
        else if (low <= ma5 and low >= ma6)
            touchPrice := ma6
        else if (low <= ma6 and low >= ma7)
            touchPrice := ma7
        else if (low <= ma7 and low >= ma8)
            touchPrice := ma8
        else if (low <= ma8 and low >= ma9)
            touchPrice := ma9
        else if (low <= ma9 and low >= ma10)
            touchPrice := ma10
        else if (low <= ma10 and low >= ma11)
            touchPrice := ma11
        else if (low <= ma11 and low >= ma12)
            touchPrice := ma12
        else
            touchPrice := na
    else if (trend == 'DOWNTREND')
        if (high >= ma1 and high <= ma2)
            touchPrice := ma2
        else if (high >= ma2 and high <= ma3)
            touchPrice := ma3
        else if (high >= ma3 and high <= ma4)
            touchPrice := ma4
        else if (high >= ma4 and high <= ma5)
            touchPrice := ma5
        else if (high >= ma5 and high <= ma6)
            touchPrice := ma6
        else if (high >= ma6 and high <= ma7)
            touchPrice := ma7
        else if (high >= ma7 and high <= ma8)
            touchPrice := ma8
        else if (high >= ma8 and high <= ma9)
            touchPrice := ma9
        else if (high >= ma9 and high <= ma10)
            touchPrice := ma10
        else if (high >= ma10 and high <= ma11)
            touchPrice := ma11
        else if (high >= ma11 and high <= ma12)
            touchPrice := ma12
        else
            touchPrice := na

maMean = ((ma1 + ma2 + ma3 + ma4 + ma5 + ma6 + ma7 + ma8 + ma9 + ma10 + ma11 + ma12) / 12)

isMa1To4Above            = ma1 > ma2 and ma2 > ma3 and ma3 > ma4 ? 1 : 0
isMa1To4Below            = ma1 < ma2 and ma2 < ma3 and ma3 < ma4 ? 1 : 0
isMa5To8Above            = ma5 > ma6 and ma6 > ma7 and ma7 > ma8 ? 1 : 0
isMa5To8Below            = ma5 < ma6 and ma6 < ma7 and ma7 < ma8 ? 1 : 0
isCloseGreaterMaMean     = close > maMean ? 1 : 0
isCloseLesserMaMean      = close < maMean ? 1 : 0
isCurHighGreaterPrevHigh = high > high[1] ? 1 : 0
isCurLowLesserPrevLow    = low < low[1] ? 1 : 0
isMaUptrend              = isCloseGreaterMaMean and isMa5To8Above ? 1 : 0
isMaDowntrend            = isCloseLesserMaMean and isMa5To8Below ? 1 : 0
isUptrend                = isMaUptrend ? 'UPTREND' : na
isDowntrend              = isMaDowntrend ? 'DOWNTREND' : na

curTouchPriceUptrend    = maTouchPriceTrend(ma1, ma2, ma3, ma4, ma5, ma6, ma7, ma8, ma9, ma10, ma11, ma12, isUptrend)
prevTouchPriceUptrend   = curTouchPriceUptrend[1]
curTouchPriceDowntrend  = maTouchPriceTrend(ma1, ma2, ma3, ma4, ma5, ma6, ma7, ma8, ma9, ma10, ma11, ma12, isDowntrend)
prevTouchPriceDowntrend = curTouchPriceDowntrend[1]

isPrevTouchPriceUptrendTouched   = prevTouchPriceUptrend > 0.0 or not na(prevTouchPriceUptrend) ? 1 : 0
isPrevTouchPriceDowntrendTouched = prevTouchPriceDowntrend > 0.0 or not na(prevTouchPriceDowntrend) ? 1 : 0
isPrevTouchedPriceUptrend        = isPrevTouchPriceUptrendTouched and isMaUptrend ? 1 : 0
isPrevTouchedPriceDowntrend      = isPrevTouchPriceDowntrendTouched and isMaDowntrend ? 1 : 0

isPositionFlat  = strategy.position_size == 0 ? 1 : 0

var float positionEntryPrice         = na
var bool positionIsEntryLong         = false
var bool positionIsEntryShort        = false
var float longPositionHighestHigh    = na
var float shortPositionLowestLow     = na
var float stopLossLong               = na
var float stopLossShort              = na
var float targetLong                 = na
var float targetShort                = na
var bool isTurnoverTrendLongTrigger  = na
var bool isTurnoverTrendShortTrigger = na

isPositionLongClose  = na(positionEntryPrice) and not positionIsEntryLong ? 1 : 0
isPositionShortClose = na(positionEntryPrice) and not positionIsEntryShort ? 1 : 0
isLongCondition      = isMaUptrend and isCurHighGreaterPrevHigh and isPrevTouchedPriceUptrend ? 1 : 0
isShortCondition     = isMaDowntrend and isCurLowLesserPrevLow and isPrevTouchedPriceDowntrend ? 1 : 0
longTurnoverExit     = verifyTurnoverSignal and verifyTurnoverSignalPriceExit ? (verifyTurnoverSignal and isLongCondition and positionIsEntryShort and close < positionEntryPrice) : verifyTurnoverSignal ? (verifyTurnoverSignal and isLongCondition and positionIsEntryShort) : na
shortTurnoverExit    = verifyTurnoverSignal and verifyTurnoverSignalPriceExit ? (verifyTurnoverSignal and isShortCondition and positionIsEntryLong and close > positionEntryPrice) : verifyTurnoverSignal ? (verifyTurnoverSignal and isShortCondition and positionIsEntryLong) : na

if (isPositionFlat)
    positionEntryPrice          := na
    positionIsEntryLong         := false
    positionIsEntryShort        := false
    stopLossLong                := na
    targetLong                  := na
    stopLossShort               := na
    targetShort                 := na
    isTurnoverTrendLongTrigger  := na
    isTurnoverTrendShortTrigger := na

if ((isLongCondition and isPositionLongClose) or longTurnoverExit)
    positionEntryPrice          := close
    positionIsEntryLong         := true
    positionIsEntryShort        := false
    longPositionHighestHigh     := na
    shortPositionLowestLow      := na
    isTurnoverTrendLongTrigger  := na
    isTurnoverTrendShortTrigger := na
    stopLossLong                := prevTouchPriceUptrend
    if (isCurLowLesserPrevLow)
        curLowToucedPrice = na(curTouchPriceUptrend) ? low : curTouchPriceUptrend
        stopLossLong      := na(curTouchPriceUptrend) ? ((stopLossLong + curLowToucedPrice) / 2) : curLowToucedPrice
    targetLong := (positionEntryPrice + (math.abs(positionEntryPrice - stopLossLong) * targetFactor))
    if (targetLong > 0 and stopLossLong > 0)
        alertMessage = '{ "side/lado": "buy", "entry/entrada": ' + str.tostring(positionEntryPrice) + ', "stop": ' + str.tostring(stopLossLong) + ', "target/alvo": ' + str.tostring(targetLong) + ' }'
        alert(alertMessage)
        strategy.entry('Long', strategy.long)
        strategy.exit('Exit Long', 'Long', stop=stopLossLong, limit=targetLong)

if ((isShortCondition and isPositionShortClose) or shortTurnoverExit)
    positionEntryPrice          := close
    positionIsEntryLong         := false
    positionIsEntryShort        := true
    longPositionHighestHigh     := na
    shortPositionLowestLow      := na
    isTurnoverTrendLongTrigger  := na
    isTurnoverTrendShortTrigger := na
    stopLossShort               := prevTouchPriceDowntrend
    if (isCurHighGreaterPrevHigh)
        curHighToucedPrice = na(curTouchPriceDowntrend) ? high : curTouchPriceDowntrend
        stopLossShort      := na(curTouchPriceDowntrend) ? ((stopLossShort + curHighToucedPrice) / 2) : curHighToucedPrice
    targetShort := (positionEntryPrice - (math.abs(positionEntryPrice - stopLossShort) * targetFactor))
    if (targetShort > 0 and stopLossShort > 0)
        alertMessage = '{ "side/lado": "sell", "entry/entrada": ' + str.tostring(positionEntryPrice) + ', "stop": ' + str.tostring(stopLossShort) + ', "target/alvo": ' + str.tostring(targetShort) + ' }'
        alert(alertMessage)
        strategy.entry('Short', strategy.short)
        strategy.exit('Exit Short', 'Short', stop=stopLossShort, limit=targetShort)

if (verifyTurnoverTrend and positionIsEntryLong)
    curHighestHigh = high
    if (curHighestHigh > longPositionHighestHigh or na(longPositionHighestHigh))
        longPositionHighestHigh := curHighestHigh
    if (isMa1To4Below and isCloseLesserMaMean and longPositionHighestHigh > positionEntryPrice)
        isTurnoverTrendLongTrigger := true
        alertMessage = '{ "side/lado": "buy", "stop": ' + str.tostring(stopLossLong) + ', "target/alvo": ' + str.tostring(longPositionHighestHigh) + ', "new setup/nova definição": ' + str.tostring(isTurnoverTrendLongTrigger) + ' }'
        alert(alertMessage)
        strategy.exit('Exit Long', 'Long', stop=stopLossLong, limit=longPositionHighestHigh)

if (verifyTurnoverTrend and positionIsEntryShort)
    curLowestLow = low
    if (curLowestLow < shortPositionLowestLow or na(shortPositionLowestLow))
        shortPositionLowestLow := curLowestLow
    if (isMa1To4Above and isCloseGreaterMaMean and shortPositionLowestLow < positionEntryPrice)
        isTurnoverTrendShortTrigger := true
        alertMessage = '{ "side/lado": "sell", "stop": ' + str.tostring(stopLossShort) + ', "target/alvo": ' + str.tostring(shortPositionLowestLow) + ', "new setup/nova definição": ' + str.tostring(isTurnoverTrendShortTrigger) + ' }'
        alert(alertMessage)
        strategy.exit('Exit Short', 'Short', stop=stopLossShort, limit=shortPositionLowestLow)

plot(ma1, title='1st Moving Average', color=color.rgb(240, 240, 240))
plot(ma2, title='2nd Moving Average', color=color.rgb(220, 220, 220))
plot(ma3, title='3rd Moving Average', color=color.rgb(200, 200, 200))
plot(ma4, title='4th Moving Average', color=color.rgb(180, 180, 180))
plot(ma5, title='5th Moving Average', color=color.rgb(160, 160, 160))
plot(ma6, title='6th Moving Average', color=color.rgb(140, 140, 140))
plot(ma7, title='7th Moving Average', color=color.rgb(120, 120, 120))
plot(ma8, title='8th Moving Average', color=color.rgb(100, 120, 120))
plot(ma9, title='9th Moving Average', color=color.rgb(80, 120, 120))
plot(ma10, title='10th Moving Average', color=color.rgb(60, 120, 120))
plot(ma11, title='11th Moving Average', color=color.rgb(40, 120, 120))
plot(ma12, title='12th Moving Average', color=color.rgb(20, 120, 120))

tablePosition    = position.bottom_right
tableColumns     = 2
tableRows        = 7
tableFrameWidth  = 1
tableBorderColor = color.gray
tableBorderWidth = 1
tableInfoTrade   = table.new(position=tablePosition, columns=tableColumns, rows=tableRows, frame_width=tableFrameWidth, border_color=tableBorderColor, border_width=tableBorderWidth)

table.cell(table_id=tableInfoTrade, column=0, row=0)
table.cell(table_id=tableInfoTrade, column=1, row=0)

table.cell(table_id=tableInfoTrade, column=0, row=1, text='Entry Side/Lado da Entrada', text_color=color.white)
table.cell(table_id=tableInfoTrade, column=0, row=2, text=positionIsEntryLong ? 'LONG' : positionIsEntryShort ? 'SHORT' : 'NONE/NENHUM', text_color=color.yellow)

table.cell(table_id=tableInfoTrade, column=1, row=1, text='Entry Price/Preço da Entrada', text_color=color.white)
table.cell(table_id=tableInfoTrade, column=1, row=2, text=not na(positionEntryPrice) ? str.tostring(positionEntryPrice) : 'NONE/NENHUM', text_color=color.blue)

table.cell(table_id=tableInfoTrade, column=0, row=3, text='Take Profit Price/Preço Alvo Lucro', text_color=color.white)
table.cell(table_id=tableInfoTrade, column=0, row=4, text=positionIsEntryLong ? str.tostring(targetLong) : positionIsEntryShort ? str.tostring(targetShort) : 'NONE/NENHUM', text_color=color.green)

table.cell(table_id=tableInfoTrade, column=1, row=3, text='Stop Loss Price/Preço Stop Loss', text_color=color.white)
table.cell(table_id=tableInfoTrade, column=1, row=4, text=positionIsEntryLong ? str.tostring(stopLossLong) : positionIsEntryShort ? str.tostring(stopLossShort) : 'NONE/NENHUM', text_color=color.red)

table.cell(table_id=tableInfoTrade, column=0, row=5, text='New Target/Novo Alvo', text_color=color.white)
table.cell(table_id=tableInfoTrade, column=0, row=6, text=verifyTurnoverTrend and positionIsEntryLong and isTurnoverTrendLongTrigger ? str.tostring(longPositionHighestHigh) : verifyTurnoverTrend and positionIsEntryShort and isTurnoverTrendShortTrigger ? str.tostring(shortPositionLowestLow) : 'NONE/NENHUM', text_color=color.green)

table.cell(table_id=tableInfoTrade, column=1, row=5, text='Possible Market Turnover/Possível Virada do Mercado', text_color=color.white)
table.cell(table_id=tableInfoTrade, column=1, row=6, text=verifyTurnoverTrend and positionIsEntryLong and isTurnoverTrendLongTrigger ? 'YES/SIM (Possible long going short/Possível long indo short)' : verifyTurnoverTrend and positionIsEntryShort and isTurnoverTrendShortTrigger ? 'YES/SIM (Possible short going long/Possível short indo long)' : 'NONE/NENHUM', text_color=color.red)