script problem with if

 

i  gut  i try  to develop a script  for  do a trade  , this  script  create  some  button  for open   a trade  with one  click can open also 10  trade  short or long and  close  it  when arrive  at  profit 0.01 ,  i have created  also another  button for disable  taget profit , the name of  button is "Auto profit"

but  when i try to active , not  work ,  where  is   the  error???

//+------------------------------------------------------------------+
//|                                                     RoboCooP.mq4 |
//|                                      Copyright © 2016, Faustf    |
//|                                   http://www1.ilmortodelmese.com |
//+------------------------------------------------------------------+
#include <mt4gui2.mqh>
#property copyright   "Copyright © 2016, Faustf"
#property link        "http://www1.ilmortodelmese.com"
#property version     "1.3"      // Current version of the Expert Advisor



#property strict 

// Global Variables
extern   int e_MagicID=33569;
extern   double limit_closing_short=0.00020;
extern   double limit_closing_long=0.00045;
extern   double dProfit_want=0.01;
extern   string  min_open_trade="1";
extern   int traling_profit=100;
extern   int Qt_open=10;
extern string   b10="=== Parametri Spostamento GUI ===";
extern int GUIX = 980;
extern int GUIY = -290;
input ushort   Seconds_Delay=21;

int m=TimeSeconds(TimeCurrent());
int aTimer_Long[];

int aTimer_Short[203];
int aTicket_Short[400];
int CtrlPush=0;
int AutoProfit=0;
double ShortStpFix=0.0;
double LongStpFix=0.0;
int Ctrl_SSFIX=0;
int Ctrl_LSFIX=0;
string ShortStop_fix;
double SStopFIX;
string LongStop_fix;
double LStopFIX;



int hwnd=0;
int W=0;

// GUI Object Handles
int Button1,Button2,Button3,Button4,Button5,Button6,Button7,Button8,Button9;
int Label1,Edit1,Edit2,Edit3;

// Settings
int ButtonWidth=150;
int ButtonHeight=20;
string sQ_Aperture;
int iQ_Aperture=0;
int TicketNumber;
bool bStatus_close=False;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
   ObjectsDeleteAll();
   hwnd=WindowHandle(Symbol(),Period());
// Lets remove all Objects from Chart before we start
   guiRemoveAll(hwnd);
// Lets build the Interface
   BuildInterface();
   return(0);
  }
//// Add new objects, Type:  "button","checkbox","list","label","text"
void BuildInterface()
  {
   Label1=guiAdd(hwnd,"label",GUIX,GUIY+50,ButtonWidth*0.6,15,"Qtt. Aperture ");
   guiSetBgColor(hwnd,Label1,LightGreen);guiSetTextColor(hwnd,Label1,Black);

   Button1 = guiAdd(hwnd,"button",GUIX,GUIY+ButtonHeight*15.5+5,90,ButtonHeight,"Short");
   Button4 = guiAdd(hwnd,"button",GUIX,GUIY+ButtonHeight*17+5,90,ButtonHeight,Qt_open+" Short");
   Button2 = guiAdd(hwnd,"button",GUIX,GUIY+ButtonHeight*18.5+5,90,ButtonHeight,"Long");
   Button5 = guiAdd(hwnd,"button",GUIX,GUIY+ButtonHeight*20+5,90,ButtonHeight,Qt_open+" Long");
   Button6 = guiAdd(hwnd,"button",GUIX,GUIY+ButtonHeight*21.5+5,90,ButtonHeight,"Clean");
   Button3 = guiAdd(hwnd,"button",GUIX,GUIY+ButtonHeight*23+5,90,ButtonHeight,"Close ALL");
   Button7 = guiAdd(hwnd,"button",GUIX,GUIY+ButtonHeight*25+5,90,ButtonHeight,"Auto Profit");
   Button8 = guiAdd(hwnd,"button",GUIX,GUIY+ButtonHeight*28+5,90,ButtonHeight,"Short StopFix");
   Button9 = guiAdd(hwnd,"button",GUIX,GUIY+ButtonHeight*31+5,90,ButtonHeight,"Long StopFix");

// Textfield Object

   Edit1=guiAdd(hwnd,"text",GUIX,GUIY+20,90,20,min_open_trade);
   guiSetBgColor(hwnd,Edit1,Gainsboro);guiSetTextColor(hwnd,Edit1,Black);
   Edit2=guiAdd(hwnd,"text",GUIX,GUIY-253,90,20,ShortStpFix);
   guiSetBgColor(hwnd,Edit2,Gainsboro);guiSetTextColor(hwnd,Edit2,Black);
   Edit3=guiAdd(hwnd,"text",GUIX,GUIY-195,90,20,LongStpFix);
   guiSetBgColor(hwnd,Edit3,Gainsboro);guiSetTextColor(hwnd,Edit3,Black);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int deinit()
  {
// Very important to cleanup and remove all gui items from chart      
   if(hwnd>0) { guiRemoveAll(hwnd);      guiCleanup(hwnd); }
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+


//+------------------------------------------------------------------+
//|            expert start function                                                     |
//+------------------------------------------------------------------+
int start()
  {
// Button GUI Item has Clicked Event to capture
// You can use "guiIsClicked" command to capture the event

// -------- Bottome Short Stop Fix -------------------------------------------------------
   int i;
   if(guiIsClicked(hwnd,Button8))
     {
      Ctrl_SSFIX=1;
      PlaySound("ok.wav");
      ShortStop_fix=guiGetText(hwnd,Edit2);
      SStopFIX=StrToDouble(ShortStop_fix);

      for(i=0; i!=iQ_Aperture;i++)
        {
         TicketNumber=OrderSend(Symbol(),OP_SELL,0.01,Bid,3,0,0,"Robocop Bottone Sell",e_MagicID);
        }
     }
// else PlaySound("error.wav");

// -------- Bottome Long Stop Fix -------------------------------------------------------
  
   if(guiIsClicked(hwnd,Button9))
     {
      Ctrl_LSFIX=1;
      PlaySound("ok.wav");
      LongStop_fix=guiGetText(hwnd,Edit3);
      LStopFIX=StrToDouble(LongStop_fix);

      for(i=0; i!=iQ_Aperture;i++)
        {
         TicketNumber=OrderSend(Symbol(),OP_SELL,0.01,Bid,3,0,0,"Robocop Bottone Sell",e_MagicID);
        }
     }
// else PlaySound("error.wav");
// --------- Bottone Auto profit ---------------------------------------
   if(guiIsClicked(hwnd,Button7))
     {
      PlaySound("ok.wav");
      if(CtrlPush==0)
        {
         guiSetBgColor(hwnd,Label1,Red);guiSetTextColor(hwnd,Label1,Black);
         CtrlPush=1;
         AutoProfit=1;
        }
      else if(CtrlPush==1)
        {
         guiSetBgColor(hwnd,Label1,LightGreen);guiSetTextColor(hwnd,Label1,Black);
         CtrlPush=0;
         AutoProfit=0;
        }
      return(0);
     }
// else PlaySound("alert.wav");

// --------- Bottone Clean ---------------------------------------
   if(guiIsClicked(hwnd,Button6))
     {
      PlaySound("ok.wav");
      ObjectsDeleteAll();
      return(0);
     }
// else PlaySound("alert.wav");

// -------- Bottome SELL -------------------------------------------------------
  
   if(guiIsClicked(hwnd,Button1))
     {
      PlaySound("ok.wav");
      sQ_Aperture=guiGetText(hwnd,Edit1);
      iQ_Aperture=StrToInteger(sQ_Aperture);
      for(i=0; i!=iQ_Aperture;i++)
        {
         TicketNumber=OrderSend(Symbol(),OP_SELL,0.01,Bid,3,0,0,"Robocop Bottone Sell",e_MagicID);
        }
     }
// else PlaySound("error.wav");

// --------- Bottone Long -------------------------------------------------------

   if(guiIsClicked(hwnd,Button2))
     {
      PlaySound("ok.wav");
      sQ_Aperture=guiGetText(hwnd,Edit1);
      iQ_Aperture=StrToInteger(sQ_Aperture);
      for(i=0; i!=iQ_Aperture;i++)
        {
         TicketNumber=OrderSend(Symbol(),OP_BUY,0.01,Ask,3,0,0,"RobocopBottone Buy",e_MagicID);//long
        }
     }
// else PlaySound("error.wav");

// --------- Bottone 10 Long  --------------------------------------------------------------

   if(guiIsClicked(hwnd,Button5))
     {
      PlaySound("ok.wav");
      for(i=0; i!=Qt_open; i++)
        {
         TicketNumber=OrderSend(Symbol(),OP_BUY,0.01,Ask,3,0,0,"RobocopBottone Buy",e_MagicID);//long
        }
     }
// else PlaySound("error.wav");

// --------- Bottone 10 Short --------------------------------------------------------------

   if(guiIsClicked(hwnd,Button4))
     {
      PlaySound("ok.wav");
      for(i=0; i!=Qt_open; i++)
        {
         TicketNumber=OrderSend(Symbol(),OP_SELL,0.01,Bid,3,0,0,"V2 Bottone Multi Short",e_MagicID); //short
        }
     }
// else PlaySound("error.wav");

// --------- Bottone Close All   --------------------------------------------------------

   int total=OrdersTotal();

   if(guiIsClicked(hwnd,Button3))
     {
      for(int i=total-1;i>=0;i--)
        {
         PlaySound("ok.wav");
         if(OrderSelect(0,SELECT_BY_POS)==true)
           {
            OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),5,Yellow);
            OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),5,Yellow);
           }
        }
     }
   Dog_woff_OandREO();
   return(0);
  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//|            Watch Dog woff                                        
//+------------------------------------------------------------------+
void Dog_woff_OandREO()
  {
   for(int G=0; G<=OrdersTotal(); G++)
     {
      if(OrderSelect(G,SELECT_BY_POS)==true)
        {
         if(OrderMagicNumber()!=0)
           {
            if(OrderType()==0 && OrderSymbol()==Symbol())
              {
               if(Bid<=(OrderOpenPrice()-limit_closing_long) && OrderProfit()==0) // LONG 
                 {
                  bStatus_close=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),3,Blue); // long
                                                                                                                 //   PlaySound("alert.wav");                 
                 }
               if(OrderProfit()>=dProfit_want)
                 {
                  //--- LONG SE LA CONDIZIONE è GIUSTA RISCUOTE -----

                   Print(" long auto proft è  "+AutoProfit);
                  if(AutoProfit==0)
                    {
                     if((Ctrl_LSFIX==1) && (Bid<=LStopFIX))
                       {

                        bStatus_close=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),3,Red);
                        // PlaySound("APPLAU22.WAV");
                        Ctrl_LSFIX=0;
                       }
                     if(Ctrl_LSFIX==0)
                       {
                        bStatus_close=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),3,Red);
                        // PlaySound("APPLAU22.WAV");
                       }
                       

                    }
                  if(AutoProfit==1)
                    {

                     if((Ctrl_LSFIX==1) && (Bid<=LStopFIX))
                       {

                        bStatus_close=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),3,Red);
                        // PlaySound("APPLAU22.WAV");
                        Ctrl_LSFIX=0;
                       }
                     if(Ctrl_LSFIX==0)
                       {
                        PlaySound("minion_ring_ring.wav");
                       }
                     
                    }
                 }
               //---------------------------------------------------
              }
            if(OrderType()==1 && OrderSymbol()==Symbol())
              {
               if(Bid>=(OrderOpenPrice()+limit_closing_short) && OrderProfit()==0) // SHORT
                 {
                  bStatus_close=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),3,Red); //short
                                                                                                                // PlaySound("alert.wav");
                 }
              }
            //--- SHORT SE LA CONDIZIONE è GIUSTA RISCUOTE -----
            if(OrderProfit()>=dProfit_want)
              {

                 Print("short auto proft è  "+AutoProfit);

               if(AutoProfit==0)
                 {

                  if((Ctrl_SSFIX==1) && (Bid>=SStopFIX))
                    {

                     bStatus_close=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),3,Red);
                     //  PlaySound("APPLAU22.WAV");
                     Ctrl_SSFIX=0;
                    }
                  if(Ctrl_SSFIX==0)
                    {
                     bStatus_close=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),3,Red);
                     //  PlaySound("APPLAU22.WAV");
                    }
                     
                 }

              }
            if(AutoProfit==1)
              {

               if((Ctrl_SSFIX==1) && (Bid>=SStopFIX))
                 {

                  bStatus_close=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),3,Red);
                  //  PlaySound("APPLAU22.WAV");
                  Ctrl_SSFIX=0;
                 }
               if(Ctrl_SSFIX==0)
                 {
                  //   PlaySound("minion_ring_ring.wav");
                 }
              }
          // }
         //--------------------------------------------------- 
        }
     }
   double vbid=NormalizeDouble(MarketInfo(OrderSymbol(),MODE_BID),5);
  }
}
//+------------------------------------------------------------------+
 

some  can help me ?? thankz  at all  :)

 
faustf: when i try to active , not  work ,  where  is   the  error???
  1. "Doesn't work" is meaningless - just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires - meaningless. There are no mind readers here.
  2. We're not going to debug your code.
 

sorry

when i push  button  autoprofit , i should disable  takeprofit target or  enable it ,  but not  do this  remaning  always  in  enable target takeprofit , and  close operation.

how is possible ??

 
faustf: how is possible ??
  1. You code it to do what you want.
  2. learn to code it, or pay someone. We're not going to code it FOR you.
    We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem.
 

but  i write  the  code  up , so  ... in particular  the problem i ddont  understund  is 

// --------- Bottone Auto profit ---------------------------------------
   if(guiIsClicked(hwnd,Button7))
     {
      PlaySound("ok.wav");
      if(CtrlPush==0)
        {
         guiSetBgColor(hwnd,Label1,Red);guiSetTextColor(hwnd,Label1,Black);
         CtrlPush=1;
         AutoProfit=1;
        }
      else if(CtrlPush==1)
        {
         guiSetBgColor(hwnd,Label1,LightGreen);guiSetTextColor(hwnd,Label1,Black);
         CtrlPush=0;
         AutoProfit=0;
        }
      return(0);
     }
// else PlaySound("alert.wav");

in practic , when i push a  button change  color , and  set a variable AutoProfit=0 or 1 , (the logic  is  if  you push first time  set  AutoProfit=1 , if  you push 2° time AutoProfit=0),  in this  mode  i  know  when is  pressed or  not

with this  varible i can  set  if  takeprofit on or  off

i write  this  for  do that 

 Print(" long auto proft è  "+AutoProfit);
                  if(AutoProfit==0)
                    {
                     if((Ctrl_LSFIX==1) && (Bid<=LStopFIX))
                       {

                        bStatus_close=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),3,Red);
                        // PlaySound("APPLAU22.WAV");
                        Ctrl_LSFIX=0;
                       }
                     if(Ctrl_LSFIX==0)
                       {
                        bStatus_close=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),3,Red);
                        // PlaySound("APPLAU22.WAV");
                       }
                       

                    }
                  if(AutoProfit==1)
                    {

                     if((Ctrl_LSFIX==1) && (Bid<=LStopFIX))
                       {

                        bStatus_close=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),3,Red);
                        // PlaySound("APPLAU22.WAV");
                        Ctrl_LSFIX=0;
                       }
                     if(Ctrl_LSFIX==0)
                       {
                        PlaySound("minion_ring_ring.wav");
                       }
                     
                    }
                 }

but  i dont understund  why  not  work  , example  i press it  and  see label change  green to red  , but not   remove the take profit .

For try to debug  i use 

Print(" long auto proft è  "+AutoProfit);

and  i saw in console  write 

2016.08.01 20:41:45.980    RoboCooP_V3 USDCAD,H4: short auto proft è  1

2016.08.01 20:41:45.980    RoboCooP_V3 USDCAD,H4: close #113021074 sell 0.01 GBPUSD at 1.31922 at price 1.31918

but  close the  operation



i ask only if  you  see  a problem could  tell me  where is  , is not  necessary  you write a  solution  , i wanna  learn mql4  ,  not  copy and  past thankz 

 

Why are you trying to fly before you can run?

Write simple scripts to learn how to handle orders.

Then make the next step.

 

thankz  eddie  ,  but  my script is  easy..... (for me ), i  have only one problem , and  i  just  write therfore  if  someone can help about  the  problem is  welcome .

thankz at all again