narrow range breakout ea

expertadv
22
expertadv  

I am making narrow range with last four candles in narrow range and enter buy if high crosses above narrow range created by last four candles.

Its very simple ea.

created ea with help of online ea generator, but it has limitations so

high low within 2 % OF LAST FOUR CANDLES 
simple code is as follows 

MAX(HIGH,4) < (HIGH,0) * 1.02 AND 
MIN(LOW,4) > (LOW,0) * 0.98 AND
VOLUME > REF(VOLUME,1)*1.5 AND
CROSSOVER(HIGH,MAXOF(HIGH,4))

MQL CODE IS AS FOLLOWS 


//+------------------------------------------------------------------+
//|                                                  fxeabuilder.mq4 |
//|                                                      fxeabuilder |
//|                                       http://www.fxeabuilder.com |
//+------------------------------------------------------------------+

#property copyright "fxeabuilder.com"
#property link "www.fxeabuilder.com"

// External variables
extern double LotSize = 1;
extern double StopLoss = 0;
extern double TakeProfit = 0;
extern double TrailingStopLimit = 0;
extern double TrailingStopStop = 0;
extern int MagicNumber = 23310;


// Global variables
int LongTicket;
int ShortTicket;
double RealPoint;



// Init function
int init()
        {
      RealPoint = RealPipPoint(Symbol());
     
        }


// Start function
int start()
        {
        //Variables
        
                
                // Long
                
                OrderSelect(LongTicket,SELECT_BY_TICKET);
                if(OrderCloseTime() != 0 || LongTicket == 0)
                {
                
                    
bool buy_condition_1 = iCustom(NULL, 0, HMAX, 0, HIGH, 4) iHighest < High[0] *1.02  ;
bool buy_condition_2 = iCustom(NULL, 0, LMIN, 0, LOW, 4) iLowest > Low[0] *0.98  ;
bool buy_condition_4 = iCustom(NULL, 0, Volx0, 0, VOLUME, 0) iVolume > iCustom(NULL, 0, Volx1, 0, VOLUME, 1) iVolume  ;
bool buy_condition_5 = High[0]  > iCustom(NULL, 0, H4, 0, HIGH, 4) iHighest ;


                                 
                if( buy_condition_1    buy_condition_2  &&  buy_condition_4  &&  buy_condition_5   )
                        {
                                
                                OrderSelect(ShortTicket,SELECT_BY_TICKET);
                                
                                if(OrderCloseTime() == 0 && ShortTicket > 0)
                                        {
                                                                                        
                                                bool Closed = OrderClose(ShortTicket,OrderLots(),Ask,0,Red);
                                        }                               

                                
                                
                                
                                
                                LongTicket = OrderSend(Symbol(),OP_BUY,LotSize,Ask,0,0,0,"Buy Order",MagicNumber,0,Green);
                                
                                
                                OrderSelect(LongTicket,SELECT_BY_TICKET); 
                                double OpenPrice = OrderOpenPrice();
                                
            
             
            if(StopLoss > 0) double LongStopLoss = OpenPrice - (StopLoss * RealPoint);
            if(TakeProfit > 0) double LongTakeProfit = OpenPrice + (TakeProfit * RealPoint);
            
            
                                if(LongStopLoss > 0 || LongTakeProfit > 0) 
                                {
               bool LongMod = OrderModify(LongTicket,OpenPrice,LongStopLoss, LongTakeProfit,0);
                                }
                                
                                                        
                                ShortTicket = 0;
                        }
                
                }
                                
                //Close long
      if (OrdersTotal() > 0)
                {              
                
                    
                
                    
                    
bool close_buy_condition_1 = High[0]  > iBs(NULL, 0, 20, 2, 0, PRICE_CLOSE, MODE_UPPER, 0)   ;
bool close_buy_condition_2 = Low[0]  < iBs(NULL, 0, 20, 2, 0, PRICE_CLOSE, MODE_LOWER, 0)  ;

                    
                
                 if( close_buy_condition_1  &&  close_buy_condition_2   )
                        {
                                OrderSelect(LongTicket,SELECT_BY_TICKET);
                
                                if(OrderCloseTime() == 0 && LongTicket > 0)
                                        {

                                                Closed = OrderClose(LongTicket,OrderLots(),Bid,0,Red);
                                                
                                                
                                                LongTicket = 0;
                                        }               
                    }
                }
                
                return(0);
        }


// Pip Point Function
double RealPipPoint(string Currency)
        {
                int CalcDigits = MarketInfo(Currency,MODE_DIGITS);
                if(CalcDigits == 2 || CalcDigits == 3) double CalcPoint = 0.01;
                else if(CalcDigits == 4 || CalcDigits == 5) CalcPoint = 0.0001;
                return(CalcPoint);
        }
        

am stuck in coding stuff with lots of error have generated PLEASE ANYONE HELP 

Create Your Own Expert Advisor in MQL5 Wizard
Create Your Own Expert Advisor in MQL5 Wizard
  • www.mql5.com
The knowledge of programming languages is no longer a prerequisite for creating trading robots. Earlier lack of programming skills was an impassable obstacle to the implementation of one's own trading strategies, but with the emergence of the MQL5 Wizard, the situation radically changed. Novice traders can stop worrying because of the lack of...
Keith Watford
Moderator
26056
Keith Watford  
expertadv:

As this is MQL4, I will move this topic to the MQL4 and Metatrader 4 section.

In future please post in the correct section.

expertadv
22
expertadv  
Keith Watford:

As this is MQL4, I will move this topic to the MQL4 and Metatrader 4 section.

In future please post in the correct section.

seems inactive forum anybody please help out me.

Keith Watford
Moderator
26056
Keith Watford  
expertadv:

seems inactive forum anybody please help out me.

This section is quite active and a lot of people get help here.

It helps if you indent your code properly and remove the unnecessary empty lines. It will make it easier for others to read.

William Roeder
23455
William Roeder  
expertadv: I am making narrow range with last four candles in narrow range and enter buy if high crosses above narrow range created by last four candles.

Its very simple ea.

created ea with help of online ea generator, but it has limitations so

am stuck in coding stuff with lots of error have generated PLEASE ANYONE HELP 

  1. Post in the correct location.
  2. MAX(HIGH,4) < (HIGH,0) * 1.02 AND 
    MIN(LOW,4) > (LOW,0) * 0.98 AND
    VOLUME > REF(VOLUME,1)*1.5 AND
    CROSSOVER(HIGH,MAXOF(HIGH,4))
    
    No idea what crossover does. If the current high (or Bid) is above the previous high(s) then hasn't it crossed over?

  3. //|                                                  fxeabuilder.mq4 |
    EA builder, EATree, Etasoft forex generator, Forex Strategy Builder, FOREXEADVISOR STRATEGY BUILDER, FX EA Builder, fxDreema, FxPro, Molanis, Online Forex Expert Advisor Generator, Strategy Builder FX, Strategy Quant, Visual Trader Studio, MQL5 Wizard, etc., are all the same. You will get something quick, but then you will spend a much longer time trying to get it right, than if you learned the language up front, and then just wrote it.
    • Since you haven't learned MQL4/5, therefor 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.
      We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem, but we are not going to debug your hundreds of lines of code. You are essentially going to be on your own.

    • EA builder makes bad code counting up while closing multiple orders.
      EA builder makes bad code Bars is unreliable (Max bars in chart), volume is unreliable (miss ticks.) Always use time.
      EA builder makes bad code, not adjusting for 4/5 digit brokers, TP/SL and slippage.
      EA builder makes bad code, not adjusting for ECN brokers. pre-Build 500)
      EA builder makes bad code, not
      checking return codes.

    • EATree uses objects on chart to save values — not persistent storage (files or GV+Flush.) No recovery (crash/power failure.)

    • FX EA Builder makes bad code, not checking return codes.
      FX EA Builder makes bad code, loosing open tickets on terminal restart. No recovery (crash/power failure.)
      FX EA Builder makes bad code, not adjusting stops for the spread.
      FX EA Builder makes bad code, using OrdersTotal directly.

    • FOREXEADVISOR STRATEGY BUILDER makes bad code, non-updateing global variables.
      FOREXEADVISOR STRATEGY BUILDER makes bad code, compilation errors.
      FOREXEADVISOR STRATEGY BUILDER makes bad code, not checking return codes.

    Learn to code it, or pay someone (Freelance) someone to code it.
              Hiring to write script - General - MQL5 programming forum

  4. bool buy_condition_1 = iCustom(NULL, 0, HMAX, 0, HIGH, 4) iHighest < High[0] *1.02  ;
    bool buy_condition_2 = iCustom(NULL, 0, LMIN, 0, LOW, 4) iLowest > Low[0] *0.98  ;
    bool buy_condition_4 = iCustom(NULL, 0, Volx0, 0, VOLUME, 0) iVolume > iCustom(NULL, 0, Volx1, 0, VOLUME, 1) iVolume  ;
    bool buy_condition_5 = High[0]  > iCustom(NULL, 0, H4, 0, HIGH, 4) iHighest ;
    
    Your generated code is utter bable. Do not post code what won't even compile. Learn to code; throw out your conditional logic you posted and code it manually from scratch.
  5. Help you with what? You stated a want. You have only four choices:
    1. Search for it.
    2. Beg at
    3. MT4: Learn to code it.
      MT5: Begin learning 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.
                Hiring to write script - General - MQL5 programming forum
    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
expertadv
22
expertadv  

interesting Williams,will definitely find a way out to problem.

Thanks for your suggestions inspired me and gave direction to go somewhere.

William Roeder
23455
William Roeder  
Don't double post! Don't triple post! You already had this thread open.
          General rules and best pratices of the Forum. - General - MQL5 programming forum
Keith Watford
Moderator
26056
Keith Watford  
expertadv:


Your duplicate posts have been deleted.

expertadv
22
expertadv  

anyone with coding knowledge please tell me how to define a narrow range of 2 % of last four candles.(refer attached image)

I know it is a good brain exercise for mql coders here.

I know its difficult for me but if anybody have knowledge and can spare a min to resolve.

i will be more happy.

what seems easy to anybody can be difficult for another one so just tell if you know the answer to my questions.,if not even then also i will be happy and find a way out but that is secondary plan .

first let check if i can get some help here.,

William Roeder
23455
William Roeder  
expertadv: tell me how to define a narrow range of 2 % of last four candles

Get the HH(4), the LL(4) The range is the difference. Buy if Bid goes above HH + 1% of the range.

Show us your attempt (using the CODE button) and state the nature of your problem.
          No free help 2017.04.21

Or pay someone. Top of every page is the link Freelance.
          Hiring to write script - General - MQL5 programming forum 2018.05.12