ماہانہ کارکردگی PnL کیلنڈر کی حکمت عملی

مصنف:چاؤ ژانگ، تاریخ: 2024-01-08 16:16:58
ٹیگز:

img

جائزہ

اس حکمت عملی کا بنیادی کام ماہانہ کارکردگی کو حقیقی وقت میں ٹریک کرنا اور ظاہر کرنا ہے۔ یہ حقیقی وقت میں ایک ٹیبل میں ہر ماہ کے منافع اور نقصان کو اپ ڈیٹ کرے گا۔

اصول

اسٹریٹیجی میں ماہانہ کارکردگی کی نگرانی مندرجہ ذیل مراحل کے ذریعے حاصل کی جاتی ہے:

  1. متغیرات کی وضاحت کریں تاکہ ریکارڈ کیا جا سکے کہ اس مہینے میں بند تجارتیں ہیں یا نہیں۔
  2. ہر مہینے کے مخصوص منافع اور نقصان کی قیمت کو ریکارڈ کرنے کے لئے متغیرات کی وضاحت کریں.
  3. وقت کے مطابق مہینے کو ریکارڈ کرنے کے لئے متغیرات کی وضاحت کریں.
  4. جب اس مہینے میں بند تجارتیں ہوں تو ماہانہ PnL اور مہینے کو متعلقہ صفوں میں ریکارڈ کریں۔
  5. ٹیبل میں مخصوص مقامات پر مہینے کے عنوانات دکھائیں۔
  6. ماہانہ PnL صف کو عبور کریں اور ٹیبل میں ماہ کے متعلقہ کالموں میں PnL اقدار دکھائیں۔
  7. اسی وقت متعلقہ سال کی معلومات دکھائیں.
  8. ہر سال کے پی این ایل کا خلاصہ کریں۔
  9. مثبت اور منفی PnLs کو الگ کرنے کے لئے رنگ استعمال کریں.

مندرجہ بالا اس حکمت عملی کے بنیادی اقدامات اور کام کرنے کے اصول ہیں۔

فوائد کا تجزیہ

اس طرح کی ماہانہ کارکردگی کی نگرانی کی حکمت عملی میں مندرجہ ذیل فوائد ہیں:

  1. کسی بھی وقت تازہ ترین ماہانہ پی این ایل کی حیثیت دیکھنے کے لئے ریئل ٹائم اپ ڈیٹ۔
  2. ٹیبلز میں مخصوص ماہانہ PnL کی بدیہی نمائش۔
  3. ہر مہینے کی تفصیلات واضح طور پر دیکھنے کے لئے ٹھیک اناج.
  4. ماہانہ PnLs کو زیادہ بصری طور پر متضاد کرنے کے لئے رنگوں کا استعمال کرتے ہوئے بدیہی موازنہ.
  5. شماریاتی جمع بھی سالانہ PnL جمع فراہم کرتا ہے.
  6. ٹیبل کی جگہ، سائز وغیرہ کو ایڈجسٹ کرنے کے لئے مرضی کے مطابق ڈسپلے

خطرے کا تجزیہ

اس حکمت عملی میں کچھ خطرات بھی ہیں:

  1. پیچیدہ منطق غلطیوں کی وجہ سے غلط اعداد و شمار کا سبب بن سکتی ہے.
  2. ٹیبل کو زیادہ بار بار تازہ کاری کرنے سے کارکردگی متاثر ہوسکتی ہے۔
  3. صف ڈیٹا اسٹوریج کم موثر ہے.
  4. وقت اور مہینے کے تبادلوں کے حساب غلط ہو سکتے ہیں۔

خطرات کو مندرجہ ذیل طریقوں سے کم کیا جا سکتا ہے:

  1. درست منطق کو یقینی بنانے کے لئے سخت کوڈ کا جائزہ لیں.
  2. زیادہ سے زیادہ تازہ کاری سے بچنے کے لئے تازہ کاری کی تعدد کو بہتر بنائیں.
  3. ڈیٹا کو ذخیرہ کرنے کے لئے زیادہ موثر ڈیٹا ڈھانچے کا استعمال کریں۔
  4. وقت اور مہینے کے تبادلوں کے لئے استثناء ہینڈلنگ شامل کریں.

اصلاح

اس حکمت عملی کی اصلاحات:

  1. ماہانہ اعداد و شمار کو ذخیرہ کرنے کے لئے لغات جیسے زیادہ موثر ڈیٹا ڈھانچے کا استعمال کریں۔
  2. سالانہ واپسی کے حسابات شامل کریں.
  3. تبدیلی کی شرح کی طرح دیگر میٹرکس شامل کریں.
  4. بصری طور پر واپسی منحنی خطوط دکھائیں.
  5. اعداد و شمار کے لئے اپنی مرضی کے مطابق وقت کی حد کی حمایت.
  6. CSV فائلوں میں ڈیٹا برآمد کرنے کی حمایت.

یہ حکمت عملی کی فعالیت اور صارف کے تجربے کو بہتر بنا سکتے ہیں۔

نتیجہ

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


/*backtest
start: 2023-01-01 00:00:00
end: 2024-01-07 00:00:00
period: 1d
basePeriod: 1h
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/
// © MAURYA_ALGO_TRADER

//@version=5
strategy("Monthly Performance", overlay=true)

period = input(20, "Length")

longCondition =   close > high[20]  //ta.crossover(ta.sma(close, 14), ta.sma(close, 28))
if (longCondition)
    strategy.entry("My Long Entry Id", strategy.long)

shortCondition = close < low[20]  //ta.crossunder(ta.sma(close, 14), ta.sma(close, 28))
if (shortCondition)
    strategy.entry("My Short Entry Id", strategy.short)



// Copy below code to end of the desired strategy script
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                 monthly pnl performance  by Dr. Maurya @MAURYA_ALGO_TRADER                        //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
show_performance = input.bool(true, 'Show Monthly Monthly Performance ?', group='Monthly Performance')

dash_loc_mp = input("Bottom Right","Location"  ,options=["Top Right","Bottom Right","Top Left","Bottom Left", "Middle Right","Bottom Center"]  ,group='Monthly Performance', inline = "performance")

text_size_mp = input('Small',"Size"  ,options=["Tiny","Small","Normal","Large"]  ,group='Monthly Performance', inline = "performance")

var table_position_mp = dash_loc_mp == 'Top Left' ? position.top_left :
  dash_loc_mp == 'Bottom Left' ? position.bottom_left :
  dash_loc_mp == 'Middle Right' ? position.middle_right :
  dash_loc_mp == 'Bottom Center' ? position.bottom_center :
  dash_loc_mp == 'Top Right' ? position.top_right : position.bottom_right
  
var table_text_size_mp = text_size_mp == 'Tiny' ? size.tiny :
  text_size_mp == 'Small' ? size.small :
  text_size_mp == 'Normal' ? size.normal : size.large

/////////////////
text_c = color.white

/////////////////////////////////////////////

// var bool new_month = na
new_month = ta.change(month) //> 0 ? true : false
newest_month = new_month and strategy.closedtrades >= 1
strategy.initial_capital = 50000
// profit
only_profit = strategy.netprofit
initial_balance = strategy.initial_capital

// month number
var int month_number = na
month_number := (ta.valuewhen(newest_month, month(time), 0)) //and month(time) > 1 ? (ta.valuewhen(newest_month, month(time), 0) - 1) :  12 //1 to 12

//month_year
var int month_time = na
month_time := ta.valuewhen(newest_month, time, 0) - 2419200000 


var int m_counter = 0
if newest_month
    m_counter += 1



// current month values
var bool new_year = na
new_year := ta.change(year)
curr_m_pnl = only_profit - nz(ta.valuewhen(newest_month, only_profit, 0), 0)
curr_m_number = newest_month ? ta.valuewhen(newest_month, month(time), 0) : month(time)
curr_y_pnl = (only_profit - nz(ta.valuewhen(new_year, only_profit, 0),0)) 



var float [] net_profit_array = array.new_float()
var int [] month_array = array.new_int()
var int [] month_time_array = array.new_int()


if newest_month
    array.push(net_profit_array, only_profit)
    array.push(month_array, month_number)
    array.push(month_time_array, month_time)



var float [] y_pnl_array = array.new_float()
var int [] y_number_array = array.new_int()
var int [] y_time_array = array.new_int()

newest_year = ta.change(year) and strategy.closedtrades >= 1
get_yearly_pnl = nz(ta.valuewhen(newest_year, strategy.netprofit, 0) - nz(ta.valuewhen(newest_year, strategy.netprofit, 1), 0), 0)
get_m_year = ta.valuewhen(newest_year, year(time), 1)
get_y_time = ta.valuewhen(newest_year, time, 0)

if newest_year
    array.push(y_pnl_array, get_yearly_pnl)
    array.push(y_number_array, get_m_year)
    array.push(y_time_array, get_y_time)
var float monthly_profit = na
var int column_month_number = na
var int row_month_time = na

 


var testTable = table.new(position = table_position_mp, columns = 14, rows = 40, bgcolor = color.rgb(7, 226, 242, 38), border_color = color.white, border_width = 1)
if barstate.islastconfirmedhistory and show_performance
    table.cell(table_id = testTable, column = 0, row = 0, text = "YEAR", text_color = text_c, text_size=table_text_size_mp)
    table.cell(table_id = testTable, column = 1, row = 0, text = "JAN", text_color = text_c, text_size=table_text_size_mp)
    table.cell(table_id = testTable, column = 2, row = 0, text = "FEB", text_color = text_c, text_size=table_text_size_mp)
    table.cell(table_id = testTable, column = 3, row = 0, text = "MAR", text_color = text_c, text_size=table_text_size_mp)
    table.cell(table_id = testTable, column = 4, row = 0, text = "APR", text_color = text_c, text_size=table_text_size_mp)
    table.cell(table_id = testTable, column = 5, row = 0, text = "MAY", text_color = text_c, text_size=table_text_size_mp)
    table.cell(table_id = testTable, column = 6, row = 0, text = "JUN", text_color = text_c, text_size=table_text_size_mp)
    table.cell(table_id = testTable, column = 7, row = 0, text = "JUL", text_color = text_c, text_size=table_text_size_mp)
    table.cell(table_id = testTable, column = 8, row = 0, text = "AUG", text_color = text_c, text_size=table_text_size_mp)
    table.cell(table_id = testTable, column = 9, row = 0, text = "SEP", text_color = text_c, text_size=table_text_size_mp)
    table.cell(table_id = testTable, column = 10, row = 0, text = "OCT", text_color = text_c, text_size=table_text_size_mp)
    table.cell(table_id = testTable, column = 11, row = 0, text = "NOV", text_color = text_c, text_size=table_text_size_mp)
    table.cell(table_id = testTable, column = 12, row = 0, text = "DEC", text_color = text_c, text_size=table_text_size_mp)
    table.cell(table_id = testTable, column = 13, row = 0, text = "YEAR P/L", text_color = text_c, text_size=table_text_size_mp)

    for i = 0 to (array.size(y_number_array) == 0 ? na : array.size(y_number_array) - 1)
        row_y = year(array.get(y_time_array, i)) - year(array.get(y_time_array, 0)) + 1
        table.cell(table_id = testTable, column = 13, row = row_y, text = str.tostring(array.get(y_pnl_array , i), "##.##") + '\n' + '(' + str.tostring(array.get(y_pnl_array , i)*100/initial_balance, "##.##") + ' %)', bgcolor = array.get(y_pnl_array , i) > 0 ? color.green : array.get(y_pnl_array , i) < 0 ? color.red : color.gray, text_color = color.rgb(0, 0, 0), text_size=table_text_size_mp)
    curr_row_y = array.size(month_time_array) == 0 ? 1 : (year(array.get(month_time_array, array.size(month_time_array) - 1))) - (year(array.get(month_time_array, 0))) + 1
    table.cell(table_id = testTable, column = 13, row = curr_row_y, text = str.tostring(curr_y_pnl, "##.##") + '\n' + '(' + str.tostring(curr_y_pnl*100/initial_balance, "##.##") + ' %)', bgcolor = curr_y_pnl > 0 ? color.green : curr_y_pnl < 0 ? color.red : color.gray, text_color = color.rgb(0, 0, 0), text_size=table_text_size_mp)
    

    for i = 0 to (array.size(net_profit_array) == 0 ? na : array.size(net_profit_array) - 1)
        monthly_profit := i > 0 ? ( array.get(net_profit_array, i) - array.get(net_profit_array, i - 1) ) : array.get(net_profit_array, i) 
        column_month_number := month(array.get(month_time_array, i)) 
        row_month_time :=((year(array.get(month_time_array, i))) - year(array.get(month_time_array, 0)) ) + 1 
        table.cell(table_id = testTable, column = column_month_number, row = row_month_time, text = str.tostring(monthly_profit, "##.##") + '\n' + '(' + str.tostring(monthly_profit*100/initial_balance, "##.##") + ' %)', bgcolor = monthly_profit > 0 ? color.green : monthly_profit < 0 ? color.red : color.gray, text_color = text_c, text_size=table_text_size_mp)
        table.cell(table_id = testTable, column = 0, row =row_month_time, text = str.tostring(year(array.get(month_time_array, i)), "##.##"), text_color = text_c, text_size=table_text_size_mp)
       
    curr_row_m = array.size(month_time_array) == 0 ? 1 : (year(array.get(month_time_array, array.size(month_time_array) - 1))) - (year(array.get(month_time_array, 0))) + 1
    table.cell(table_id = testTable, column = curr_m_number, row = curr_row_m, text = str.tostring(curr_m_pnl, "##.##") + '\n' + '(' + str.tostring(curr_m_pnl*100/initial_balance, "##.##") + ' %)', bgcolor = curr_m_pnl > 0 ? color.green : curr_m_pnl < 0 ? color.red : color.gray, text_color = text_c, text_size=table_text_size_mp)
    table.cell(table_id = testTable, column = 0, row =curr_row_m, text = str.tostring(year(time), "##.##"), text_color = text_c, text_size=table_text_size_mp)

//============================================================================================================================================================================

مزید