표시기(별도 창) 안에 텍스트를 삽입하는 방법의 예를 볼 수 있습니까?
감사해요
나는 시도했다
if ( ObjectFind ( 0 ,label_name)< 0 ) { Print ( "Generating a label" ); ObjectCreate ( 0 ,label_name, OBJ_LABEL , 0 , 0 , 0 ); ObjectSetInteger ( 0 ,label_name, OBJPROP_XDISTANCE , 10 ); ObjectSetInteger ( 0 ,label_name, OBJPROP_YDISTANCE , 30 ); ObjectSetInteger ( 0 ,label_name, OBJPROP_COLOR , YellowGreen ); ObjectSetString ( 0 ,label_name, OBJPROP_TEXT , "This is an example text inside chart window" ); ObjectSetString ( 0 ,label_name, OBJPROP_FONT , "Arial" ); ObjectSetInteger ( 0 ,label_name, OBJPROP_FONTSIZE , 14 ); ObjectSetInteger ( 0 ,label_name, OBJPROP_SELECTABLE ,false); ChartRedraw ( 0 ); } int window=- 1 ; if (( ENUM_PROGRAM_TYPE ) MQL5InfoInteger ( MQL5_PROGRAM_TYPE )== PROGRAM_INDICATOR ) { window= ChartWindowFind (); Print (window); } if ( ObjectFind (window,label2_name)< 0 ) { Print ( "Generating a label2" ); ObjectCreate (window,label2_name, OBJ_LABEL , 0 , 0 , 0 ); Print ( GetLastError ()); ObjectSetInteger (window,label2_name, OBJPROP_XDISTANCE , 10 ); ObjectSetInteger (window,label2_name, OBJPROP_YDISTANCE , 30 ); ObjectSetInteger (window,label2_name, OBJPROP_COLOR , YellowGreen ); ObjectSetString (window,label2_name, OBJPROP_TEXT , "This is an example text inside indicator, cool, huh?" ); ObjectSetString (window,label2_name, OBJPROP_FONT , "Arial" ); ObjectSetInteger (window,label2_name, OBJPROP_FONTSIZE , 14 ); ObjectSetInteger (window,label2_name, OBJPROP_SELECTABLE ,false); ChartRedraw (window); }
하지만
ObjectCreate (window,label2_name, OBJ_LABEL , 0 , 0 , 0 );
오류 4101을 반환합니다.
어떤 아이디어? (MT5 빌드 237)
http://clip2net.com/clip/m19204/1263295278-clip-38kb.png
차트에만 있지만 지표에는 없습니다.
누군가가 나를 도와주기를 원하면 표시기의 코드를 업로드합니다.
나는 기꺼이 제안을 수락하고 수정합니다 .....
감사합니다
다른 구성을 시도했지만 MT5의 표시기 창 내부에 모든 개체가 허용되지 않는 것으로 나타났습니다.
보다
https://www.mql5.com/en/docs/index
사용자 지정 지표 섹션은 다음과 같이 말합니다.
Custom Indicator 는 이미 클라이언트 터미널에 통합된 것 외에 독립적으로 작성된 기술 지표입니다. 내장 지표와 마찬가지로 자동으로 거래할 수 없으며 분석 기능을 구현하기 위한 용도로만 사용됩니다.
사용자 지정 지표는 차트 또는 차트 개체 작업에 함수를 사용할 수 없습니다. 사용자 지정 표시기는 terminal_directory \MQL5\Indicators 에 저장됩니다.
따라서 표시기 창에 텍스트를 넣는 유일한 방법은 INDICATOR_SHORTNAME 속성을 설정하는 것 입니다.
예
IndicatorSetString(INDICATOR_SHORTNAME,"안녕하세요 "+label2_name+"...");
내가 틀렸다면 정정하십시오.
친애하는
한 가지 부탁드립니다. 예를 들어 주시겠습니까?
감사해요
현재로서는 가능합니다. 시도하십시오.
Rosh, 빌드 238을 사용하여 달성하려고 했지만 여전히 운이 없습니다. 이 코드 조각
#property indicator_separate_window #property indicator_buffers 1 #property indicator_plots 1 #property indicator_minimum 0 #property indicator_maximum 100 string label_name= "mainwindow_label" ; string label2_name= "indicator_label" ; int window=- 1 ; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping //--- return ( 0 ); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate( const int rates_total, const int prev_calculated, const datetime & time[], const double & open[], const double & high[], const double & low[], const double & close[], const long & tick_volume[], const long & volume[], const int & spread[]) { //--- //--- return value of prev_calculated for next call if ( ObjectFind ( 0 ,label_name)< 0 ) { Print ( "Generating a label" ); ObjectCreate ( 0 ,label_name, OBJ_LABEL , 0 , 0 , 0 ); ObjectSetInteger ( 0 ,label_name, OBJPROP_XDISTANCE , 10 ); ObjectSetInteger ( 0 ,label_name, OBJPROP_YDISTANCE , 30 ); ObjectSetInteger ( 0 ,label_name, OBJPROP_COLOR , YellowGreen ); ObjectSetString ( 0 ,label_name, OBJPROP_TEXT , "This is an example text inside chart window" ); ObjectSetString ( 0 ,label_name, OBJPROP_FONT , "Arial" ); ObjectSetInteger ( 0 ,label_name, OBJPROP_FONTSIZE , 14 ); ObjectSetInteger ( 0 ,label_name, OBJPROP_SELECTABLE ,false); ChartRedraw ( 0 ); } if (( ENUM_PROGRAM_TYPE ) MQL5InfoInteger ( MQL5_PROGRAM_TYPE )== PROGRAM_INDICATOR ) { window= ChartWindowFind (); Print (window); } if ( ObjectFind (window,label2_name)< 0 ) { Print ( "Generating a label2" ); ObjectCreate (window,label2_name, OBJ_LABEL , 0 , 0 , 0 ); Print ( GetLastError ()); ObjectSetInteger (window,label2_name, OBJPROP_XDISTANCE , 10 ); ObjectSetInteger (window,label2_name, OBJPROP_YDISTANCE , 10 ); ObjectSetInteger (window,label2_name, OBJPROP_COLOR , YellowGreen ); ObjectSetString (window,label2_name, OBJPROP_TEXT , "This is an example text inside indicator, cool, huh?" ); ObjectSetString (window,label2_name, OBJPROP_FONT , "Arial" ); ObjectSetInteger (window,label2_name, OBJPROP_FONTSIZE , 14 ); ObjectSetInteger (window,label2_name, OBJPROP_SELECTABLE ,false); ChartRedraw (window); } IndicatorSetString ( INDICATOR_SHORTNAME , "Hello " +label2_name+ "..." ); return (rates_total); } void OnDeinit( const int reason) { if ( ObjectFind ( 0 ,label_name)>= 0 ) ObjectDelete ( 0 ,label_name); if ( ObjectFind (window,label2_name)>= 0 ) ObjectDelete (window,label2_name); }
메인 차트 창에 하나, 표시기 창에 두 번째 개체(레이블) 2개를 넣으려고 합니다.
if (( ENUM_PROGRAM_TYPE ) MQL5InfoInteger ( MQL5_PROGRAM_TYPE )== PROGRAM_INDICATOR ) { window= ChartWindowFind (); Print (window); }
창 변수는 표시기 창에 대해 1로 설정되며 표시기를 실행할 때 표시되는 것은
그리고
Print ( "Generating a label2" ); ObjectCreate (window,label2_name, OBJ_LABEL , 0 , 0 , 0 ); Print ( GetLastError ());
GetLastError는 '4101' 값을 반환합니다.
내 지표 샘플 사용해보기
//+------------------------------------------------------------------+ //| testObjectsInIndicator.mq5 | //| Copyright 2009, MetaQuotes Software Corp. | //| http://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "2009, MetaQuotes Software Corp." #property link "http://www.mql5.com" #property version "1.00" #property indicator_chart_window #property indicator_buffers 2 #property indicator_plots 1 //---- plot Bollinger #property indicator_label1 "BB High; BB Low" #property indicator_type1 DRAW_FILLING #property indicator_color1 Magenta,LimeGreen #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- input parameters input int BBperiod= 20 ; // период BBands input int length= 30 ; // длина канала input double width= 2.0 ; // ширина BBands input color channelColor= Turquoise ; // цвет канала //--- indicator buffers double BollingerBuffer1[]; double BollingerBuffer2[]; int handleBBands; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer ( 0 ,BollingerBuffer1, INDICATOR_DATA ); SetIndexBuffer ( 1 ,BollingerBuffer2, INDICATOR_DATA ); handleBBands= iBands ( NULL , 0 ,BBperiod, 0 ,width, PRICE_CLOSE ); //--- Print ( "Function " , __FUNCTION__ , " Build " , __MQ5BUILD__ ); return ( 0 ); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate( const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { //--- static int prevbars=- 1 ; //int bars=Bars(NULL,0); int copied= CopyBuffer (handleBBands, 1 , 0 ,rates_total,BollingerBuffer1); if (copied<= 0 ) { Print ( "Copying of indicator values failed" ); return ( 0 ); } copied= CopyBuffer (handleBBands, 2 , 0 ,rates_total,BollingerBuffer2); if (copied<= 0 ) { Print ( "Copying of indicator values failed" ); return ( 0 ); } if (prevbars!=rates_total) { prevbars=rates_total; ArraySetAsSeries (time,true); SetupChannel(time[length],time[ 1 ]); } //--- return value of prev_calculated for next call return (rates_total); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void SetupChannel( datetime time1, datetime time2) { static string channelName= "Channel" ; static string startLine= "start" ; static string finishLine= "finish" ; if ( ObjectFind ( 0 ,channelName)< 0 ) { Print ( "Channel not found, let's create it" ); if (! ObjectCreate ( 0 ,channelName, OBJ_STDDEVCHANNEL , 0 , 0 , 0 )) Print ( "Channel creation failed error =" , GetLastError ()); else { ObjectSetInteger ( 0 ,channelName, OBJPROP_COLOR ,channelColor); Print ( "Set channel beginning at" ,time1); ObjectSetInteger ( 0 ,channelName, OBJPROP_TIME , 0 ,time1); Print ( "Set channel finish at" ,time2); bool modified= ObjectSetInteger ( 0 ,channelName, OBJPROP_TIME , 1 ,time2); if (!modified) { Print ( "Can not to set up time coordinates. Error" , GetLastError ()); } Print ( "Move channel on background" ); ObjectSetInteger ( 0 ,channelName, OBJPROP_BACK ,true); } } if ( ObjectFind ( 0 ,startLine)< 0 ) { Print ( "Линия start не найдена, создадим сами" ); if (! ObjectCreate ( 0 ,startLine, OBJ_VLINE , 0 ,time1, 0 )) Print ( "Не удалось создать линию startLine, error =" , GetLastError ()); } if ( ObjectFind ( 0 ,finishLine)< 0 ) { Print ( "Линия finish не найдена, создадим сами" ); if (! ObjectCreate ( 0 ,finishLine, OBJ_VLINE , 0 ,time2, 0 )) Print ( "Не удалось создать линию finishLine, error =" , GetLastError ()); } } //+------------------------------------------------------------------+
내 지표 샘플 사용해보기
표시기는 올바르게 작동하지만 별도의 창이 아닌 기본 차트에 개체를 표시합니다(별도의 표시기 창에 개체를 그려야 함). 내가 사용할 때
#property indicator_separate_window
대신에
#property indicator_chart_window
(귀하의 예에서와 같이)
그리고 내가 설정
ObjectCreate ( 1 ,startLine, OBJ_VLINE , 0 ,time1, 0 )
나는 다음과 같은 오류 출력을 얻는다
2010.01.14 16:11:40 testObjectOnIndicator (EURUSD,M5) Не удалось создать линию finishLine, error = 4101 2010.01.14 16:11:40 testObjectOnIndicator (EURUSD,M5) Линия finish не найдена, создадим сами 2010.01.14 16:11:40 testObjectOnIndicator (EURUSD,M5) Не удалось создать линию startLine, error = 4101 2010.01.14 16:11:40 testObjectOnIndicator (EURUSD,M5) Линия start не найдена, создадим сами 2010.01.14 16:11:40 testObjectOnIndicator (EURUSD,M5) Channel creation failed error = 4101 2010.01.14 16:11:40 testObjectOnIndicator (EURUSD,M5) Channel not found, let's create it 2010.01.14 16:11:40 testObjectOnIndicator (EURUSD,M5) Function OnInit Build 223
Object Create 메서드의 첫 번째 매개변수 ("1")는 ChartWindowFind()에서 반환된 값입니다.
if (( ENUM_PROGRAM_TYPE ) MQL5InfoInteger ( MQL5_PROGRAM_TYPE )== PROGRAM_INDICATOR ) { window= ChartWindowFind (); }
):
여기에 제안된 대로 : https://www.mql5.com/en/docs/chart_operations/chartwindowfind
- www.mql5.com
//| testObjectsInIndicator.mq5 |
//| Copyright 2009, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2009, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property version "1.00"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots 1
//---- plot Bollinger
#property indicator_label1 "BB High; BB Low"
#property indicator_type1 DRAW_FILLING
#property indicator_color1 Magenta,LimeGreen
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//--- input parameters
input int BBperiod=20; // период BBands
input int length=30; // длина канала
input double width=2.0; // ширина BBands
input color channelColor=Turquoise; // цвет канала
//--- indicator buffers
double BollingerBuffer1[];
double BollingerBuffer2[];
int handleBBands;
//---
int window=1;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- get window number
window =ChartWindowFind();
//--- indicator buffers mapping
SetIndexBuffer(0,BollingerBuffer1,INDICATOR_DATA);
SetIndexBuffer(1,BollingerBuffer2,INDICATOR_DATA);
handleBBands=iBands(NULL,0,BBperiod,0,width,PRICE_CLOSE);
//---
Print("Function ",__FUNCTION__," Build ",__MQ5BUILD__);
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
//---
static int prevbars=-1;
//int bars=Bars(NULL,0);
int copied=CopyBuffer(handleBBands,1,0,rates_total,BollingerBuffer1);
if(copied<=0)
{
Print("Copying of indicator values failed");
return(0);
}
copied=CopyBuffer(handleBBands,2,0,rates_total,BollingerBuffer2);
if(copied<=0)
{
Print("Copying of indicator values failed");
return(0);
}
if(prevbars!=rates_total)
{
prevbars=rates_total;
ArraySetAsSeries(time,true);
SetupChannel(time[length],time[1]);
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void SetupChannel(datetime time1,datetime time2)
{
static string channelName="Channel";
static string startLine="start";
static string finishLine="finish";
if(ObjectFind(0,channelName)<0)
{
Print("Channel not found, let's create it");
if(! ObjectCreate(0,channelName,OBJ_STDDEVCHANNEL, window ,0,0) )
Print("Channel creation failed error =",GetLastError());
else
{
ObjectSetInteger(0,channelName,OBJPROP_COLOR,channelColor);
Print("Set channel beginning at",time1);
ObjectSetInteger(0,channelName,OBJPROP_TIME,0,time1);
Print("Set channel finish at",time2);
bool modified=ObjectSetInteger(0,channelName,OBJPROP_TIME,1,time2);
if(!modified)
{
Print("Can not to set up time coordinates. Error",GetLastError());
}
Print("Move channel on background");
ObjectSetInteger(0,channelName,OBJPROP_BACK,true);
}
}
if(ObjectFind(0,startLine)<0)
{
Print("Линия start не найдена, создадим сами");
if(!ObjectCreate(0,startLine,OBJ_VLINE,window,time1,0))
Print("Не удалось создать линию startLine, error =",GetLastError());
}
if(ObjectFind(0,finishLine)<0)
{
Print("Линия finish не найдена, создадим сами");
if(!ObjectCreate(0,finishLine,OBJ_VLINE,window,time2,0))
Print("Не удалось создать линию finishLine, error =",GetLastError());
}
}
//+------------------------------------------------------------------+
표시기(별도 창) 안에 텍스트를 삽입하는 방법의 예를 볼 수 있습니까?
감사해요