Button in EA

 

Hey Leute,

ich probiere vergeblich seit Stunden einen Button, zum direkten EIN/Aus schalten meines EA´s vom Chart aus einzufügen.

Ich schaff es aber einfach nicht :(((((.

Kann von Euch vielleicht mal einer kurz drüber schauen oder paar Tipps geben. Wäre echt Super nett von Euch.


Hier der Code für den Button:

string button1ID="Button1";
bool EAWorking = false;
//???? #import "HD-Turbo.mq4"; 
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit() {

   CreateButton(button1ID, "Start",200, 16);
   
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason) {
   ObjectDelete(0,button1ID);
}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick() {
   if (!EAWorking) return;
   //hier soll er arbeiten
}
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam) {
//--- Check the event by pressing a mouse button
   if(id==CHARTEVENT_OBJECT_CLICK) {
      string clickedChartObject=sparam;
      if(clickedChartObject==button1ID) {
         bool selected=ObjectGetInteger(0,button1ID,OBJPROP_STATE);
         if(selected) { 
            if (ObjectGetString(0,button1ID,OBJPROP_TEXT) == "Start") {
               EAWorking = true; //??? Start von EA= Experts/HD-Turbo.mq4
               ObjectSetString(0,button1ID,OBJPROP_TEXT,"Stop");
               ObjectSetInteger(0,button1ID,OBJPROP_STATE,0);
            } else {
               EAWorking = false; //??? Stop von EA= Experts/HD-Turbo.mq4
               ObjectSetString(0,button1ID,OBJPROP_TEXT,"Start");
               ObjectSetInteger(0,button1ID,OBJPROP_STATE,0);
            }
         }
      }
      ChartRedraw();
   }
}
void CreateButton(string name, string text, int x, int y) {
   ObjectCreate(0,name,OBJ_BUTTON,0,100,100);
   ObjectSetInteger(0,name,OBJPROP_COLOR,clrWhite);
   ObjectSetInteger(0,button1ID,OBJPROP_BGCOLOR,clrGreen);
   ObjectSetInteger(0,button2ID,OBJPROP_BGCOLOR,clrRed);
   ObjectSetInteger(0,name,OBJPROP_XDISTANCE,x);
   ObjectSetInteger(0,name,OBJPROP_YDISTANCE,y);
   ObjectSetInteger(0,name,OBJPROP_XSIZE,50);//200);
   ObjectSetInteger(0,name,OBJPROP_YSIZE,25);//50);
   ObjectSetString(0,name,OBJPROP_FONT,"Arial");
   ObjectSetString(0,name,OBJPROP_TEXT,text);
   ObjectSetInteger(0,name,OBJPROP_FONTSIZE,10);
   ObjectSetInteger(0,name,OBJPROP_SELECTABLE,0);
}

und hier mein EA wo es rein soll

//+------------------------------------------------------------------+

//| This MQL is generated by Expert Advisor Builder                  |

//|                http://sufx.core.t3-ism.net/ExpertAdvisorBuilder/ |

//|                                                                  |

//|  In no event will author be liable for any damages whatsoever.   |

//|                      Use at your own risk.                       |

//|                                                                  |

//+------------------- DO NOT REMOVE THIS HEADER --------------------+



#define SIGNAL_NONE 0

#define SIGNAL_BUY   1

#define SIGNAL_SELL  2

#define SIGNAL_CLOSEBUY 3

#define SIGNAL_CLOSESELL 4



#property copyright "Expert Advisor Builder"

#property link      "http://sufx.core.t3-ism.net/ExpertAdvisorBuilder/"



extern int MagicNumber = 0;

extern bool SignalMail = False;

extern bool EachTickMode = False;

extern double Lots = 1.0;

extern int Slippage = 3;

extern bool UseStopLoss = True;

extern int StopLoss = 70;

extern bool UseTakeProfit = True;

extern int TakeProfit = 50;

extern bool UseTrailingStop = False;

extern int TrailingStop = 10;

extern int PIP = 10;

extern int Alarmpip = 100;

extern int OFFSET = 10;



int BarCount;

int Current;

bool TickCheck = False;

bool TRADE = False;

bool SELL;

bool NEWSELL, NEWBUY; 

bool SendNotification;

//+------------------------------------------------------------------+

//| expert initialization function                                   |

//+------------------------------------------------------------------+

int init() {

   BarCount = Bars;



   if (EachTickMode) Current = 0; else Current = 1;



   return(0);

}

//+------------------------------------------------------------------+

//| expert deinitialization function                                 |

//+------------------------------------------------------------------+

int deinit() {

   return(0);

}

//+------------------------------------------------------------------+

//| expert start function                                            |

//+------------------------------------------------------------------+

int start() {

   int Order = SIGNAL_NONE;

   int Total, Ticket;

   double StopLossLevel, TakeProfitLevel;







   if (EachTickMode && Bars != BarCount) TickCheck = False;

   Total = OrdersTotal();

   Order = SIGNAL_NONE;



   //+------------------------------------------------------------------+

   //| Variable Begin                                                   |

   //+------------------------------------------------------------------+





   

   //+------------------------------------------------------------------+

   //| Variable End                                                     |

   //+------------------------------------------------------------------+



   //Check position

   bool IsTrade = False;



   for (int i = 0; i < Total; i ++) {

      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);

      if(OrderType() <= OP_SELL &&  OrderSymbol() == Symbol()) {

         IsTrade = True;

         if(OrderType() == OP_BUY) 

            //Close



{                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          

         }

      }

   }



   //+------------------------------------------------------------------+

   //| Signal Begin(Entry)                                              |

   //+------------------------------------------------------------------+

   

   // if (( Open[1] - Close[1] < Point * PIP) && ( Open[1] - Close[1]  > 0) && Open[2] < Close[2] ) Order = SIGNAL_BUY;

    if (( Open[2] < Close[2] ) && ( Open[1] > Close[1] )   ) Order = SIGNAL_BUY;

    if (( Open[2] > Close[2] ) && ( Open[1] > Close[1] )   ) NEWBUY = False;

    else NEWBUY = true;

    



  // if (( Close[1] - Open[1]  < Point * PIP) && (Close[1] - Open[1] > 0) && Open[2] > Close[2] ) Order = SIGNAL_SELL;

     if (( Open[2] > Close[2] ) && ( Open[1] < Close[1] )  )  Order = SIGNAL_SELL;

     if (( Open[2] < Close[2] ) && ( Open[1] < Close[1] )  )  NEWSELL = False;

     else NEWSELL = true;

     

   

  // if (Sell1_1 < Sell1_2) Order = SIGNAL_SELL;

     







   //+------------------------------------------------------------------+

   //| Signal End                                                       |

   //+------------------------------------------------------------------+









if (IsTrade && SIGNAL_SELL ) {           // Open[2] > Close[2] ) && ( Open[1] < Close[1]  || !IsTrade

{

OrderSelect( SELECT_BY_POS, MODE_TRADES);

if(OrderSymbol()==Symbol()) // check for symbol

{

if ((OrderType()==OP_BUYLIMIT || OrderType()==OP_BUYSTOP) && OP_SELLSTOP) //check for buy stops/limits





{

OrderDelete(OrderTicket());

}}}}





if (IsTrade && SIGNAL_BUY ) {              //( Open[2] < Close[2] ) && ( Open[1] > Close[1] )

{

OrderSelect( SELECT_BY_POS, MODE_TRADES);

if(OrderSymbol()==Symbol()) // check for symbol

{

if ((OrderType()==OP_SELLLIMIT || OrderType()==OP_SELLSTOP)&& OP_BUYSTOP) //check for sell stops/limits



{

//if (OrderOpenPrice() <= Bid-StopLoss*Point) 

{

OrderDelete(OrderTicket());

}

}}}}

   //Buy

   if (Order == SIGNAL_BUY && NEWBUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {

      if(!IsTrade) {

         //Check free margin

         if (AccountFreeMargin() < (1000 * Lots)) {

            Print("We have no money. Free Margin = ", AccountFreeMargin());

            return(0);

         }



         if (UseStopLoss) StopLossLevel = Ask - StopLoss * Point + OFFSET * Point; else StopLossLevel = 0.0;

         if (UseTakeProfit) TakeProfitLevel = Ask + TakeProfit * Point + OFFSET * Point; else TakeProfitLevel = 0.0;



         Ticket = OrderSend(Symbol(), OP_BUYSTOP, Lots, Ask + (Open[1] - Close[1]) + OFFSET * Point , Slippage, StopLossLevel + (Open[1] - Close[1]),   TakeProfitLevel + (Open[1] - Close[1]) , "Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue);

         if(Ticket > 0) {

            if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {

Print("BUY order opened : ", OrderOpenPrice());

                if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Open Buy");

} else {

Print("Error opening BUY order : ", GetLastError());

}

         }

         if (EachTickMode) TickCheck = True;

         if (!EachTickMode) BarCount = Bars;

         return(0);

      }

   }



   //Sell

   if (Order == SIGNAL_SELL && NEWSELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {

      if(!IsTrade) {

         //Check free margin

         if (AccountFreeMargin() < (1000 * Lots)) {

            Print("We have no money. Free Margin = ", AccountFreeMargin());

            return(0);

         }



         if (UseStopLoss) StopLossLevel = Bid +  StopLoss * Point - OFFSET * Point; else StopLossLevel = 0.0;

         if (UseTakeProfit) TakeProfitLevel = Bid - TakeProfit * Point -  OFFSET * Point; else TakeProfitLevel = 0.0;



         Ticket = OrderSend(Symbol(), OP_SELLSTOP, Lots, Bid - (Close[1] - Open[1]) - OFFSET * Point, Slippage, StopLossLevel - (Close[1] - Open[1]),   TakeProfitLevel - (Close[1] - Open[1]), "Sell(#" + MagicNumber + ")", MagicNumber, 0, DeepPink);

         if(Ticket > 0) {

            if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {

Print("SELL order opened : ", OrderOpenPrice());

                if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Open Sell");

} else {

Print("Error opening SELL order : ", GetLastError());

}

         }

         if (EachTickMode) TickCheck = True;

         if (!EachTickMode) BarCount = Bars;

         return(0);

      }

   }



   if (!EachTickMode) BarCount = Bars;



   return(0);

}

//+------------------------------------------------------------------+
 

Bitte füge den Code mittels des SRC Buttons (direkt hier im Editor Fenster) ein.
Ansonsten wird Dir alleine wegen der miesen Lesbarkeit niemand helfen können/wollen.

 

Schau mal hier! Denke immer, es gibt fast nicht, was es nicht schon gibt für MT4/5.

Also warum das Rad neu erfinden, wenn es ein Nachbar bereits verschenkt?

 

Okay hab ich geändert siehe oben :).


Hmmm Carl danke dafür aber ich probier bzw. suche jetzt schon so lange das ich nur noch verzweifel. :(

 

Warum willst Du den denn im OnInit() einbauen und nicht -wie bereits angefangen- in OnEvent() - das Ziel ist, dass Du im laufenden Betrieb an- und ausschalten kannst, richtig?

 

genau. den EA unten hab ich mir nur über so eine Seite zam gebastelt und ein paar änderungen (Nach meinem unprofessionelen Verständniss fürs programmieren) .


An der Vorlage habe ich noch nichts geändert. hier müsste halt mein EA irgendwie rein. oder Halt anders rum.


Aber wie Du schon sagtest ist das ziel ihn im laufendem Betrieb EIN bzw. Auszuschalten ohne über F7 zu gehen.

 
IDCBOI:

genau. den EA unten hab ich mir nur über so eine Seite zam gebastelt und ein paar änderungen (Nach meinem unprofessionelen Verständniss fürs programmieren) .


An der Vorlage habe ich noch nichts geändert. hier müsste halt mein EA irgendwie rein. oder Halt anders rum.


Aber wie Du schon sagtest ist das ziel ihn im laufendem Betrieb EIN bzw. Auszuschalten ohne über F7 zu gehen.


Bau es doch direkt in den EA ein:

Sobald das funktioniert mit der booleschen Abfrage, solltest Du noch am Farbwechsel des Buttons oder einem ausgegebenen String arbeiten, damit Du weißt, ob der EA gerade "scharf" ist oder nicht. 
Wenn Du das so realisierst, bleibt natürlich der EA selbst auf Autotrading, also Smiley :-) in der Ecke. 

bool Create_DeActivateButton(const long       chart_ID=0,                     // chart's ID
                      const string            name="Button_DeActivate",       // button name
                      const int               x=0,                            // X coordinate
                      const int               y=20,                           // Y coordinate
                      const int               width=60,                       // button width
                      const int               height=20,                      // button height
                      const ENUM_BASE_CORNER  corner=CORNER_LEFT_UPPER,       // chart corner for anchoring
                      const string            text="DeActivate",              // text
                      const string            font="Courier New",             // font
                      const int               font_size=10,                   // font size
                      const color             clr=clrBlack,                   // text color
                      const color             back_clr=clrGray,               // background color
                      const bool              back=false                      // in the background
                      )
  {
//--- reset the error value (optional for deactivation)
   ResetLastError();
//--- create the button
   ObjectCreate(chart_ID,name,OBJ_BUTTON,0,0,0);
   ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x);
   ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y);
   ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width);
   ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height);
   ObjectSetString(chart_ID,name,OBJPROP_TEXT,text);
   ObjectSetString(chart_ID,name,OBJPROP_FONT,font);
   ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size);
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
   ObjectSetInteger(chart_ID,name,OBJPROP_BGCOLOR,back_clr);
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
//--- successful execution
   return(true);
  }
  
  
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//---
   if(id==CHARTEVENT_OBJECT_CLICK)
     {
      if(sparam=="Button_DeActivate")
        {
         //DeActivate() or EAWorking = false;
         //ObjectSetInteger(0,"Button_DeActivate",OBJPROP_STATE,false);
        }
      
     }
  }
 

naja und das versuche ich ja die ganze zeit. aber ich weiß halt nicht wo ich was rein machen soll :(. hab schon so viel probiert aber ich komm einfach nicht weiter.

 

Also mein letzter stand ist der hier.


Der button ist zwar da aber der EA läuft halt immer als wäre der Button Inaktiv.

//+------------------------------------------------------------------+
//| This MQL is generated by Expert Advisor Builder                  |
//|                http://sufx.core.t3-ism.net/ExpertAdvisorBuilder/ |
//|                                                                  |
//|  In no event will author be liable for any damages whatsoever.   |
//|                      Use at your own risk.                       |
//|                                                                  |
//+------------------- DO NOT REMOVE THIS HEADER --------------------+

#define SIGNAL_NONE 0
#define SIGNAL_BUY   1
#define SIGNAL_SELL  2
#define SIGNAL_CLOSEBUY 3
#define SIGNAL_CLOSESELL 4

#property copyright "Expert Advisor Builder"
#property link      "http://sufx.core.t3-ism.net/ExpertAdvisorBuilder/"

extern int MagicNumber = 0;
extern bool SignalMail = False;
extern bool EachTickMode = False;
extern double Lots = 1.0;
extern int Slippage = 3;
extern bool UseStopLoss = True;
extern int StopLoss = 70;
extern bool UseTakeProfit = True;
extern int TakeProfit = 50;
extern bool UseTrailingStop = False;
extern int TrailingStop = 10;
extern int PIP = 10;
extern int Alarmpip = 100;
extern int OFFSET = 10;

int BarCount;
int Current;
bool TickCheck = False;
bool TRADE = False;
bool SELL;
bool NEWSELL, NEWBUY; 
bool SendNotification;
bool EAWorking = False;

string button1ID="Button1";

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+




int OnInit() {
   BarCount = Bars;
   CreateButton(button1ID, "Start",200, 16);

   if (EachTickMode) Current = 0; else Current = 1;

   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit() {
ObjectDelete(0,button1ID);

   return(0);
}




//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam) {
//--- Check the event by pressing a mouse button
   if(id==CHARTEVENT_OBJECT_CLICK) {
      string clickedChartObject=sparam;
      if(clickedChartObject==button1ID) {
         bool selected=ObjectGetInteger(0,button1ID,OBJPROP_STATE);
         if(selected) { 
            if (ObjectGetString(0,button1ID,OBJPROP_TEXT) == "Start") {
               EAWorking = true; //??? Start von EA= Experts/HD-Turbo.mq4
               ObjectSetString(0,button1ID,OBJPROP_TEXT,"Stop");
               ObjectSetInteger(0,button1ID,OBJPROP_STATE,0);
            } else {
               EAWorking = false; //??? Stop von EA= Experts/HD-Turbo.mq4
               ObjectSetString(0,button1ID,OBJPROP_TEXT,"Start");
               ObjectSetInteger(0,button1ID,OBJPROP_STATE,0);
            }
         }
      }
      ChartRedraw();
   }
}
void CreateButton(string name, string text, int x, int y) {
   ObjectCreate(0,name,OBJ_BUTTON,0,100,100);
   ObjectSetInteger(0,name,OBJPROP_COLOR,clrWhite);
   ObjectSetInteger(0,button1ID,OBJPROP_BGCOLOR,clrGreen);
   //ObjectSetInteger(0,button2ID,OBJPROP_BGCOLOR,clrRed);
   ObjectSetInteger(0,name,OBJPROP_XDISTANCE,x);
   ObjectSetInteger(0,name,OBJPROP_YDISTANCE,y);
   ObjectSetInteger(0,name,OBJPROP_XSIZE,50);//200);
   ObjectSetInteger(0,name,OBJPROP_YSIZE,25);//50);
   ObjectSetString(0,name,OBJPROP_FONT,"Arial");
   ObjectSetString(0,name,OBJPROP_TEXT,text);
   ObjectSetInteger(0,name,OBJPROP_FONTSIZE,10);
   ObjectSetInteger(0,name,OBJPROP_SELECTABLE,0);
}

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start() {
   int Order = SIGNAL_NONE;
   int Total, Ticket;
   double StopLossLevel, TakeProfitLevel;
    if (!EAWorking) return;



   if (EachTickMode && Bars != BarCount) TickCheck = False;
   Total = OrdersTotal();
   Order = SIGNAL_NONE;
   
   
   
 
   
   
   
  
  
  
  
  
   
   

   //+------------------------------------------------------------------+
   //| Variable Begin                                                   |
   //+------------------------------------------------------------------+


double Buy1_1 = iMA(NULL, 0, 20, 0, MODE_LWMA, PRICE_CLOSE, Current + 0);
double Buy1_2 = iSAR(NULL, 0, 0.03, 0.089, Current + 0);

double Sell1_1 = iMA(NULL, 0, 20, 0, MODE_LWMA, PRICE_CLOSE, Current + 0);
double Sell1_2 = iSAR(NULL, 0, 0.03, 0.089, Current + 0);

double CloseBuy1_1 = iBands(NULL, 0, 11, 2, 0, PRICE_TYPICAL, MODE_UPPER, Current + 0);
double CloseBuy1_2 = iClose(NULL, 0, Current + 0);

double CloseSell1_1 = iSAR(NULL, 0, 0.03, 0.089, Current + 0);
double CloseSell1_2 = iClose(NULL, 0, Current + 0);

   
   //+------------------------------------------------------------------+
   //| Variable End                                                     |
   //+------------------------------------------------------------------+

   //Check position
   bool IsTrade = False;

   for (int i = 0; i < Total; i ++) {
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      if(OrderType() <= OP_SELL &&  OrderSymbol() == Symbol()) {
         IsTrade = True;
         if(OrderType() == OP_BUY) {
            //Close

            //+------------------------------------------------------------------+
            //| Signal Begin(Exit Buy)                                           |
            //+------------------------------------------------------------------+

                  


            //+------------------------------------------------------------------+
            //| Signal End(Exit Buy)                                             |
            //+------------------------------------------------------------------+

            if (Order == SIGNAL_CLOSEBUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
               OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen);
               if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy");
               if (!EachTickMode) BarCount = Bars;
               IsTrade = False;
               continue;
            }
            //Trailing stop
            if(UseTrailingStop && TrailingStop > 0) {                 
               if(Bid - OrderOpenPrice() > Point * TrailingStop) {
                  if(OrderStopLoss() < Bid - Point * TrailingStop) {
                     OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen);
                     if (!EachTickMode) BarCount = Bars;
                     if(Ticket > 0) {
                     if((Bid - OrderOpenPrice() > Point * Alarmpip)  || (Bid + OrderOpenPrice() > Point * Alarmpip))
            if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
                                SendNotification ("PIPALARM : ");
                
                     continue;
                     }}
                  }
               }
            }
         } else {                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
            //Close

            //+------------------------------------------------------------------+
            //| Signal Begin(Exit Sell)                                          |
            //+------------------------------------------------------------------+

                   


            //+------------------------------------------------------------------+
            //| Signal End(Exit Sell)                                            |
            //+------------------------------------------------------------------+

            if (Order == SIGNAL_CLOSESELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
               OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange);
               if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Close Sell");
               if (!EachTickMode) BarCount = Bars;
               IsTrade = False;
               continue;
            }
            //Trailing stop
            if(UseTrailingStop && TrailingStop > 0) {                 
               if((OrderOpenPrice() - Ask) > (Point * TrailingStop)) {
                  if((OrderStopLoss() > (Ask + Point * TrailingStop)) || (OrderStopLoss() == 0)) {
                     OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point * TrailingStop, OrderTakeProfit(), 0, DarkOrange);
                     if (!EachTickMode) BarCount = Bars;
                     continue;
                  }
               }
            }
         }
      }
   }

   //+------------------------------------------------------------------+
   //| Signal Begin(Entry)                                              |
   //+------------------------------------------------------------------+
   
   // if (( Open[1] - Close[1] < Point * PIP) && ( Open[1] - Close[1]  > 0) && Open[2] < Close[2] ) Order = SIGNAL_BUY;
    if (( Open[2] < Close[2] ) && ( Open[1] > Close[1] )   ) Order = SIGNAL_BUY;
    if (( Open[2] > Close[2] ) && ( Open[1] > Close[1] )   ) NEWBUY = False;
    else NEWBUY = true;
    

  // if (( Close[1] - Open[1]  < Point * PIP) && (Close[1] - Open[1] > 0) && Open[2] > Close[2] ) Order = SIGNAL_SELL;
     if (( Open[2] > Close[2] ) && ( Open[1] < Close[1] )  )  Order = SIGNAL_SELL;
     if (( Open[2] < Close[2] ) && ( Open[1] < Close[1] )  )  NEWSELL = False;
     else NEWSELL = true;
     
   
  // if (Sell1_1 < Sell1_2) Order = SIGNAL_SELL;
     



   //+------------------------------------------------------------------+
   //| Signal End                                                       |
   //+------------------------------------------------------------------+




if (IsTrade && SIGNAL_SELL ) {           // Open[2] > Close[2] ) && ( Open[1] < Close[1]  || !IsTrade
{
OrderSelect( SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol()==Symbol()) // check for symbol
{
if ((OrderType()==OP_BUYLIMIT || OrderType()==OP_BUYSTOP) && OP_SELLSTOP) //check for buy stops/limits


{
OrderDelete(OrderTicket());
}}}}


if (IsTrade && SIGNAL_BUY ) {              //( Open[2] < Close[2] ) && ( Open[1] > Close[1] )
{
OrderSelect( SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol()==Symbol()) // check for symbol
{
if ((OrderType()==OP_SELLLIMIT || OrderType()==OP_SELLSTOP)&& OP_BUYSTOP) //check for sell stops/limits

{
//if (OrderOpenPrice() <= Bid-StopLoss*Point) 
{
OrderDelete(OrderTicket());
}
}}}}
   //Buy
   if (Order == SIGNAL_BUY && NEWBUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
      if(!IsTrade) {
         //Check free margin
         if (AccountFreeMargin() < (1000 * Lots)) {
            Print("We have no money. Free Margin = ", AccountFreeMargin());
            return(0);
         }

         if (UseStopLoss) StopLossLevel = Ask - StopLoss * Point + OFFSET * Point; else StopLossLevel = 0.0;
         if (UseTakeProfit) TakeProfitLevel = Ask + TakeProfit * Point + OFFSET * Point; else TakeProfitLevel = 0.0;

         Ticket = OrderSend(Symbol(), OP_BUYSTOP, Lots, Ask + (Open[1] - Close[1]) + OFFSET * Point , Slippage, StopLossLevel + (Open[1] - Close[1]),   TakeProfitLevel + (Open[1] - Close[1]) , "Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue);
         if(Ticket > 0) {
            if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
                                Print("BUY order opened : ", OrderOpenPrice());
                if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Open Buy");
                        } else {
                                Print("Error opening BUY order : ", GetLastError());
                        }
         }
         if (EachTickMode) TickCheck = True;
         if (!EachTickMode) BarCount = Bars;
         return(0);
      }
   }

   //Sell
   if (Order == SIGNAL_SELL && NEWSELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
      if(!IsTrade) {
         //Check free margin
         if (AccountFreeMargin() < (1000 * Lots)) {
            Print("We have no money. Free Margin = ", AccountFreeMargin());
            return(0);
         }

         if (UseStopLoss) StopLossLevel = Bid +  StopLoss * Point - OFFSET * Point; else StopLossLevel = 0.0;
         if (UseTakeProfit) TakeProfitLevel = Bid - TakeProfit * Point -  OFFSET * Point; else TakeProfitLevel = 0.0;

         Ticket = OrderSend(Symbol(), OP_SELLSTOP, Lots, Bid - (Close[1] - Open[1]) - OFFSET * Point, Slippage, StopLossLevel - (Close[1] - Open[1]),   TakeProfitLevel - (Close[1] - Open[1]), "Sell(#" + MagicNumber + ")", MagicNumber, 0, DeepPink);
         if(Ticket > 0) {
            if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
                                Print("SELL order opened : ", OrderOpenPrice());
                if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Open Sell");
                        } else {
                                Print("Error opening SELL order : ", GetLastError());
                        }
         }
         if (EachTickMode) TickCheck = True;
         if (!EachTickMode) BarCount = Bars;
         return(0);
      }
   }

   if (!EachTickMode) BarCount = Bars;

   return(0);
}
//+------------------------------------------------------------------+
 

Also ich les mir jetzt nicht den ganzen Code durch,
aber wozu denn das SELECTED in der OnChartEvent() ???

Machs doch einfach so:

   if(id==CHARTEVENT_OBJECT_CLICK) {
      if(sparam==button1ID) {
         EAWorking=!EAWorking;
         if (EAWorking) ObjectSetString(0,button1ID,OBJPROP_TEXT,"Stop"); else ObjectSetString(0,button1ID,OBJPROP_TEXT,"Start");
         ObjectSetInteger(0,button1ID,OBJPROP_STATE,0); 
      }
   }