Heiken ashi with Moving average cross over code

To add comments, please log in or register
satham
11
satham  

Hi all,


i am new here, can anyone help me to write code for my simple strategy


strategy 


Heiken ashi open below moving average --- sell signal with order need to place 

Heiken ashi open above moving average --buy signal with new order to place but square off old position before open new one.


please let me know if you are using same or do you have idea about this, thanks for your response.

William Roeder
20214
William Roeder  
satham: can anyone help me to …
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. MT4: Learn to code it.
    MT5: Learn to code. 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
          urgent help.
satham
11
satham  
@William Roeder
William Roeder:
Help you with what? You haven't stated a problem, you stated a want. You have only four choices:
  1. Search forit.
  2. Beg at
  3. MT4: Learn to code it.
    MT5: Learn to code. 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
          urgent help.

@William Roeder Thanks for your response,


i tried belo code 

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

//|                                                 Adam and Eve.mq4 |

//|                                        Copyright 2016, onesoubra |

//|                                       https://www.onesoubra.com/ |

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



#property copyright   "Copyright 2019, satham"
#property link        "https://www.mql5.com/en/job/new?prefered=satham2019"
#property version     "1.00"
#property description "Skype: satham"
#property description "https://www.onesoubra.com/"
#property description " "
#property description "- Do not use only one currency pair"
#property strict

extern double calculated_amount = 10000;     //Amount for AUTO Lot
extern double calculated_lot = 1;
//extern double orderType = ''MIS'';        //Auto Lot Size each Amount
extern double protected_free_margin = 90.9; //Protected % of Free Margin
extern int    magic = 1234;                 //EA ID Number (Magic Number)

   string trade_comment;
   int    slippage = 5;
   int  AccountStopoutMode();

   //double auto_lot;
///double atr14_2;
  double atr14_1;
///double atr14_0;
   double haopen;
///double haHighLow_1;
   double haclose;
   double hahigh;
   double halow;
   double sma20_2, sma20_1, sma20_0,
          sma14_2, sma14_1, sma14_0,
          sma12_2, sma12_1, sma12_0,
          sma10_2, sma10_1, sma10_0,
          ema9_2, ema9_1, ema9_0,ema9_3, 
          sma7_2, sma7_1, sma7_0,
          sma5_2, sma5_1, sma5_0;
   int    ticketBid;
   int    ticketAsk;
#define HAHIGH      0;
#define HALOW       1;
#define HAOPEN      2;
#define HACLOSE     3;
//Heiken

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

//| Expert initialization function                                   |

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

int OnInit()
{   
   trade_comment = "FROM TIME FRAME: "+IntegerToString(Period())+" Min"; 
   //This function converts value of integer type into a string of a specified length and returns the obtained string
//---
   return(INIT_SUCCEEDED);
}//END OnInit()

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

//| Expert OnTick function                                           |

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

void OnTick()
{
   //auto_lot = AccountBalance() / calculated_amount * calculated_lot;
  
 //atr14_2 = iATR(Symbol(),PERIOD_CURRENT,14,2);
   atr14_1 = iATR(Symbol(),PERIOD_CURRENT,14,1);
 //atr14_0 = iATR(Symbol(),PERIOD_CURRENT,14,0);
   
     haopen = iCustom(Symbol(),PERIOD_CURRENT,"Heiken Ashi",Red,White,Red,White,haopen,1);

   //haHighLow_1 = iCustom(Symbol(),PERIOD_CURRENT,"Heiken Ashi",Red,White,Red,White,1,1);

     haclose    = iCustom(Symbol(),PERIOD_CURRENT,"Heiken Ashi",Red,White,Red,White,haclose,1);
     hahigh   = iCustom(Symbol(),PERIOD_CURRENT,"Heiken Ashi",Red,White,Red,White,hahigh,1);
     halow    =  iCustom(Symbol(),PERIOD_CURRENT,"Heiken Ashi",Red,White,Red,White,halow,1);

   ema9_2  = iMA(Symbol(),PERIOD_CURRENT,9,0,MODE_EMA,PRICE_CLOSE,2);
   ema9_1  = iMA(Symbol(),PERIOD_CURRENT,9,0,MODE_EMA,PRICE_CLOSE,1);
   ema9_0  = iMA(Symbol(),PERIOD_CURRENT,9,0,MODE_EMA,PRICE_CLOSE,0);
   ema9_3  = iMA(Symbol(),PERIOD_CURRENT,9,0,MODE_EMA,PRICE_CLOSE,0);
   {
      //TO SELL
           
      if (haclose < ema9_0)

      {                         

      {
      
      sell();
      
      }}}//END SELL CONDITIONS

      //TO BUY

      if (haopen > ema9_0) 
      {
      {
      
      buy();
      
      }}}//END BUY CONDITIONS
            

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

//| Expert sell function                                             |

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

void sell()
{   
   ticketBid =
            OrderSend(Symbol(),OP_SELL,1,Bid,slippage,0,Ask-atr14_1,trade_comment,magic,0,clrNONE);
}//END sell()

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

//| Expert buy function                                              |

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

void buy()
{   
   ticketAsk =
            OrderSend(Symbol(),OP_BUY,1,Ask,slippage,0,Bid+atr14_1,trade_comment,1234,0,clrNONE);
}//END buy()

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

//END   

not working for me 

William Roeder
20214
William Roeder  
  1. Why did you post your MT4 question in the Root / MT5 General section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2.         haopen = iCustom(Symbol(),PERIOD_CURRENT,"Heiken Ashi",Red,White,Red,White,haopen,1);
        haclose    = iCustom(Symbol(),PERIOD_CURRENT,"Heiken Ashi",Red,White,Red,White,haclose,1);
          hahigh   = iCustom(Symbol(),PERIOD_CURRENT,"Heiken Ashi",Red,White,Red,White,hahigh,1);
          halow    = iCustom(Symbol(),PERIOD_CURRENT,"Heiken Ashi",Red,White,Red,White,halow,1);
    The variable haopen has a random value. How can that be a input? You need to specify which buffer you want. Likewise the rest.
              take candle color hekin ashi - Inflation - MQL4 and MetaTrader 4 - MQL4 programming forum

  3.    ema9_0  = iMA(Symbol(),PERIOD_CURRENT,9,0,MODE_EMA,PRICE_CLOSE,0);
       ema9_3  = iMA(Symbol(),PERIOD_CURRENT,9,0,MODE_EMA,PRICE_CLOSE,0);
    What's the difference?

  4. if (haopen > ema9_0) 
    You are looking at a signal. Once that becomes true you will open a new order per tick. No tests for already open order, new bar, or a change in signal.
              MQL4 (in Strategy Tester) - double testing of entry conditions - Strategy Tester - Expert Advisors and Automated Trading - MQL5 programming forum #1

  5. ticketAsk =
                OrderSend(Symbol(),OP_BUY,1,Ask,slippage,0,Bid+atr14_1,trade_comment,1234,0,clrNONE);
    Check your return codes for errors, and report them including GLE/LE. Don't look at it unless you have an error. Don't just silence the compiler, it is trying to help you.
              What are Function return values ? How do I use them ? - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles

To add comments, please log in or register