برای کانال رگرسیون خطی ، می توان نحوه ادامه نمایش صفحه نمایش آن را به سمت راست (خاصیت OBJPROP_RAY_RIGHT) مشخص کرد. حالت پر کردن کانال با رنگ نیز می تواند تنظیم شود.
اسکریپت زیر کانال رگرسیون خطی را در نمودار ایجاد و حرکت می دهد. توابع ویژه ای برای ایجاد و تغییر خصوصیات شیء گرافیکی ایجاد شده است. شما می توانید از این توابع "همانطور که هست" در برنامه های خود استفاده کنید.
#Property Strict // --- توضیحات #Property توضیحات "اسکریپت ترسیم می کند \" کانال رگرسیون خطی \ "شیء گرافیکی".#توضیحات #Property "مختصات نقطه لنگر در درصد اندازه" #Property توضیحات "پنجره نمودار" تنظیم شده است.// --- پنجره نمایش پارامترهای ورودی در هنگام راه اندازی اسکریپت #Property script_show_inputs // --- پارامترهای ورودی رشته ورودی اسکریپت inpname = "رگرسیون" ؛// نام کانال ورودی int inpdate1 = 10 ؛// تاریخ 1 ST Point ، ٪ int inpdate2 = 40 ؛// تاریخ 2 نقطه ، ٪ رنگ ورودی inpcolor = clrred ؛// input input enum_line_style inpstyle = style_dash ؛// سبک خطوط کانال ورودی int inpwidth = 1 ؛// عرض خطوط کانال ورودی BOOL INPFILL = FALSE ؛// پر کردن کانال با ورودی ورودی BOOL INPBACK = FALSE ؛// ورودی کانال پس زمینه BOOL INPSELECTION = TRUE ؛// برجسته برای حرکت ورودی BOOL inprayright = false ؛// ادامه کانال به ورودی ورودی راست inphidden = true ؛// پنهان در لیست شیء ورودی طولانی inpzorder = 0 ؛// اولویت برای کلیک ماوس //+----------------------------------------------------------------------+ // |ایجاد کانال رگرسیون خطی توسط مختصات داده شده |//+--------------------------------------------------------------------------+ BOOL RegressionCreate (Const Long Chart_ID = 0 ، // شناسه نمودار نام رشته نام = "رگرسیون" ، // نام کانال const int sub_window = 0، // شاخص Subwindow DateTime Time1 = 0 ، // زمان اول DateTime Time2 = 0 ، // زمان دوم Const Color CLR = Clrred ، // Conline Const Const Enum_line_Style = Style_Solid ، // سبک خطوط کانال const int width= 1 ، // عرض خطوط کانال const bool fill = flate ، // پر کردن کانال با رنگ const bool back = false ، // در پس زمینه انتخاب const bool = true ، // برجسته برای حرکت const bool ray_right = false ،// ادامه کانال به سمت راست Const Bool Hidden = True ، // پنهان در لیست شیء Const Long Z_ORDER = 0) // اولویت برای کلیک ماوس< //--- set anchor points' coordinates if they are not set ChangeRegressionEmptyPoints(time1,time2); //--- reset the error value ResetLastError (); //--- create a channel by the given coordinates if (! ObjectCreate (chart_ID,name, OBJ_REGRESSION ,sub_window,time1,0,time2,0)) < Print ( __FUNCTION__ , ": failed to create linear regression channel! Error code = " , GetLastError ()); return ( false ); > //--- set channel color ObjectSetInteger (chart_ID,name, OBJPROP_COLOR ,clr); //--- set style of the channel lines ObjectSetInteger (chart_ID,name, OBJPROP_STYLE ,style); //--- set width of the channel lines ObjectSetInteger (chart_ID,name, OBJPROP_WIDTH ,width); //--- display in the foreground (false) or background (true) ObjectSetInteger (chart_ID,name, OBJPROP_BACK ,back); //--- enable (true) or disable (false) the mode of highlighting the channel for moving //--- when creating a graphical object using ObjectCreate function, the object cannot be //--- highlighted and moved by default. Inside this method, selection parameter //--- is true by default making it possible to highlight and move the object ObjectSetInteger (chart_ID,name, OBJPROP_SELECTABLE ,selection); ObjectSetInteger (chart_ID,name, OBJPROP_SELECTED ,selection); //--- enable (true) or disable (false) the mode of continuation of the channel's display to the right ObjectSetInteger (chart_ID,name, OBJPROP_RAY_RIGHT ,ray_right); //--- hide (true) or display (false) graphical object name in the object list ObjectSetInteger (chart_ID,name, OBJPROP_HIDDEN ,hidden); //--- set the priority for receiving the event of a mouse click in the chart ObjectSetInteger (chart_ID,name, OBJPROP_ZORDER ,z_order); //--- successful execution return ( true ); >//+-----------------------------------------------------------------+ //|جابجایی نقطه لنگر کانال |//+-----------------------------------------------------------------+ bool RegressionPointChange( const long chart_ID=0, // شناسه نمودار const string name= "Channel" , // نام کانال const int point_index=0، // نقطه لنگر index datetime time=0) // نقطه لنگر مختصات زمانی< //--- if point time is not set, move the point to the current bar if (!time) time= TimeCurrent (); //--- reset the error value ResetLastError (); //--- move the anchor point if (! ObjectMove (chart_ID,name,point_index,time,0)) < Print ( __FUNCTION__ , ": failed to move the anchor point! Error code = " , GetLastError ()); return ( false ); > //--- successful execution return ( true ); >//+-----------------------------------------------------------------+ //|حذف کانال |//+-----------------------------------------------------------------+ bool RegressionDelete( const long chart_ID=0, // شناسه نمودار const string name= "Channel" ) // نام کانال< //--- reset the error value ResetLastError (); //--- delete the channel if (! ObjectDelete (chart_ID,name)) < Print ( __FUNCTION__ , ": failed to delete the channel! Error code = " , GetLastError ()); return ( false ); > //--- successful execution return ( true ); >//+------------------------------------------------------------------------+ //|مقادیر لنگرهای کانال را بررسی کنید و مقادیر پیش فرض | را تنظیم کنید//|برای خالی ها |//+------------------------------------------------------------------------+ void ChangeRegressionEmptyPoints (تاریخ و زمان1، تاریخ و ساعت2)< //--- if the second point's time is not set, it will be on the current bar if (!time2) time2= TimeCurrent (); //--- if the first point's time is not set, it is located 9 bars left from the second one if (!time1) < //--- array for receiving the open time of the last 10 bars datetime temp[10]; CopyTime ( Symbol (), Period (),time2,10,temp); //--- set the first point 9 bars left from the second one time1=temp[0]; > >//+-----------------------------------------------------------------+ //|تابع شروع برنامه اسکریپت |//+-----------------------------------------------------------------+ void OnStart ()< //--- check correctness of the input parameters if ( InpDate1 100 || InpDate2 100) < Print ( "Error! Incorrect values of input parameters!" ); return ; >//--- تعداد نوارهای قابل مشاهده در پنجره نمودار int bars =( int ) ChartGetInteger (0, CHART_VISIBLE_BARS );//--- قیمت آرایه اندازه int accuracy=1000;//--- آرایه هایی برای ذخیره تاریخ و مقادیر قیمتی که باید استفاده شوند //--- برای تنظیم و تغییر مختصات نقطه لنگر کانال datetime date[]; دو قیمت[];//--- تخصیص حافظه ArrayResize (تاریخ، نوارها)؛ArrayResize (قیمت، دقت)؛//--- پر کردن آرایه تاریخ ResetLastError (); if ( CopyTime ( نماد ()، دوره ()، 0، نوارها، تاریخ)==-1)< Print ( "Failed to copy time values! Error code = " , GetLastError ()); return ; > //--- fill the array of prices //--- find the highest and lowest values of the chart double max_price= ChartGetDouble (0, CHART_PRICE_MAX ); double min_price= ChartGetDouble (0, CHART_PRICE_MIN ); //--- define a change step of a price and fill the array double step=(max_price-min_price)/accuracy; for ( int i=0;i