Getting previous histogram information

 

Can any one help? How do i get the previous volume histogram information on a current bar.

I want my EA to enter if all the rules are true on the current bar + a histogram cross above ema of the last previous candle

I tried this;

(GreenArrow >= VMA && RedArrow >= VMA && NewBar)

but it doesnt work.

bear with me as i am not a coder

 
Use this: https://docs.mql4.com/predefined/variables/volume with the bar number you are interested in.
 

But i am using a custom Volume that has an ema displayed in a separate window, so i have to use icustome to use it in my EA . is there another way to do this?? using regular Volume??

//+------------------------------------------------------------------+
//|                            Volume with Custom Moving Average.mq4 |
//|                       Copyright ?2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2004, MetaQuotes Software Corp. Modified RonT"
#property link      "http://www.metaquotes.net/"

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Red
#property indicator_color2 Green
#property indicator_color3 Red

// User input
extern int MA_Period=13;
extern int MA_Shift=0;
extern int MA_Mode=0;

// Buffers
double VolBuffer1[];  // value down
double VolBuffer2[];  // value up
double VolBuffer3[];  // moving average

//----
int ExtCountedBars=0;
int lastcolor=0;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   int    draw_begin;
   string short_name;

   // indicator buffers mapping, drawing settings and Shift

   // Histogram downArrow Red
   SetIndexBuffer(0,VolBuffer1);
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexShift(0,MA_Shift);

   // Histogram upArrow Green
   SetIndexBuffer(1,VolBuffer2);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexShift(1,MA_Shift);

   // Moving average line Red
   SetIndexBuffer(2,VolBuffer3);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexShift(2,MA_Shift);

   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));

   if(MA_Period<2) MA_Period=2;
   draw_begin=MA_Period-1;

   switch(MA_Mode)
     {
      case 1  : short_name="EMA(" ;  draw_begin=0; break;
      case 2  : short_name="SMMA(";                break;
      case 3  : short_name="LWMA(";                break;
      default : short_name="SMA(" ;  MA_Mode=0;
     }
   IndicatorShortName(short_name+MA_Period+")");

   SetIndexDrawBegin(0,draw_begin);

   return(0);
  }

//+------------------------------------------------------------------+
//| Main                                                             |
//+------------------------------------------------------------------+
int start()
  {

   if(Bars<=MA_Period) return(0);
   ExtCountedBars=IndicatorCounted();

// check for possible errors
   if (ExtCountedBars<0) return(-1);

// last counted bar will be recounted
   if (ExtCountedBars>0) ExtCountedBars--;

   switch(MA_Mode)
     {
      case 0 : sma();  break;
      case 1 : ema();  break;
      case 2 : smma(); break;
      case 3 : lwma();
     }
   return(0);
  }

//+------------------------------------------------------------------+
//| Simple Moving Average                                            |
//+------------------------------------------------------------------+
void sma()
  {
   double sum=0;
   int    i,pos=Bars-ExtCountedBars-1;

   // initial accumulation
   if(pos<MA_Period) pos=MA_Period;
   for(i=1;i<MA_Period;i++,pos--)
      sum+=Volume[pos];

   while(pos>=0)
     {
      sum+=Volume[pos];
      VolBuffer3[pos]=sum/MA_Period;
   sum-=Volume[pos+MA_Period-1];
   Vcolor(pos);
    pos--;
     }

   // zero initial bars
   if(ExtCountedBars<1)
      for(i=1;i<MA_Period;i++) VolBuffer1[Bars-i]=0;
  }

//+------------------------------------------------------------------+
//| Exponential Moving Average                                       |
//+------------------------------------------------------------------+
void ema()
  {
   double pr=2.0/(MA_Period+1);
   int    pos=Bars-2;

   if(ExtCountedBars>2) pos=Bars-ExtCountedBars-1;

   while(pos>=0)
     {
      if(pos==Bars-2) VolBuffer3[pos+1]=Volume[pos+1];
      VolBuffer3[pos]=Volume[pos]*pr+VolBuffer3[pos+1]*(1-pr);
      Vcolor(pos);
    pos--;
     }
  }

//+------------------------------------------------------------------+
//| Smoothed Moving Average                                          |
//+------------------------------------------------------------------+
void smma()
  {
   double sum=0;
   int    i,k,pos=Bars-ExtCountedBars+1;

   pos=Bars-MA_Period;
   if(pos>Bars-ExtCountedBars) pos=Bars-ExtCountedBars;
   while(pos>=0)
     {
      if(pos==Bars-MA_Period)
        {
         // initial accumulation
         for(i=0,k=pos;i<MA_Period;i++,k++)
           {
            sum+=Volume[k];
            // zero initial bars
            VolBuffer3[k]=0;
           }
        }
      else sum=VolBuffer3[pos+1]*(MA_Period-1)+Volume[pos];
      VolBuffer3[pos]=sum/MA_Period;
    pos--;
     }
  }

//+------------------------------------------------------------------+
//| Linear Weighted Moving Average                                   |
//+------------------------------------------------------------------+
void lwma()
  {
   double sum=0.0,lsum=0.0;
   double price;
   int    i,weight=0,pos=Bars-ExtCountedBars-1;
//---- initial accumulation
   if(pos<MA_Period) pos=MA_Period;
   for(i=1;i<=MA_Period;i++,pos--)
     {
      price=Volume[pos];
      sum+=price*i;
      lsum+=price;
      weight+=i;
     }
//---- main calculation loop
   pos++;
   i=pos+MA_Period;
   while(pos>=0)
     {
      VolBuffer3[pos]=sum/weight;
      if(pos==0) break;
      pos--;
      i--;
      price=Volume[pos];
      sum=sum-lsum+price*MA_Period;
      lsum-=Volume[i];
      lsum+=price;
     }
//---- zero initial bars
   if(ExtCountedBars<1)
      for(i=1;i<MA_Period;i++) VolBuffer3[Bars-i]=0;
  }

//+------------------------------------------------------------------+
//| Color depends on gain or loss and previous volume                |
//+------------------------------------------------------------------+
// 1 - histo down red
// 2 - histo up green
// 3 - line white

void Vcolor(int p)
  {

   if (Volume[p+1]>Volume[p])
     {
      VolBuffer1[p]=Volume[p];
      VolBuffer2[p]=0;
      lastcolor=Red;
     }

   if (Volume[p+1]<Volume[p])
     {
      VolBuffer1[p]=0;
      VolBuffer2[p]=Volume[p];
      lastcolor=Green;
     }

   if (Volume[p+1]==Volume[p])
     {
      if ( lastcolor==Red )
        {
         VolBuffer1[p]=Volume[p];
         VolBuffer2[p]=0;
        }
      if ( lastcolor==Green )
        {
         VolBuffer1[p]=0;
         VolBuffer2[p]=Volume[p];
        }
     }
  }

//+------------------------------------------------------------------+
 
prodi:

But i am using a custom Volume that has an ema displayed in a separate window, so i have to use icustome to use it in my EA . is there another way to do this?? using regular Volume??

Ah OK, yes use iCustom, are you passing all 3 Externs in the iCustom call ?
 
RaptorUK:
Ah OK, yes use iCustom, are you passing all 3 Externs in the iCustom call ?

Yes, but it doesnt seem to work, or get the previous histogram ema cross information
 
prodi:

Yes, but it doesnt seem to work, or get the previous histogram ema cross information
Can you show your EA code or at least your iCustom calls ?
 
  1. Indicator code:
    //|                            Volume with Custom Moving Average.mq4 |
    double VolBuffer1[];  // value down
    double VolBuffer2[];  // value up
    double VolBuffer3[];  // moving averag
    extern int MA_Period=13;
    extern int MA_Shift=0;
    extern int MA_Mode=0;
    What is the Exact file name of the indicator without the .mq4 extension?
    EA code:
    #define CMA_NAME "Custom Moving Average"
    #define CMA_DOWN 0
    #define CMA_UP   1
    #define CMA_AVE  2
    int MA_Period=13;
    int MA_Shift=0;
    int MA_Mode=0;
    double value = iCustom(NULL,0, CMA_NAME, MA_Period, MA_Shift, MA_Mode, CMA_AVE, 0);
    

  2. bear with me as i am not a coder
    learn to code or pay someone. We're not going to code it FOR you. We are willing to HELP you.
 

Here is the icustom call

     double GreenArrow=iCustom(NULL, 0, "MA Volumes",VMAPeriod,0,VMAMode,0,0);  
     double RedArrow=iCustom(NULL, 0, "MA Volumes",VMAPeriod,0,VMAMode,1,0);
     double VMA=iCustom(NULL, 0, "MA Volumes",VMAPeriod,0,VMAMode,2,0);

And parameters

extern int       VMAPeriod               = 32;
extern int       VMAMode                 = 1;

Yes i have paid quite well for crappy coding unfortunately i have no choice but to get help

 

here is the code

extern double    ExtraPips               = 5;
extern int       ForceIndexperiod        = 4;
extern double    FIndexBLevel            = 0.30000;
extern double    FIndexSLevel            = -0.30000;
extern int       VMAPeriod               = 32;
extern int       VMAMode                 = 1;
extern double    MACDtimeframe           = 60;
extern int       MACDfastema             = 1;
extern double    MACDslowema             = 4;
extern double    MACDsignalperiod        = 2;
extern int       MAperiod                = 16;
extern int       MAmode                  = 1;
extern string    ResName                 = "Buy";
extern string    SuppName                = "Sell";
extern string    UniName                 = "Uni";
extern double    Order1Lots              = 0.16;
extern double    Order2Lots              = 0.16;
extern double    Order1TakeProfit        = 10;
extern double    OrdersStopLoss          = 20;
extern double    MoveSLafterOrder1       = 0;
extern int       TrailStopBarsForOrder2  = 1;
extern int       StartTradeHour          = 0;
extern int       EndTradeHour            = 24;
extern int       MagicNumber             = 164783;
extern bool      UseEmails               = false;
 
bool cont;
int dig = 1, i, AllOrders, currPos = 0, orderTicket, cycle, TodayTrades=0, preClosed=0;
bool ThereIsOrder1, ThereIsOrder2, ThereIsPendingBuy, ThereIsPendingSell, ThereIsBuy, ThereIsSell;
 datetime prevDate,prevDateD;
double preBid, preAsk ;
//+------------------------------------------------------------------------------------------------------------------------------------+
//| expert initialization function                                                                                                     |
//+------------------------------------------------------------------------------------------------------------------------------------+
 
int init()
  {
   if( MarketInfo(Symbol(),MODE_DIGITS) == 3 || MarketInfo(Symbol(),MODE_DIGITS) == 5)
      dig = 10;
   currPos = 0;
   prevDate = Time[0];
   prevDateD = 0;
 
   preClosed = OrdersHistoryTotal();
    preBid = Bid;
   preAsk = Ask;
 
   return(0);
  }
//+------------------------------------------------------------------------------------------------------------------------------------+
//| expert deinitialization function                                                                                                   |
//+------------------------------------------------------------------------------------------------------------------------------------+
 int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------------------------------------------------------------------------+
//| expert start function                                                                                                              |
//+------------------------------------------------------------------------------------------------------------------------------------+
 int start()
  {
   bool NewBar = isNewBar();
 
     double MA = iMA(Symbol(), Period(), MAperiod, 0, MAmode, PRICE_CLOSE, 0);
     
     double FIndex = iForce(Symbol(), Period(), ForceIndexperiod, MAmode,PRICE_CLOSE,0);
      
     
     
     double MACDmain   = iMACD(Symbol(),MACDtimeframe,MACDfastema,MACDslowema,MACDsignalperiod,PRICE_CLOSE,MODE_MAIN,0);
     double MACDsignal = iMACD(Symbol(),MACDtimeframe,MACDfastema,MACDslowema,MACDsignalperiod,PRICE_CLOSE,MODE_SIGNAL,0);
   
     double GreenArrow=iCustom(NULL, 0, "MA Volumes",VMAPeriod,0,VMAMode,0,0);  
     double RedArrow=iCustom(NULL, 0, "MA Volumes",VMAPeriod,0,VMAMode,1,0);
     double VMA=iCustom(NULL, 0, "MA Volumes",VMAPeriod,0,VMAMode,2,0);
   
      if (preClosed < OrdersHistoryTotal())
      {
         OrderSelect(OrdersHistoryTotal() - 1, SELECT_BY_POS, MODE_HISTORY);
           if (OrderMagicNumber() == MagicNumber && OrderSymbol() == Symbol() )
            if (StringFind(OrderComment(), "[tp]", 0) >= 0 ) TodayTrades++;
      }
   
   if ( isNewBarDaily() ) TodayTrades = 0;
    
   AllOrders = 0;
 
   ThereIsOrder1 = false;
   ThereIsOrder2 = false;
   
   ThereIsBuy = false;
   ThereIsSell = false;
   
   for ( i = OrdersTotal()-1; i >= 0; i--)
      {
         OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
           AllOrders++;
         if (OrderMagicNumber() == MagicNumber && OrderSymbol() == Symbol())
         {
            if(OrderComment() == "Order 1") ThereIsOrder1 = true;
            if(OrderComment() == "Order 2") ThereIsOrder2 = true;
            if(OrderType() == OP_BUY)       ThereIsBuy    = true;
            if(OrderType() == OP_SELL)      ThereIsSell   = true;
         } 
         
   
   
      }
   for ( i = 0; i < OrdersTotal(); i++)
       {
         OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
         
          if(!ThereIsOrder1 && ThereIsOrder2)
         {
            if (OrderMagicNumber() == MagicNumber && OrderSymbol() == Symbol() && ((OrderType() == OP_BUY && OrderStopLoss() != OrderClosePrice() + MoveSLafterOrder1*Point*dig) || (OrderType() == OP_SELL && OrderStopLoss() != OrderClosePrice() - MoveSLafterOrder1*Point*dig)))
              {
               if (OrderType() == OP_BUY) OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() + MoveSLafterOrder1*Point*dig, OrderTakeProfit(), 0, NULL); 
               if (OrderType() == OP_SELL) OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() - MoveSLafterOrder1*Point*dig, OrderTakeProfit(), 0, NULL); 
            }
         }
         
         if(!ThereIsOrder1 && ThereIsOrder2 )
         {
            double LowestP = Low[iLowest(Symbol(),Period(),MODE_LOW,TrailStopBarsForOrder2,1)+1];
            double HighestP = High[iHighest(Symbol(),Period(),MODE_HIGH,TrailStopBarsForOrder2,1)+1];
              if (OrderComment() == "Order 2" && OrderMagicNumber() == MagicNumber && OrderSymbol() == Symbol() && OrderStopLoss() == 0)
               OrderModify(OrderTicket(), 0, OrderOpenPrice(), OrderTakeProfit(), 0, NULL);
              if (OrderComment() == "Order 2" && OrderMagicNumber() == MagicNumber && OrderSymbol() == Symbol() && ((OrderType() == OP_BUY && OrderStopLoss() < LowestP) || (OrderType() == OP_SELL && OrderStopLoss() > HighestP ) || OrderStopLoss() == 0))
              {
               if (OrderType() == OP_BUY) OrderModify(OrderTicket(), OrderOpenPrice(), LowestP, OrderTakeProfit(), 0, NULL); 
               if (OrderType() == OP_SELL) OrderModify(OrderTicket(), OrderOpenPrice(), HighestP, OrderTakeProfit(), 0, NULL); 
            }
         }
      }
  
  double Supp = 0;
  double Res  = 0;
  double Uni  = 0;
  
  for(i=0;i<ObjectsTotal();i++)
    {
 
     Supp = 0;
     Res  = 0;
     Uni  = 0;
    
     if(StringFind(ObjectDescription(ObjectName(i)), SuppName, 0) >= 0) Supp = ObjectGet(ObjectName(i), OBJPROP_PRICE1); 
     if(StringFind(ObjectDescription(ObjectName(i)), ResName,  0) >= 0) Res =  ObjectGet(ObjectName(i), OBJPROP_PRICE1);
     if(StringFind(ObjectDescription(ObjectName(i)), UniName,  0) >= 0) Uni =  ObjectGet(ObjectName(i), OBJPROP_PRICE1); 
      
      
      if((currPos <= 0 && !ThereIsBuy && Hour() >= StartTradeHour && Hour() < EndTradeHour && FIndex >= FIndexBLevel && MACDsignal >= 0 && MACDmain >= 0  && MACDsignal < MACDmain && Ask > MA && Res > MA && preAsk < Res && Ask >= Res && Open[0] < Res && Res > 0) 
      || (FIndex >= FIndexBLevel && MACDsignal >= 0 && MACDmain >= 0  && MACDsignal < MACDmain && Ask > MA && Res > MA && preAsk < Uni && Ask >= Uni && Open[0] < Uni && Uni > 0))
        {
         if((FIndex >= FIndexBLevel && MACDsignal >= 0 && MACDmain >= 0  && MACDsignal < MACDmain && Ask > MA && Res > MA && preAsk < Uni && Ask >= Uni && Open[0] < Uni && Uni > 0)) Res = Uni;
          CloseAll();
         Open_Buy(Res + ExtraPips*Point*dig, Res + Order1TakeProfit*Point*dig + ExtraPips*Point*dig, Res - OrdersStopLoss*Point*dig + ExtraPips*Point*dig,  Order1Lots, "Order 1");
         Open_Buy(Res + ExtraPips*Point*dig,0, Res - OrdersStopLoss*Point*dig + ExtraPips*Point*dig, Order2Lots, "Order 2");
          Comment("BUY   - " + NormalizeDouble(Ask, Digits));        
         currPos = 1;
      }  
      if((currPos >= 0 && !ThereIsSell && Hour() >= StartTradeHour && Hour() < EndTradeHour && FIndex <= FIndexSLevel && MACDsignal <= 0 && MACDmain <= 0 && MACDsignal > MACDmain && Bid < MA && Supp < MA && preBid > Supp && Bid <= Supp && Open[0] > Supp && Supp > 0) 
      || (FIndex <= FIndexSLevel && MACDsignal <= 0 && MACDmain <= 0 && MACDsignal > MACDmain && Bid < MA && Supp < MA && preBid > Uni && Bid <= Uni && Open[0] > Uni && Uni > 0)) 
        {
         if((FIndex <= FIndexSLevel && MACDsignal <= 0 && MACDmain <= 0 && MACDsignal > MACDmain && Bid < MA && Supp < MA && preBid > Uni && Bid <= Uni && Open[0] > Uni && Uni > 0)) Supp = Uni;
          CloseAll();
         Open_Sell(Supp - ExtraPips*Point*dig, Supp - Order1TakeProfit*Point*dig- ExtraPips*Point*dig, Supp + OrdersStopLoss*Point*dig - ExtraPips*Point*dig, Order1Lots, "Order 1");
         Open_Sell(Supp - ExtraPips*Point*dig,0, Supp + OrdersStopLoss*Point*dig- ExtraPips*Point*dig, Order2Lots, "Order 2");
          Comment("SELL   - " + NormalizeDouble(Bid, Digits));         
         currPos = -1;
 

Доброго времени суток уважаемые форумчане!

Меня зовут Герман, мне 23 года, я являюсь трейдером компании "Инстафорекс"

Помогите в поиске нужного скрипта! Скрипт нужен для сетки отложенных ордеров.