How to use iMA to order when iMa crossover right before candle ?

To add comments, please log in or register
dlrkfka1028
16
dlrkfka1028  

I would like to make a EA which is when 

iMa crossover the Close[1] like right before candle then buy or sell depends on what former candlewas

I tried to code but still i don't get it :(. I can't figure it out how to use iMa.

this is my code.

extern double volume1 = 1.0;//Lot사이즈(Buy)
extern double volume2 = 1.0;//Lot사이즈(Sell)
extern int order_total = 10; //주문허용 갯수
extern int magic = 15425; //매직넘버 
extern int stop_loss = 50; //손절매
extern int take_profit = 100;//이익실현 
datetime prev_time;

double real_sl=  0.0;
double real_tp=  0.0;
int sell_count = 0;
int buy_count = 0;

int OnInit()
  {
    // prev_time=Time[0];  
    return(INIT_SUCCEEDED);
  }

void OnDeinit(const int reason)
  {
  }
void OnTick()
  {  
 if(OrdersTotal()==0 || OrdersTotal()< order_total){        
//buy
 double value_ima=iMA(Symbol(),0,5,0,0,PRICE_CLOSE,0);

         if(Time[0]!=prev_time && value_ima<=Close[1] && value_ima>=Open[1] && (Open[1]<Close[1])){
                                       
               if(stop_loss > 0){
                           real_sl = NormalizeDouble(Bid-stop_loss*Point,Digits);
                        }
                        if(take_profit > 0){
                           real_tp = NormalizeDouble(Bid+take_profit*Point,Digits);
                   }
            int ordersend = OrderSend(Symbol(),OP_BUY,volume1,Ask,10,real_sl,real_tp,"Order",magic,0,clrGreen);
            buy_count+=1;
         }      
         prev_time=Time[0];

        }
}

William Roeder
20207
William Roeder  
  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. 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 and MetaTrader 4 - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
    Only those functions that return a value (e.g. iClose, MarketInfo, etc.) must you call ResetLastError before in order to check after.

  3. What is the value of real_sl/real_tp when stop_loss/take_profit is zero?
  4. They also must be a multiple of tick size not point
dlrkfka1028
16
dlrkfka1028  
whroeder1:
  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. 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 and MetaTrader 4 - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
    Only those functions that return a value (e.g. iClose, MarketInfo, etc.) must you call ResetLastError before in order to check after.

  3. What is the value of real_sl/real_tp when stop_loss/take_profit is zero?
  4. They also must be a multiple of tick size not point

Oh sorry, I'm new here so didn't know about the rules.

I edited my code.It still has errors tho :(

stop_loss/take_profit is extern variable!

error
Alain Verleyen
38661
Alain Verleyen  

Forum on trading, automated trading systems and testing trading strategies

General rules and best practices of the Forum.

Don't double post please !


Please do not post multiple times. Post once in a relevant thread or open a topic with a relevant title. You probably don't realise how selfish you are being by posting multiple times.

Have you any idea how frustrating it is when someone uses their free time to answer a query and then opens another thread and finds a duplicate query that has already been answered? That means that the time spent on answering was completely wasted! Time that could have been used to help somebody else.

Your duplicated posts have been deleted.


To add comments, please log in or register