Page 1 of 1

Back Testing a manual trading system using an EA MQL4 Coding help request

Posted: Sat Jun 25, 2022 10:32 am
by XXXX
I am trying to get an MT4 EA I have written that opens and closes trades manually by clicking buttons on the chart to do the same within the strategy tester.

There are people that have done it but I can't find any examples of how to code it. If anyone is aware of some sample code to do this it would be greatly appreciated.

Re: Back Testing a manual trading system using an EA MQL4 Coding help request

Posted: Sun Jun 26, 2022 10:48 am
by XXXX
Found an example of what I need.

Code: Select all

#include<Controls/Button.mqh>

CButton buybutton;
CButton sellbutton;

extern int        magic          = 1234;            //Magic Number
extern double     Lots           = 0.01;             //Lot Size
extern double     Take_Profit    = 15;              //Take Profit
extern double     Stop_Loss      = 4.5;             //Stop Loss
extern int        BuyX           = 0;               //Buy Button Height Start
extern int        BuyY           = 500;             //Buy Button Width Start
extern int        BuyX1          = 0;               //Buy Button Height Finish
extern int        BuyY1          = 590;             //Buy Button Width Finish
extern int        SellX           = 0;              //Sell Button Height Start
extern int        SellY           = 600;            //Sell Button Width Start
extern int        SellX1          = 0;              //Sell Button Height Finish
extern int        SellY1          = 690;            //Sell Button Width Finish

double ticket1, ticket2;

   int P = 1;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   if(Digits == 5 || Digits == 3 || Digits == 1)P = 10;else P = 1; // To account for 5 digit brokers


   
   buybutton.Create(0,"buybutton",BuyX,BuyY,BuyX1,BuyY1,25);
   buybutton.Text("Buy");
   buybutton.FontSize(12);
   buybutton.Color(clrWhite);
   buybutton.ColorBackground(clrGreen);
   
   sellbutton.Create(0,"sellbutton",SellX,SellY,SellX1,SellY1,25);
   sellbutton.Text("Sell");
   sellbutton.FontSize(12);
   sellbutton.Color(clrWhite);
   sellbutton.ColorBackground(clrRed);
   

   return(0);
  }

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
   {
//---
   if( IsVisualMode() )
   {
      long   lparam = 0;
      double dparam = 0.0;
      string sparam = "";
//---
      sparam = "buybutton";
      if( bool( ObjectGetInteger( 0, sparam, OBJPROP_STATE ) ) )
        OnChartEvent( CHARTEVENT_OBJECT_CLICK, lparam, dparam, sparam );
//---
      sparam = "sellbutton";
      if( bool( ObjectGetInteger( 0, sparam, OBJPROP_STATE ) ) )
        OnChartEvent( CHARTEVENT_OBJECT_CLICK, lparam, dparam, sparam );
   }
//---
   for(int i=OrdersTotal()-1;i>=0;i--)
   {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         if(OrderMagicNumber()==magic)
            if(OrderSymbol()==Symbol())
               if(OrderType()==OP_BUY)
                  if(Ask>OrderOpenPrice())
                     if(OrderStopLoss()<Bid-(Stop_Loss*Point*P))
                        ticket1=OrderModify(OrderTicket(),OrderOpenPrice(),Bid - (Stop_Loss*Point*P),OrderTakeProfit(),0,clrNONE);
                        
                          
                        
          
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         if(OrderMagicNumber()==magic)
            if(OrderSymbol()==Symbol())
               if(OrderType()==OP_SELL)
                  if(Bid<OrderOpenPrice())
                     if(OrderStopLoss()>Ask+(Stop_Loss*Point*P))   
                        ticket2=OrderModify(OrderTicket(),OrderOpenPrice(),Bid + (Stop_Loss*Point*P),OrderTakeProfit(),0,clrNONE);
   }    
   }             
            

//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
   
   if(id==CHARTEVENT_OBJECT_CLICK && sparam=="buybutton")
   {
      if(OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Bid - (Stop_Loss*Point*P),Bid + (Take_Profit*Point*P),NULL,magic,0,clrBlue)==-1)
         Print("did not place buy order");
      buybutton.Pressed(false);
   }
   
   if(id==CHARTEVENT_OBJECT_CLICK && sparam=="sellbutton")
   {
      if(OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Ask+(Stop_Loss*Point*P),Ask-(Take_Profit*Point*P),NULL,magic,0,clrRed)==-1)
         Print("did not place buy order");
      sellbutton.Pressed(false);
   }   
  }


Re: Back Testing a manual trading system using an EA MQL4 Coding help request

Posted: Fri Jul 29, 2022 2:15 am
by lansion
Dear Mr. Fourxxxx, I want to buy the source code of this indicator and modify it. How much would you sell me the source code for? I need the MQL4 source file (XU v20-XARD UNIVERSE). Thank you lansion888@gmail.com

Re: Back Testing a manual trading system using an EA MQL4 Coding help request

Posted: Fri Jul 29, 2022 10:16 am
by XXXX
lansion wrote: Fri Jul 29, 2022 2:15 am Dear Mr. Fourxxxx, I want to buy the source code of this indicator and modify it. How much would you sell me the source code for? I need the MQL4 source file (XU v20-XARD UNIVERSE). Thank you
Image
lansion888@gmail.com
It's not even mine to sell. FUCK OFF