EA. Need help with easy coding.

 

I have an EA I´ve been playing around with good results (demo) . I will share it here below. It is a simple EA that simply place buy/sell-orders every 30 min that last for 60 min. Buy low sell high basically with a twist of scaling in..


What I want is to add a filter to it. So it decides if its suppose to put buy or sell limits in.

For example the Awesome Indicator.



This is how I am thinking:

Every 30 min it checks the Awesome indicator.

If it is + 0.002 and above it launches the sell limits

If it is - 0.002 and below it launches  the buy limits.

If it is in between it doesnt launch anything


The EA is gonna run on Eur/usd on a 15 min chart btw.. So that 0.002 is 20 pips..

(The Awesome Indicator is basically two moving average.. 5 and 35.. So when the 5 MA is more than 20 pips above the 35 it trigges sell-limits.. and vice versa..)



Here is the Script everything is based on.. I also uppload it with an attach file .


Sorry for my bad english and I hope someone can help me with this.




#include <stdlib.mqh>



extern int CheckEveryXMinutes=30;//------------------------l a u n c h
extern int InLastXMins=60;
extern int PipRange=5;
extern int ExpertId = 222;

//extern string Start="5:00";
//extern string Stop="18:00";



void init()
{
   // Do any initialisation stuff in here, every time you switch TF this runs again though.
   // Then start() runs again.
   
   Comment("Changed TF");
   return;
}
Her
//Called for every TICK, so fast and efficient to remain re-entrant!
void start()  
{

   // FUNCTION: Every X minutes if last x minutes range NOT more than X pips execute a script


   if(Bars < 10 || IsTradeAllowed()==false) return;
   
   static datetime CurrentTime = 0;
   static datetime DoWorkTime = 60;
   if (TimeCurrent() < DoWorkTime ) return;

   //Do some work....
   
   int      fromBar = iBarShift(NULL, 0, TimeCurrent()-(60*InLastXMins)),
            toBar = iBarShift(NULL, 0,   TimeCurrent()),
            length = fromBar - toBar + 1,
            HHbar = iHighest(NULL,0, MODE_HIGH, length, toBar),
            LLbar =  iLowest(NULL,0, MODE_LOW,  length, toBar);
   double   high    = High[HHbar], 
            low     =  Low[LLbar]; 
   double range = high - low;
   
   if (range < PipRange)
   {
      
      //Below the minimum pip range for the time period so run script here...
      
      
      
      
      //         << START OF Script code inserted in here.... >>



      
      int    ticket,expiration;
      double point;
      //----
      point=MarketInfo(Symbol(),MODE_POINT);
      expiration=TimeCurrent()+PERIOD_H4*60;
      //----5
      
  ticket=OrderSend(Symbol(),OP_SELLLIMIT,0.07,Bid+400*point,0,Ask+600*point,Ask+200*point,"WIDE HARD",16384,expiration,Red);
  ticket=OrderSend(Symbol(),OP_SELLLIMIT,0.06,Bid+380*point,0,Ask+600*point,Ask+175*point,"WIDE HARD",16384,expiration,Red);
  ticket=OrderSend(Symbol(),OP_SELLLIMIT,0.05,Bid+360*point,0,Ask+600*point,Ask+150*point,"WIDE HARD",16384,expiration,Red);
  ticket=OrderSend(Symbol(),OP_SELLLIMIT,0.04,Bid+300*point,0,Ask+600*point,Ask+125*point,"WIDE HARD",16384,expiration,Red);
  ticket=OrderSend(Symbol(),OP_SELLLIMIT,0.03,Bid+240*point,0,Ask+600*point,Ask+100*point,"WIDE HARD",16384,expiration,Red);             
  ticket=OrderSend(Symbol(),OP_SELLLIMIT,0.02,Bid+180*point,0,Ask+600*point,Ask+75*point,"WIDE HARD",16384,expiration,Red);
  ticket=OrderSend(Symbol(),OP_SELLLIMIT,0.01,Bid+150*point,0,Ask+600*point,Ask+50*point,"WIDE HARD",16384,expiration,Red);
//  ticket=OrderSend(Symbol(),OP_SELLLIMIT,0.01,Bid+210*point,0,Ask+280*point,Ask-10050*point,"SELL LIMIT M30",16384,expiration,Red); 
 // ticket=OrderSend(Symbol(),OP_SELLLIMIT,0.01,Bid+180*point,0,Ask+240*point,Ask+0*point,"SELL LIMIT M30",16384,expiration,Red);
 // ticket=OrderSend(Symbol(),OP_SELLLIMIT,0.01,Bid+120*point,0,Ask+230*point,Ask-25*point,"SELL LIMIT M30",16384,expiration,Red);
 // ticket=OrderSend(Symbol(),OP_SELLLIMIT,0.01,Bid+50*point,0,Ask+200*point,Ask-50*point,"SELL LIMIT M30",16384,expiration,Red);
//-------------------------------------------------------------------------------------------------------------------------------------
 // ticket=OrderSend(Symbol(),OP_BUYLIMIT,0.01,Ask-50*point,0,Bid-200*point,Bid+50*point,"BUY LIMIT M30",16384,expiration,Blue);
 // ticket=OrderSend(Symbol(),OP_BUYLIMIT,0.01,Ask-120*point,0,Bid-230*point,Bid+250*point,"BUY LIMIT M30",16384,expiration,Blue);
 // ticket=OrderSend(Symbol(),OP_BUYLIMIT,0.01,Ask-180*point,0,Bid-240*point,Bid-0*point,"BUY LIMIT M30",16384,expiration,Blue);   
 // ticket=OrderSend(Symbol(),OP_BUYLIMIT,0.01,Ask-210*point,0,Bid-280*point,Bid+100*point,"BUY LIMIT M30",16384,expiration,Blue);
  ticket=OrderSend(Symbol(),OP_BUYLIMIT,0.01,Ask-150*point,0,Bid-600*point,Bid-50*point,"WIDE HARD",16384,expiration,Blue);
  ticket=OrderSend(Symbol(),OP_BUYLIMIT,0.02,Ask-180*point,0,Bid-600*point,Bid-75*point,"WIDE HARD",16384,expiration,Blue);      
  ticket=OrderSend(Symbol(),OP_BUYLIMIT,0.03,Ask-240*point,0,Bid-600*point,Bid-100*point,"WIDE HARD",16384,expiration,Blue);
  ticket=OrderSend(Symbol(),OP_BUYLIMIT,0.04,Ask-300*point,0,Bid-600*point,Bid-125*point,"WIDE HARD",16384,expiration,Blue);
  ticket=OrderSend(Symbol(),OP_BUYLIMIT,0.05,Ask-360*point,0,Bid-600*point,Bid-150*point,"WIDE HARD",16384,expiration,Blue);      
  ticket=OrderSend(Symbol(),OP_BUYLIMIT,0.06,Ask-380*point,0,Bid-600*point,Bid-175*point,"WIDE HARD",16384,expiration,Blue);
  ticket=OrderSend(Symbol(),OP_BUYLIMIT,0.07,Ask-400*point,0,Bid-600*point,Bid-200*point,"WIDE HARD",16384,expiration,Blue);
    
    
      
      
      
      
   // ticket=OrderSend(Symbol(),OP_BUYSTOP,0.01,Ask+50*point,0,Bid-150*point,Bid+600*point,"BUY_STOP M15",16384,expiration,Blue);
   // ticket=OrderSend(Symbol(),OP_BUYSTOP,0.01,Ask+50*point,0,Bid-135*point,Bid+500*point,"BUY_STOP M15",16384,expiration,Blue);
    
  // ticket=OrderSend(Symbol(),OP_BUYSTOP,0.01,Ask+40*point,0,Bid-150*point,Bid+600*point,"BUY_STOP M15",16384,expiration,Blue);
  // ticket=OrderSend(Symbol(),OP_BUYSTOP,0.01,Ask+40*point,0,Bid-140*point,Bid+500*point,"BUY_STOP M15",16384,expiration,Blue);
 //    
  //  ticket=OrderSend(Symbol(),OP_BUYSTOP,0.01,Ask+30*point,0,Bid-130*point,Bid+400*point,"BUY_STOP M15",16384,expiration,Blue);
  //  ticket=OrderSend(Symbol(),OP_BUYSTOP,0.01,Ask+30*point,0,Bid-120*point,Bid+300*point,"BUY_STOP M15",16384,expiration,Blue);
  ////  
  //  ticket=OrderSend(Symbol(),OP_BUYSTOP,0.01,Ask+30*point,0,Bid-110*point,Bid+100*point,"BUY_STOP M15",16384,expiration,Blue);
  // ticket=OrderSend(Symbol(),OP_BUYSTOP,0.01,Ask+30*point,0,Bid-100*point,Bid+80*point,"BUY_STOP M15",16384,expiration,Blue);
  //   
    
   // ticket=OrderSend(Symbol(),OP_SELLSTOP,0.01,Bid-30*point,0,Ask+100*point,Ask-80*point,"SELL_STOP M15",16384,expiration,Red);
   // ticket=OrderSend(Symbol(),OP_SELLSTOP,0.01,Bid-30*point,0,Ask+110*point,Ask-100*point,"SELL_STOP M15",16384,expiration,Red);
    
   // ticket=OrderSend(Symbol(),OP_SELLSTOP,0.01,Bid-30*point,0,Ask+120*point,Ask-300*point,"SELL_STOP M15",16384,expiration,Red);
   // ticket=OrderSend(Symbol(),OP_SELLSTOP,0.01,Bid-30*point,0,Ask+130*point,Ask-400*point,"SELL_STOP M15",16384,expiration,Red);
    
    //ticket=OrderSend(Symbol(),OP_SELLSTOP,0.01,Bid-40*point,0,Ask+140*point,Ask-500*point,"SELL_STOP M15",16384,expiration,Red);
   // ticket=OrderSend(Symbol(),OP_SELLSTOP,0.01,Bid-40*point,0,Ask+150*point,Ask-600*point,"SELL_STOP M15",16384,expiration,Red);
    
  //  ticket=OrderSend(Symbol(),OP_SELLSTOP,0.01,Bid-30*point,0,Ask+70*point,Ask-100*point,"SELL_STOP M15",16384,expiration,Red);
  //  ticket=OrderSend(Symbol(),OP_SELLSTOP,0.01,Bid-25*point,0,Ask+50*point,Ask-80*point,"SELL_STOP M15",16384,expiration,Red);
     
     
      // ticket=OrderSend(Symbol(),OP_BUY,0.01,Ask,3,Bid-80*Point,Bid+300*Point,"BUY MARKET",16384,0,Blue); 
     //  ticket=OrderSend(Symbol(),OP_SELL,0.01,Bid,3,Ask+80*Point,Ask-300*Point,"SELL MARKET",16384,0,Red); 
      // ticket=OrderSend(Symbol(),OP_BUYLIMIT,0.01,Ask-120*point,0,Bid-180*point,Bid+10*point,"BUY LIMIT M15",16384,expiration,Blue);
      //PlaySound("gun.wav");
            


      //         << END OF Script code goes in here.... >>







      Comment(range);   
      
   }

   //Forward schedule next time to do some work...
   DoWorkTime = TimeCurrent() + (CheckEveryXMinutes*60); //DoWorktime is in seconds, CheckEveryXMinutes is in minutes so multiply by 60 to get seconds

   return;
}


 

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

Use the CODE button

 
Sergey Golubev:
Sorry. New to this forum 
 
AlwaysTilt:

EA. Need help with easy coding.

What I want … I hope someone can help me with this.

  1. When you post code please use the CODE button (Alt-S)! (For large amounts of code, attach it.) Please edit your (original) post.
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor

  2. If it's easy, why haven't you coded it.
  3. Help you with what? You haven't stated a problem, you stated a want.
    You have only four choices:
    1. Search for it,
    2. Beg at
    3. learn to code it. If you don't learn MQL4/5, there is no common language for us to communicate. If we tell you what you need, you can't code it. If we give you the code, you don't know how to integrate it into yours.
    4. or pay (Freelance) someone to code it.
    We're not going to code it for you (although it could happen if you are lucky or the problem is interesting.) We are willing to help you when you post your attempt (using CODE button) and state the nature of your problem.
              No free help
              urgent help.

 

It looks easy to code but at the moment I can just hand you this snippet:

static datetime m30bar_dt=0;
datetime dt=iTime(_Symbol,PERIOD_M30,0);
if(dt!=m30bar_dt) {
   // new m30 bar
   m30bar_dt=dt;
   int shift=1;
   double aweval=iAO(_Symbol,PERIOD_M30,shift);
   if(aweval>= 0.002) LaunchSellLimits();
   if(aweval<=-0.002) LaunchBuyLimits();
}

Note it's a MQL4 topic so you're in the wrong part of the forum.

Check if it works for you and show some results.

Reason: