[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 706

 

was creating arrow indicators. God willing, I've created them, I've learned a thing or two. Now I decided to combine them, to make two in one ....... The essence of the idea: have MACD, set certain levels in the + and -. When MACD is behind these levels (both in + and -), then buy and sell arrows will appear. It seems to be done, compiles without errors BUT BUT it does not work like that well not so....

//+------------------------------------------------------------------+
//|                                               Indicator_MACD.mq4 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
// Modify Vinin
#property copyright ""
#property link      ""

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Blue
//---- input parameters
extern int       Fast_EMA=8;
extern int       Slow_EMA=34;
extern double    N = 0.0015;
extern int       A = 10;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double MACD[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   IndicatorBuffers(3);
   SetIndexStyle(0,DRAW_ARROW, EMPTY, 1);
   SetIndexArrow(0,218);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexEmptyValue(0,0.0);
   SetIndexStyle(1,DRAW_ARROW, EMPTY, 1);
   SetIndexArrow(1,217);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexEmptyValue(1,0.0);
   SetIndexBuffer(2,MACD);
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
   int limit = Bars-counted_bars-1;
   
   for(int i = limit; i>= 0; i--) {
      ExtMapBuffer2[i] = EMPTY;
      ExtMapBuffer1[i] = EMPTY;
      MACD[i]=iMACD(NULL,0,Fast_EMA,Slow_EMA,1,1,MODE_MAIN, i);
      if ((MACD[i]>MACD[i+1]) || (MACD[i]<MACD[i+1]))
      {
       if( MACD[i] <-N) ExtMapBuffer2[i] = Low[i]-A*Point;
       if( MACD[i] > N) ExtMapBuffer1[i] = High[i]+A*Point; 
      }
   }
   return(0);
}
//+------------------------------------------------------------------+ 

this is a working indicator

 

And this is what I got.......

//+------------------------------------------------------------------+
//|                                           ndicator_MACD_OsMA.mq4 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
// Modify Vinin
#property copyright ""
#property link      ""

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Blue
//---- input parameters
extern int       F_EMA=8;      // пар-ры MACD
extern int       S_EMA=34;     // пар-ры MACD
extern double    N = 0.0015;   // контр. линия
extern int       A = 10;       // расстояние от бара
extern int       Fast_EMA=12;  // пар-ры OsMA
extern int       Slow_EMA=26;  // пар-ры OsMA
extern int       Signal_EMA=9; // пар-ры OsMA
extern double    Z = 0.00005;  // контр. линия
extern int       B = 10;       // расстояние от бара

//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double MACD[];
double OsMA[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   IndicatorBuffers(3);
   SetIndexStyle(0,DRAW_ARROW, EMPTY, 1);
   SetIndexArrow(0,218);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexEmptyValue(0,0.0);
   SetIndexStyle(1,DRAW_ARROW, EMPTY, 1);
   SetIndexArrow(1,217);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexEmptyValue(1,0.0);
   SetIndexBuffer(2,MACD);
   SetIndexBuffer(2,OsMA);
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
   int limit = Bars-counted_bars-1;
   
   for(int i = limit; i>= 0; i--) {
      ExtMapBuffer2[i] = EMPTY;
      ExtMapBuffer1[i] = EMPTY;
      MACD[i]=iMACD(NULL,0,F_EMA,S_EMA,1,1,MODE_MAIN, i);
      OsMA[i]=iOsMA(NULL,0,Fast_EMA,Slow_EMA,Signal_EMA,PRICE_OPEN,i);
      if (((MACD[i]>MACD[i+1])||(MACD[i]<MACD[i+1]))&&((OsMA[i]>OsMA[i+1])||(OsMA[i]<OsMA[i+1])))
      {
       if( MACD[i] <-N) ExtMapBuffer2[i] = Low[i]-A*Point;
       if( MACD[i] > N) ExtMapBuffer1[i] = High[i]+A*Point;
       if( OsMA[i] <-Z) ExtMapBuffer2[i] = Low[i] -B*Point;
       if( OsMA[i] > Z) ExtMapBuffer1[i] = High[i]+B*Point; 
      }
   }
   return(0);
}
//+------------------------------------------------------------------+ 

I feel something is wrong in the code and I don't understand what it is............................. HELP THE WRONG..... :-))

 
Why aren't the most basic pairs: EUR/USD, USD/JPY in the Quote Archive? Maybe I am doing something wrong?
 

Hello! Thanks to Artem for the functions from KimIV.

Maybe someone knows: one of TakeProfitLastClosePos() functions (returns TakeProfit price of the last closed position or -1), returns TakeProfit valuewith four decimal places, and my DC gives five decimal places (EURUSD pair). I can´t place the next order as the TakeProfit valueof the last closed position and the price to place the next order are directly related to each other.Can you help me get out of this situation? Thanks in advance!!!

double TakeProfitLastClosePos(string sy="", int op=-1, int mn=-1) {
  datetime t;
  double   r=-1;
  int      i, k=OrdersHistoryTotal();

  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
      if (OrderSymbol()==sy || sy=="") {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (op<0 || OrderType()==op) {
            if (mn<0 || OrderMagicNumber()==mn) {
              if (t<OrderCloseTime()) {
                t=OrderCloseTime();
                r=OrderTakeProfit();
              }
            }
          }
        }
      }
    }
  }
  return(r);
}
 
dimon74:

Hello! Thanks to Artem for the functions from KimIV.

Maybe someone knows: one of TakeProfitLastClosePos() functions (returns TakeProfit price of the last closed position or -1), returns TakeProfit valuewith four decimal places, and my DC gives five decimal places (EURUSD pair). I can´t place the next order as the TakeProfit valueof the last closed position and the price to place the next order are directly related to each other.Can you help me get out of this situation? Thanks in advance!!!


Actually, the function returns a value with all significant digits after the decimal point. Even eight decimal places. It's just that the default output is 4 digits. But if you use DoubleToStr() beforehand, you can make sure
 
drknn:
OrderSend(Name of currency pair.... and other parameters......)


I need help in solving the code for multicurrency EA, I need one EA to work and trades to be opened on any currency pairs.

I have dug multicurrency EA in CodeBase, but I can't understand what's where and why.

If you do not understand the code of the multicurrency EA you won't be able to check it in the Strategy Tester (( Please explain to me, based on this code or some other code, what should go where and why, so that my EA will trade on all pairs. I don't understand it, but if I cut the code without understanding it, it will work, but I still don't understand the implementation, and I will have to ask for help again.

extern string Instrument = "EURUSD";
extern double Lots = 0.1;
extern int    TakeProfit = 50;
extern int    TrailingStop = 0;
extern int    StopLoss = 50;
extern int    FirstOpenLevel = 5;
extern int    LastOpenLevel = 20;
extern int    Slope = 2;
extern int    CloseLevel = 20;
 

int start()
{
   double MacdCurrent, MacdPrevious, SignalCurrent, SignalPrevious;
   int    i, total, p1, p2, p3, p4, p5, p6, p7, p8, p9;
  
   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);
      
   p1=0; p2=0; p3=0; p4=0; p5=0; p6=0; p7=0; p8=0; p9=0;
      
     OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
     
     if(OrderSymbol()=="EURUSD") {p1=1;}
     if(OrderSymbol()=="GBPUSD") {p2=1;}
     if(OrderSymbol()=="USDCHF") {p3=1;}
     if(OrderSymbol()=="USDJPY") {p4=1;}
     if(OrderSymbol()=="EURCHF") {p5=1;}
     if(OrderSymbol()=="EURGBP") {p6=1;}
     if(OrderSymbol()=="AUDUSD") {p7=1;}
     if(OrderSymbol()=="USDCAD") {p8=1;}
     if(OrderSymbol()=="EURJPY") {p9=1;}
      
     OrderSelect(1,SELECT_BY_POS,MODE_TRADES);
     
     if(OrderSymbol()=="EURUSD") {p1=1;}
     if(OrderSymbol()=="GBPUSD") {p2=1;}
     if(OrderSymbol()=="USDCHF") {p3=1;}
     if(OrderSymbol()=="USDJPY") {p4=1;}
     if(OrderSymbol()=="EURCHF") {p5=1;}
     if(OrderSymbol()=="EURGBP") {p6=1;}
     if(OrderSymbol()=="AUDUSD") {p7=1;}
     if(OrderSymbol()=="USDCAD") {p8=1;}
     if(OrderSymbol()=="EURJPY") {p9=1;}
     
     OrderSelect(2,SELECT_BY_POS,MODE_TRADES);
     
     if(OrderSymbol()=="EURUSD") {p1=1;}
     if(OrderSymbol()=="GBPUSD") {p2=1;}
     if(OrderSymbol()=="USDCHF") {p3=1;}
     if(OrderSymbol()=="USDJPY") {p4=1;}
     if(OrderSymbol()=="EURCHF") {p5=1;}
     if(OrderSymbol()=="EURGBP") {p6=1;}
     if(OrderSymbol()=="AUDUSD") {p7=1;}
     if(OrderSymbol()=="USDCAD") {p8=1;}
     if(OrderSymbol()=="EURJPY") {p9=1;}
     
     OrderSelect(3,SELECT_BY_POS,MODE_TRADES);
     
     if(OrderSymbol()=="EURUSD") {p1=1;}
     if(OrderSymbol()=="GBPUSD") {p2=1;}
     if(OrderSymbol()=="USDCHF") {p3=1;}
     if(OrderSymbol()=="USDJPY") {p4=1;}
     if(OrderSymbol()=="EURCHF") {p5=1;}
     if(OrderSymbol()=="EURGBP") {p6=1;}
     if(OrderSymbol()=="AUDUSD") {p7=1;}
     if(OrderSymbol()=="USDCAD") {p8=1;}
     if(OrderSymbol()=="EURJPY") {p9=1;}
     
     OrderSelect(4,SELECT_BY_POS,MODE_TRADES);
     
     if(OrderSymbol()=="EURUSD") {p1=1;}
     if(OrderSymbol()=="GBPUSD") {p2=1;}
     if(OrderSymbol()=="USDCHF") {p3=1;}
     if(OrderSymbol()=="USDJPY") {p4=1;}
     if(OrderSymbol()=="EURCHF") {p5=1;}
     if(OrderSymbol()=="EURGBP") {p6=1;}
     if(OrderSymbol()=="AUDUSD") {p7=1;}
     if(OrderSymbol()=="USDCAD") {p8=1;}
     if(OrderSymbol()=="EURJPY") {p9=1;}
   
   total=OrdersTotal();
   for(i=0;i<total;i++)
   {
     OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
        
     if(OrderSymbol()==Instrument)
      {
         if(OrderType()==OP_BUY) 
          {
            if(MacdPrevious-SignalPrevious-MacdCurrent+SignalCurrent>CloseLevel*0.1*Point)
                {
                 OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet);
                 return(0);
                }
            if(TrailingStop>0)  
              {      
               if(Bid-OrderOpenPrice()>Point*TrailingStop)
                 {
                  if(OrderStopLoss()<Bid-Point*TrailingStop || OrderStopLoss()==0)
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
                     return(0);
                    }
                 }
              }
           }
          if(OrderType()==OP_SELL)
           {
            if(SignalPrevious-MacdPrevious-SignalCurrent+MacdCurrent>CloseLevel*0.1*Point)
              {
               OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet);
               return(0);
              }
            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);
                    }
                 }
              }
           }
        }
     }
   
   total=OrdersTotal();  
   if(total<5)
   {
     if((Instrument=="EURUSD" && p1<1) || (Instrument=="GBPUSD" && p2<1) || 
        (Instrument=="USDCHF" && p3<1) || (Instrument=="USDJPY" && p4<1) ||
        (Instrument=="EURCHF" && p5<1) || (Instrument=="EURGBP" && p6<1) ||
        (Instrument=="AUDUSD" && p7<1) || (Instrument=="USDCAD" && p8<1) ||
        (Instrument=="EURJPY" && p9<1)) 
      {
        if(MacdCurrent<0 && MacdCurrent-SignalCurrent>SignalCurrent*FirstOpenLevel*(-0.01)
           && MacdCurrent-SignalCurrent<SignalCurrent*LastOpenLevel*(-0.01)
           && MacdCurrent-MacdPrevious>MacdPrevious*Slope*(-0.01)
           && MacdPrevious-SignalPrevious-MacdCurrent+SignalCurrent<(CloseLevel-10)*0.1*Point)  
          {
           OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"",0,0,Green);
           return(0); 
          }   
      
         if(MacdCurrent>0 && SignalCurrent-MacdCurrent>SignalCurrent*FirstOpenLevel*0.01
            && SignalCurrent-MacdCurrent<SignalCurrent*LastOpenLevel*0.01
            && MacdPrevious-MacdCurrent>MacdPrevious*Slope*0.01
            && SignalPrevious-MacdPrevious-SignalCurrent+MacdCurrent<(CloseLevel-10)*0.1*Point)
          {
           OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"",0,0,Red);
           return(0); 
          }
       }
    }
}
 
igrok2008:

And this is what I got.......
I smell something wrong in the code and I don't know what it is................

You've added a fourth indicator array, but you still have three in your code, below is the tweaked code:
int init(){
//---- indicators
   IndicatorBuffers(4);   
   SetIndexStyle(0,DRAW_ARROW, EMPTY, 1);
   SetIndexArrow(0,218);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexEmptyValue(0,0.0);   
   SetIndexStyle(1,DRAW_ARROW, EMPTY, 1);
   SetIndexArrow(1,217);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexEmptyValue(1,0.0);   
   SetIndexBuffer(2,MACD);
   SetIndexBuffer(3,OsMA);   
//----
}
 
Infinity:
I need help in understanding the code for multicurrency EA.

I have dug a multicurrency EA in CodeBase, but I cannot find out what's where and why.
If you do not understand the code, you cannot check it in the Strategy Tester. (( Please, explain to me, based on this code or some other code, what should go where and why, so that my EA may trade on all pairs. I don't understand the code, but it may work, but I still don't understand the implementation, and I will have to ask for help again.

This code does not fit you, as it opens transactions only on the pair, to which it is attached, it can be seen on the lines:

OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"",0,0,Green);
OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"",0,0,Red);

Function Symbol () returns the current pair. Accordingly, to open on other currency pairs, instead of this function, simply enter the desired name of the financial instrument.

 
ToLik_SRGV:

This code does not suit you as it only opens trades on the pair to which it is attached, this can be seen from the lines:

Function Symbol () returns the current pair. Accordingly, to open trades on other currency pairs, instead of this function, simply type the name of the financial instrument you need.


It is not that easy. You also need to change the Point to the right value, and Ask. And Bid too.
 
ToLik_SRGV:

This code does not suit you as it only opens trades on the pair to which it is attached, this can be seen from the lines:

Function Symbol () returns the current pair. Accordingly, to open trades on other currency pairs, instead of this function, just type the name of the financial instrument you need.


That's the thing. My Expert Advisor receives signals from different currency pairs and instead of Symbol() in my order, it assigns a variable with the value of the currency pair, i.e. if the signal comes from euro, it is EURUSD, if it comes from yen, then USDJPY but including the EA, it sees all the signals, but opens only the currency on which it is standing.

This is how I do the following sample code

//---- ранее на обработке переменная Symb получает значение валютной пары с которой пришол сигнал
// далее я сравниваю и пытаюсь открыть ордер
 if (Symb == "GBPUSD") {val ="GBPUSD"; ticket=OrderSend(val,OP_BUY,0.1,Ask,3,Bid-20*Point,Ask+25*Point,"",16384,0,Green);}
 if (Symb == "EURUSD") {val ="EURUSD"; ticket=OrderSend(val,OP_BUY,0.1,Ask,3,Bid-20*Point,Ask+25*Point,"",16384,0,Green);}
 if (Symb == "USDJPY") {val ="USDJPY"; ticket=OrderSend(val,OP_BUY,0.1,Ask,3,Bid-20*Point,Ask+25*Point,"",16384,0,Green);}
Reason: