how to make macd sample can use in another chart with different pair? - page 2

 
RaptorUK:
Are you running this in the Strategy Tester or a Demo or Live account ?

i mean little live account, in little money not a big cash... :)
 

Did you enable live trading ? do you have a smiley face in the top right hand corner of the chart with the EA name ?

 
RaptorUK:

Did you enable live trading ? do you have a smiley face in the top right hand corner of the chart with the EA name ?


yes off course, .. thanks for remind me, i had trading forex pass 3 years ago, until now.., i just do some analyze the technical, but maybe i have bad IQ in metatrader language..,

the "macd sample" that give from metatrader is works fine.. but i want to modify it to enable is some different chart, different pair.

so i hope in that case study i can have some several order (several open position, several buy or sell). so, i can averaging what will happen in the end of my analyze in the next two or three months, will i have profit or no? 10,20,or 30 %...

 
gekafx:


yes off course, .. thanks for remind me, i had trading forex pass 3 years ago, until now.., i just do some analyze the technical, but maybe i have bad IQ in metatrader language..,

the "macd sample" that give from metatrader is works fine.. but i want to modify it to enable is some different chart, different pair.

so i hope in that case study i can have some several order (several open position, several buy or sell). so, i can averaging what will happen in the end of my analyze in the next two or three months, will i have profit or no? 10,20,or 30 %...

OK, need to check all the basics . . . .

If no order is being placed then logically these conditions are not true . . .

if(MacdCurrent<0 && MacdCurrent>SignalCurrent && MacdPrevious<SignalPrevious &&
         MathAbs(MacdCurrent)>(MACDOpenLevel*Point) && MaCurrent>MaPrevious)
         

// check for short position (SELL) possibility
if(MacdCurrent>0 && MacdCurrent<SignalCurrent && MacdPrevious>SignalPrevious &&
         MacdCurrent>(MACDOpenLevel*Point) && MaCurrent<MaPrevious)

I suggest you add Print() statements to print all these variables to the log so you can investigate further . . . . I could do this for you but then you miss out on all the fun ;-)

 
RaptorUK:

OK, need to check all the basics . . . .

If no order is being placed then logically these conditions are not true . . .

I suggest you add Print() statements to print all these variables to the log so you can investigate further . . . . I could do this for you but then you miss out on all the fun ;-)


hahaha...., aha... can you help me for just once again?
//+------------------------------------------------------------------+
//|                                                  MACD Sample.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#define MAGIC 140179

extern double TakeProfit = 50;
extern double Lots = 0.1;
extern double TrailingStop = 30;
extern double MACDOpenLevel=3;
extern double MACDCloseLevel=2;
extern double MATrendPeriod=26;
extern double Stoploss = 30;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   double MacdCurrent, MacdPrevious, SignalCurrent;
   double SignalPrevious, MaCurrent, MaPrevious;
   int cnt, ticket, total;
// initial data checks
// it is important to make sure that the expert works with a normal
// chart and the user did not make any mistakes setting external 
// variables (Lots, StopLoss, TakeProfit, 
// TrailingStop) in our case, we check TakeProfit
// on a chart of less than 100 bars
   if(Bars<100)
     {
      Print("bars less than 100");
      return(0);  
     }
   if(TakeProfit<10)
     {
      Print("TakeProfit less than 10");
      return(0);  // check TakeProfit
     }
// to simplify the coding and speed up access
// data are put into internal variables
   MacdCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0);
   MacdPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1);
   SignalCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0);
   SignalPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1);
   MaCurrent=iMA(NULL,0,MATrendPeriod,0,MODE_EMA,PRICE_CLOSE,0);
   MaPrevious=iMA(NULL,0,MATrendPeriod,0,MODE_EMA,PRICE_CLOSE,1);

   total=OrdersTotal();   \============================================>>>> in this line, its only open just 1 position right?
   if(total<1)            /============================================>>>>  what sould i do then? if i want several order in total order..??
     {
      // no opened orders identified
      if(AccountFreeMargin()<(1000*Lots))
        {
         Print("We have no money. Free Margin = ", AccountFreeMargin());
         return(0);  
        }
      // check for long position (BUY) possibility
      if(MacdCurrent<0 && MacdCurrent>SignalCurrent && MacdPrevious<SignalPrevious &&
         MathAbs(MacdCurrent)>(MACDOpenLevel*Point) && MaCurrent>MaPrevious)
        {
         ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-Stoploss*Point,Ask+TakeProfit*Point,"macd sample",MAGIC,0,Green);  >>=== in this line should i place the magic number??(MAGIC)
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
           }
         else Print("Error opening BUY order : ",GetLastError()); 
         return(0); 
        }
      // check for short position (SELL) possibility
      if(MacdCurrent>0 && MacdCurrent<SignalCurrent && MacdPrevious>SignalPrevious && 
         MacdCurrent>(MACDOpenLevel*Point) && MaCurrent<MaPrevious)
        {
         ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+Stoploss*Point,Bid-TakeProfit*Point,"macd sample",MAGIC,0,Red);
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
           }
         else Print("Error opening SELL order : ",GetLastError()); 
         return(0); 
        }
      return(0);
     }
   // it is important to enter the market correctly, 
   // but it is more important to exit it correctly...   
    for(cnt=0;cnt<total;cnt++)                                \===============>all this line is original from macd sample
     {                                                         \==============>before i midified,
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);             >=============>
      if(OrderType()<=OP_SELL &&   // check for opened position /=============>
         OrderSymbol()==Symbol())  // check for symbol         /==============>
     
     
     
       for(int pos = OrdersTotal()-1; pos >= 0 ; pos--) if (           \===========>and then, i modified like this as like your 
        OrderSelect(pos, SELECT_BY_POS)            // Only my orders w/ \==========> suggestion, is this correct??? 
        &&  OrderMagicNumber() == MAGIC           // my magic number    /==========> any suggestion?? help me please....
        &&  OrderSymbol()      == Symbol() ){          // and symbol   /===========>
        // Trail stops etc.

        {
         if(OrderType()==OP_BUY)   // long position is opened
           {
            // should it be closed?
            if(MacdCurrent>0 && MacdCurrent<SignalCurrent && MacdPrevious>SignalPrevious &&
               MacdCurrent>(MACDCloseLevel*Point))
                {
                 OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position
                 return(0); // exit
                }
            // check for trailing stop
            if(TrailingStop>0)  
              {                 
               if(Bid-OrderOpenPrice()>Point*TrailingStop)
                 {
                  if(OrderStopLoss()<Bid-Point*TrailingStop)
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
                     return(0);
                    }
                 }
              }
           }
         else // go to short position
           {
            // should it be closed?
            if(MacdCurrent<0 && MacdCurrent>SignalCurrent &&
               MacdPrevious<SignalPrevious && MathAbs(MacdCurrent)>(MACDCloseLevel*Point))
              {
               OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position
               return(0); // exit
              }
            // check for trailing stop
            if(TrailingStop>0)  
              {                 
               if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
                 {
                  if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
                     return(0);
                    }
                 }
              }
           }
        }
     }
   return(0);
  }
// the end.
 

Re:

total=OrdersTotal();   \============================================>>>> in this line, its only open just 1 position right?
   if(total<1)            /============================================>>>>  what sould i do then? if i want several order in total order..??

if you have any Orders open they will count, even manually placed ones, this will stop the EA opening any orders . . . if you want to allow more than one Order then increase the number after if (total <

The loop you have modified looks OK. just make sure the braces { } are correct.

 
RaptorUK:

Re:

if you have any Orders open they will count, even manually placed ones, this will stop the EA opening any orders . . . if you want to allow more than one Order then increase the number after if (total <

The loop you have modified looks OK. just make sure the braces { } are correct.


still dont make any open order...,.... i still dont get it... :(
 
Did you Print your variables and check them ?
 
Hi Raptor.. im having the same problem :) if I do testing it open and close the position. But when i do live trade it just desnt open any position. I have read som articles about this and some people says that it doesnt work on live trading as its just sample. That MACD sample shows to users how to create an EA. Do you use this EA?
 
peterv:
Hi Raptor.. im having the same problem :) if I do testing it open and close the position. But when i do live trade it just desnt open any position. I have read som articles about this and some people says that it doesnt work on live trading as its just sample. That MACD sample shows to users how to create an EA. Do you use this EA?

Do this test and report back here:  https://www.mql5.com/en/forum/143043/page2#746319 

If the result is ECN follow this ECN link and read . . . then fix your code. 

Reason: