Button On Chart Want To Make It Available For Auto Trades Not Just Manual Trades - page 2

 
input bool RunOnCurrentCurrencyPair = true; //Here You Don't Much Need It

input bool CloseOnlyManualTrades = true; //Here You Don't Much Need It

input bool DeletePendingOrders = true; //Here You Don't Much Need It

input int  MaxSlippage = 5; //This Is Important 







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

//| Expert initialization function //No Problem Code Here            |

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

int OnInit()

  {

//--- 

   

   ObjectCreate(0,"CloseAll_btn",OBJ_BUTTON,0,0,0);

   ObjectSetInteger(0,"CloseAll_btn",OBJPROP_XDISTANCE,450);

   ObjectSetInteger(0,"CloseAll_btn",OBJPROP_YDISTANCE,5);

   ObjectSetInteger(0,"CloseAll_btn",OBJPROP_XSIZE,100);

   ObjectSetInteger(0,"CloseAll_btn",OBJPROP_YSIZE,50);


   ObjectSetString(0,"CloseAll_btn",OBJPROP_TEXT,"Close All");      
   

   ObjectSetInteger(0,"CloseAll_btn",OBJPROP_COLOR, White);

   ObjectSetInteger(0,"CloseAll_btn",OBJPROP_BGCOLOR, Red);

   ObjectSetInteger(0,"CloseAll_btn",OBJPROP_BORDER_COLOR,Red);

   ObjectSetInteger(0,"CloseAll_btn",OBJPROP_BORDER_TYPE,BORDER_FLAT);

   ObjectSetInteger(0,"CloseAll_btn",OBJPROP_BACK,false);

   ObjectSetInteger(0,"CloseAll_btn",OBJPROP_HIDDEN,true);

   ObjectSetInteger(0,"CloseAll_btn",OBJPROP_STATE,false);

   ObjectSetInteger(0,"CloseAll_btn",OBJPROP_FONTSIZE,12);



//---

   return;

  }

  

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

//| Expert deinitialization function //You Must Put It               |

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

void OnDeinit(const int reason)

  {

//---



   ObjectDelete(0,"CloseAll_btn"); //This is important

   

  }

  

  

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

//| Expert tick function //Nothing Here                              |   
 
//+------------------------------------------------------------------+

void OnTick()

  {

//---

      

  }

  

  

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

//| ChartEvent function //This a lot problem come it                 |

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

void OnChartEvent(const int id, //Nothing problem here

                  const long &lparam, //Nothing problem here

                  const double &dparam, //Nothing problem here

                  const string &sparam) //Nothing problem here

  {

//---

            

   if(sparam== "CloseAll_btn") //This you must check it to make it available for click not just have button on chart and cannot use it

      {

      if(RunOnCurrentCurrencyPair == true && CloseOnlyManualTrades == true) CloseAll(DeletePendingOrders,MaxSlippage); //This the problem so much, you must add the code to connect with the void for code check it

        

      ObjectSetInteger(0,"CloseAll_btn",OBJPROP_STATE,false); //This Not Important delete or just put it because at OnInit Already Have It   

      }

         

//---      

  }

//This Is The Junk Code You Need To Check All Of It To Make It Available To Close It At Any EA or Indicator or Anything you trade of it





void CloseAll (bool boolPendingOrders, int intMaxSlippage) //Here Check

  {   

   int ticket; // This OK

   if (OrdersTotal() == 0) return; // This OK

   for (int i = OrdersTotal() - 1; i >= 0; i--) //This OK

      {

       if (OrderSelect (i, SELECT_BY_POS, MODE_TRADES) == true) //Also OK

         {

          if (OrderType() == OP_BUY) //OK

            {

             ticket = OrderClose (OrderTicket(), OrderLots(), MarketInfo (OrderSymbol(), MODE_BID), 3, CLR_NONE);//Check This Where You Must Put It

             if (ticket == -1) Print ("Error: ", GetLastError());//OK

             if (ticket >   0) Print ("Position ", OrderTicket() ," closed");//OK

            }

          if (OrderType() == OP_SELL)//OK

            {

             ticket = OrderClose (OrderTicket(), OrderLots(), MarketInfo (OrderSymbol(), MODE_ASK), 3, CLR_NONE);//Check This Where You Must Put IT

             if (ticket == -1) Print ("Error: ",  GetLastError());

             if (ticket >   0) Print ("Position ", OrderTicket() ," closed");            

            }   

          if (OrderType() == OP_BUYLIMIT)//Check This What Type Of Order You Use It

            {

             ticket = OrderDelete (OrderTicket(), CLR_NONE); //Same Check This

             if (ticket == -1) Print ("Error: ", GetLastError());//OK

             if (ticket >   0) Print ("Position ", OrderTicket() ," closed");//OK

            }

          if (OrderType() == OP_SELLLIMIT)//Check This What Type Of Order You Use It

            {

             ticket = OrderDelete (OrderTicket(), CLR_NONE); //Same Check This

             if (ticket == -1) Print ("Error: ", GetLastError());//OK

             if (ticket >   0) Print ("Position ", OrderTicket() ," closed");//OK

            }           

         }

      }

   return; //If You Want put it on your ea or indicators this you must check it carefully

  }

To who read in this forum I already found the answer but I can't give the full code because I want build my Ultimate EA but you can check the code I will give it //and you check it and learn so am I.

Reason: