How to create Daily Target Profit ?? - page 2

 
Yosafat Supono:
mq5 or mql5?? 

bentuk codingnya MQL5 bos.. / Procedure MQL5 nya

 
bersemi asror:

Hello everyone..

can u help me, how script to make Target Daily Profit for MQL5

Thank U..


Regard..

void CloseCheck()

 {

  int totalOrder = OrdersTotal();

  for(int i=totalOrder-1;i>=0;i--)

  {

    OrderSelect(i, SELECT_BY_POS);

    int type   = OrderType();

    

    bool result = false;

    if (OrderProfit >= 100) // 100 pip

    switch(type)

    {

      //Close opened long positions

      case OP_BUY       : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );

                          break;

      

      //Close opened short positions

      case OP_SELL      : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );

                          

    }

    

    if(result == false)

    {

      Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() );

      Sleep(3000);

    }  

  }

 } 

 

Forum on trading, automated trading systems and testing trading strategies

When you post code please use the CODE button (Alt-S)!

Use the CODE button

Thank you.


 
Now is OK, thank all
 
Ali Sabbaghi:

void CloseCheck()

 {

  int totalOrder = OrdersTotal();

  for(int i=totalOrder-1;i>=0;i--)

  {

    OrderSelect(i, SELECT_BY_POS);

    int type   = OrderType();

    

    bool result = false;

    if (OrderProfit >= 100) // 100 pip

    switch(type)

    {

      //Close opened long positions

      case OP_BUY       : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );

                          break;

      

      //Close opened short positions

      case OP_SELL      : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );

                          

    }

    

    if(result == false)

    {

      Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() );

      Sleep(3000);

    }  

  }

 } 

Is this MQL5 or MQL4? If I got this code right, it closes profitable orders, not based on daily profit...

 

I happen to do similar type of coding by checking the trade history for losses and stop trading and continue the next day.

You will need to iterate your trade history and sum up the profit until $10, then stop for the day.


This code fragment is for checking losses. You can modify it to check for profit.

Check the canTradeToday condition to see if you want to open another trade.


I would suggest you use this code fragment as a small exercise and try coding on your own. 

Otherwise you would have to send your request to the freelance service.

bool canTradeToday()
     {

      datetime current=TimeCurrent();
      string today=convert(current);

      string key="[Loss]["+today+"]";

      if(GlobalVariableCheck(key))
        {
         return false;
        }

      bool success=HistorySelect(0,current);
      if(success)
        {
         double balance=0.0;

         for(int i=0,len=HistoryDealsTotal();i<len; i++)
           {
            //--- Get the deal ticket
            ulong ticket=HistoryDealGetTicket(i);
            HistoryDealProperties  deal;
            deal.time=(datetime)HistoryDealGetInteger(ticket,DEAL_TIME);
            deal.entry=(ENUM_DEAL_ENTRY)HistoryDealGetInteger(ticket,DEAL_ENTRY);
            deal.profit=HistoryDealGetDouble(ticket,DEAL_PROFIT);
            deal.commission=HistoryDealGetDouble(ticket,DEAL_COMMISSION);

            string date=convert(deal.time);

            double netProfit=deal.profit+deal.commission;
            if(deal.entry==DEAL_ENTRY_OUT)
              {
               double percent=netProfit*100/balance;
               string key="[Loss]["+date+"]";
               
                  if(percent<-1.5)
                    {
                     GlobalVariableSet(key,1);
                    }
                

              }

            balance+=netProfit;
           }
        }

      if(GlobalVariableCheck(key))
        {
         Print("Stop trading today as deficit is more than allowed.");
         return false;
        }
      else
        {
         return true;
        }
     }

string convert(datetime d)
     {
      MqlDateTime str1;
      TimeToStruct(d,str1);
      return StringFormat("%02d.%02d.%4d",str1.day,str1.mon,str1.year);
     }
 
asror bersemi:

bentuk codingnya MQL5 bos.. / Procedure MQL5 nya

'>=' - open parenthesis expected 1910 21

Reason: