Metatrader Forum | Forex Expert-Advisor | Broker & Forex Tools

Metatrader Forum | Forex Expert-Advisor | Broker & Forex Tools (http://www.expert-advisor.com/forum/index.php)
-   Programmierung MQL4 (http://www.expert-advisor.com/forum/forumdisplay.php?f=220)
-   -   Button als Schalter? (http://www.expert-advisor.com/forum/showthread.php?t=5262)

BBGPS 07.11.16 20:40

Button als Schalter?
 
Hallo liebe Leute,
hoffentlich kann mir Jemand helfen.
KANN man einen, im EA programmierten, Button auch als Schalter nutzen?
Brächte so einen Schalter zum An und Abschalten eines Traillingstops.

Ich denke mein Hauptproblem ist, dass "void OnChartEvent" keinen return-Wert zulässt was ja nichts ungewöhnliches ist.

bei mir siehts bis jetzt so aus:
PHP-Code:

bool ANAUS;
 
int init(){
   
ObjectCreate(0,"Trail",OBJ_BUTTON,0,0,0);  
   
ObjectSetInteger(0,"Trail",OBJPROP_XDISTANCE,10); 
   
ObjectSetInteger(0,"Trail",OBJPROP_YDISTANCE,70); 
   
ObjectSetInteger(0,"Trail",OBJPROP_XSIZE,100); 
   
ObjectSetInteger(0,"Trail",OBJPROP_YSIZE,50); 
   
ObjectSetString (0,"Trail",OBJPROP_TEXT,"TRAILING"); 
   
ObjectSetString (0,"Trail",OBJPROP_FONT,"Arial"); 
   
ObjectSetInteger(0,"Trail",OBJPROP_FONTSIZE,10);  
   
ObjectSetInteger(0,"Trail",OBJPROP_ALIGN,0);  
   
ObjectSetInteger(0,"Trail",OBJPROP_CORNER,CORNER_LEFT_UPPER); 
   
ObjectSetInteger(0,"Trail",OBJPROP_COLOR,clrRed); 
   
ObjectSetInteger(0,"Trail",OBJPROP_BGCOLOR,clrGray); 
   
ObjectSetInteger(0,"Trail",OBJPROP_BORDER_COLOR,clrBlue); 
return(
0);
}

int start(){
if(
ANAUS=true)
   {
   
Trailing();
   }
return(
0);
}
  
void OnChartEvent(const int    id,
                  const 
long   &lparam,
                  const 
double &dparam,
                  const 
string &sparam)
{
  if(
id==CHARTEVENT_OBJECT_CLICK && sparam=="Trail")
      {
      
bool selected=ObjectGetInteger(0,"Trail",OBJPROP_STATE);
      if(!
selectedANAUS=false;
      if(
selected)ANAUS=true;
      }



BBGPS 07.11.16 22:42

Habs selber rausgefunden... wers brauchen kann oder Verbesserungsvorschläge hat, immer her damit.

PHP-Code:

bool TRAIL=true;
//______________________________________________________________________________________________________________________________
int init(){
   
ObjectCreate(0,"Trail",OBJ_BUTTON,0,0,0);  
   
ObjectSetInteger(0,"Trail",OBJPROP_XDISTANCE,10); 
   
ObjectSetInteger(0,"Trail",OBJPROP_YDISTANCE,70); 
   
ObjectSetInteger(0,"Trail",OBJPROP_XSIZE,100); 
   
ObjectSetInteger(0,"Trail",OBJPROP_YSIZE,50); 
   
ObjectSetString (0,"Trail",OBJPROP_TEXT,"Trailing ON"); 
   
ObjectSetString (0,"Trail",OBJPROP_FONT,"Arial"); 
   
ObjectSetInteger(0,"Trail",OBJPROP_FONTSIZE,10);  
   
ObjectSetInteger(0,"Trail",OBJPROP_ALIGN,0);  
   
ObjectSetInteger(0,"Trail",OBJPROP_CORNER,CORNER_LEFT_UPPER); 
   
ObjectSetInteger(0,"Trail",OBJPROP_COLOR,clrRed); 
   
ObjectSetInteger(0,"Trail",OBJPROP_BGCOLOR,clrBlue); 
   
ObjectSetInteger(0,"Trail",OBJPROP_BORDER_COLOR,clrBlue); 
return(
0);
}
//______________________________________________________________________________________________________________________________
int start(){
if(
TRAIL==true) Print("True");
if(
TRAIL==false)Print("False");
return(
0);
}
//______________________________________________________________________________________________________________________________
void OnDeinit(const int reason){
   
ObjectDelete("Trail"); }
//______________________________________________________________________________________________________________________________
void OnChartEvent(const int    id,
                  const 
long   &lparam,
                  const 
double &dparam,
                  const 
string &sparam)
{
   if(
id==CHARTEVENT_OBJECT_CLICK && sparam=="Trail")
      {
      
bool select=ObjectGetInteger(0,"Trail",OBJPROP_STATE);
      if( 
select)
      {
      
TRAIL=true;
      
ObjectSetInteger(0,"Trail",OBJPROP_BGCOLOR,clrBlue);
      
ObjectSetString (0,"Trail",OBJPROP_TEXT,"Trailing ON"); 
      }
      if(!
select)
      {
      
TRAIL=false;
      
ObjectSetInteger(0,"Trail",OBJPROP_BGCOLOR,clrGreen);
      
ObjectSetString (0,"Trail",OBJPROP_TEXT,"Trailing OFF"); 
      }
      }




Alle Zeitangaben in WEZ +2. Es ist jetzt 03:54 Uhr.

Powered by vBulletin® Version 3.8.5 (Deutsch)
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.6.1
Powered by vBCMS® 2.7.0 ©2002 - 2024 vbdesigns.de
Copyright ©2009 - 2023 by Expert-Advisor.com - Das Metatrader Forum