Watch how to download trading robots for free
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
Experts

Simplest EA using DeMarker indicator - expert for MetaTrader 4

Syahirul Nizzam Bin Haron | English Español Português 日本語 Deutsch

Views:
3081
Rating:
votes: 21
Published:
2020.12.16 16:28
Updated:
2020.12.16 21:38

In the past, I thought of using an EA for my trading and this is part of my simple EA and this is the simplest EA I ever had so please rate this after read...

This EA working on single pair. With the fully functioning setting timeframe, lots, stoploss and takeprofit here are input in the menu properties.


extern ENUM_TIMEFRAMES TF  = PERIOD_CURRENT;// Select Time Frame
extern int period          = 8;// Period DeMarker
extern double lt           = 0.01;// Lots
extern int sl              = 100;// Stop Loss
extern int tp              = 100;// Take Profit
extern double OB           = 0.7;// Over Sold
extern double OS           = 0.3;// Over Bought
extern bool OPENBAR        = false;// Trading on newbar open price

Here is the secret, I divide it into 3 parts of variables:
1. data | timeframe
2. order
3. pair

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

//-- time frame|indicator
double dmrk[5];
int signal  =-1;//-- 0.buy 1.sell
int hold = 0;


//-- order
int ticket  =0;
double lot  =0.0;
int typ     =-1;




//-- pair
datetime t1=0;
bool newbar=false;
bool entry =false;


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

In OnInit() function, I have to initialize an indicator DeMarker array variable and also checking minimum lot size of trading for the specific type of broker requirement.

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnInit()
  {
   ArrayInitialize(dmrk,0.0);
  //---
      const double test_lot   = SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MIN);
      if(lt<test_lot)   lt    = test_lot;
  }

On OnTick() function, this is the for calculating of the indicator and to determine the buy and sell signals

//---------------------------------------------------------------------------
   signal = -1;
//---------------------------------------------------------------------------


//---calc
   for(int i=0; i<ArraySize(dmrk); i++)
     {
      dmrk[i]  =  iDeMarker(Symbol(),TF,period,i);
     }
//---


   if(dmrk[1] > OB)
     {
      hold = 1;//set
     }
   else
      if(dmrk[1] < OS)
        {
         hold = -1;//set
        }
      else
        {
         hold = 0;//reset
        }


   if(hold ==  1)
     {
      if(dmrk[0]<OB && dmrk[1]>OB)
        {
         signal = OP_SELL;
        }
     }
   if(hold == -1)
     {
      if(dmrk[0]>OS && dmrk[1]<OS)
        {
         signal = OP_BUY;
        }
     }

To open a buy and sell signal...

//---------------------------------------------------------------------------
   if(signal != -1)
      if(newbar==true)
         if(entry==false)//door open
           {
            //---
            entry =true;//set
            //---

            if(signal == OP_BUY)
              {
               ticket = OrderSend(Symbol(),OP_BUY,lt,Ask,(int)((Ask-Bid)/Point),
                                  sl>0?Bid-sl*Point:0.0,
                                  tp>0?Bid+tp*Point:0.0,
                                  EAName+":signal= "+IntegerToString(signal)+":hold= "+IntegerToString(hold),
                                  EANumber,
                                  0,
                                  clrBlue);
               signal=-1;
               //hold =0;
              }//reset
            else
               if(signal == OP_SELL)
                 {
                  ticket = OrderSend(Symbol(),OP_SELL,lt,Bid,(int)((Ask-Bid)/Point),
                                     sl>0?Ask+sl*Point:0.0,
                                     tp>0?Ask-tp*Point:0.0,
                                     EAName+":signal= "+IntegerToString(signal)+":hold= "+IntegerToString(hold),
                                     EANumber,
                                     0,
                                     clrRed);
                  signal=-1;
                  //hold =0;
                 }//reset signal

           }


And for the closing...

   if(entry == true) // closing
     {

      if(OrderSelect(ticket,SELECT_BY_TICKET))
        {
         if(OrderCloseTime() == 0)//-- order active trade
           {
            /*  todo condition to close  */
            //entry = false;
           }
         //else
            if(OrderCloseTime() != 0)//--  close by 1. manual 2. sl/tp 3. ea
              {
               entry = false;//reset entry
              }
        }
     }

  



iFisher iFisher

New fisher to catch trend with indication UP and DN

Deviation Rate BIAS MT4 Deviation Rate BIAS MT4

Stock trading indicators. BIAS.

MultiVote On Balance Volume MultiVote On Balance Volume

MultiVote On Balance Indicator displays a higher resolution of trading volume activity to the regular On Balance Volume calculation.

Clarity Index Clarity Index

Clarity index is a purely volume based indicator which is constructed on basis of volume, range and positive/negative candle count. It reflects the strength of trend with respect to volume.