How to get/store specific candle info?

Back to topics list To post a new topic, please log in or register
avatar
40
EgyAlgoTrader 2015.07.11 17:57
 

Hi, i have a question regarding getting/storing the candle info on which a specific event happened. 

 let me explain, suppose i am looking for the candle that has the following condition:

Low > EMA(2) && Low > EMA(10) 

then, i would like to store the HIGH  value data of this specific candle (say 1.5000) for later on calculation.

with getting newer candles, i still need to keep this value not changed. How could i do this?

Should i fetch backward with every new candle formation to get this information everytime candle forms. Or how?

Thanks 

 

avatar
13008
WHRoeder 2015.07.11 21:48 #
 
You do it exactly what you said
static double saveHigh;
if( Low[...] > MathMax( EMA(2), EMA(10) )) saveHigh = High[...];

avatar
40
EgyAlgoTrader 2015.07.11 23:21 #
 

Thank you so much. However, what if another true event occurred later, would this update this "static double saveHigh" with the new value?

I will include your code and see 

avatar
40
EgyAlgoTrader 2015.07.12 00:07 #
 

I am trying to check for  a change in the signal as you taught me before not a signal itself. So, if before was no signal but now ---> true signal. 

Others  ( true->true) or (true ->false), will be false signal. Then i capture this Low or High value in a static variable.  

I will be able to do that, this would be awesome. This concept with work for me with many other situations.

 

I will update here.

Thx 

avatar
40
EgyAlgoTrader 2015.07.12 19:08 #
 

Unfortunately, i still can not comprehend or able to code the code correct

 

and here is all the code:

//+------------------------------------------------------------------+
//|                                                     EgyQuant.mq4 |
//|                        Copyright 2015, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

//+------------------------------------------------------------------+
//| External Variables                                               |
//+------------------------------------------------------------------+
extern double LotSize = 0.01;
extern double StopLoss = 50;
extern double TakeProfit = 100;
extern int Slippage = 5;
extern int MagicNumberBuy = 123;
extern int MagicNumberSell = 321;
extern int ma1 = 2;
extern int ma2 = 5;
extern int ma3 = 10;
extern int ma4 = 15;
extern int ma5 = 30;
extern int ma6 = 50;
extern int ma7 = 100;

//+------------------------------------------------------------------+
//| Global Variables                                                 |
//+------------------------------------------------------------------+
int BuyTicket;
int SellTicket;
double UsePoint;
int UseSlippage;
double newSignal;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
     UsePoint    = PipPoint(Symbol());
     UseSlippage = GetSlippage(Symbol(),Slippage);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
    //set up moving averages
    double maf1 = iMA(NULL,0,ma1,0,MODE_EMA,PRICE_CLOSE,0);
    double maf2 = iMA(NULL,0,ma2,0,MODE_EMA,PRICE_CLOSE,0);
    double maf4 = iMA(NULL,0,ma4,0,MODE_EMA,PRICE_CLOSE,0);
    double maf5 = iMA(NULL,0,ma5,0,MODE_EMA,PRICE_CLOSE,0);
    double maf6 = iMA(NULL,0,ma6,0,MODE_EMA,PRICE_CLOSE,0);
    double maf7 = iMA(NULL,0,ma7,0,MODE_EMA,PRICE_CLOSE,0);
    
    static  double currentSignal = 0.0;// What i want is to store the first signal price 
    double previousSignal = currentSignal;
    currentSignal = StartSignalPrice ();//
   
    if (currentSignal != previousSignal )// I know there is something wrong here but i can not comprehend
    newSignal = currentSignal;
    
    Print ( newSignal );
    
    Comment ( "  start signal =  " + (string) newSignal);// Also, is this Typecasting correct to get rid of the warning?
               
   
  }
//+------------------------------------------------------------------+
//| User Defined functions                                           |
//+------------------------------------------------------------------+

// Pip Point Function
double PipPoint(string Currency)
{
double CalcPoint;
int CalcDigits = (int) MarketInfo(Currency,MODE_DIGITS);
if(CalcDigits == 2 || CalcDigits == 3)  CalcPoint = 0.01;
else if(CalcDigits == 4 || CalcDigits == 5) CalcPoint = 0.0001;
return(CalcPoint);
}

// Get Slippage Function

int GetSlippage(string Currency, int SlippagePips)
{
int CalcSlippage;
int CalcDigits = (int) MarketInfo(Currency,MODE_DIGITS);// notice this typecasting method (int)
if(CalcDigits == 2 || CalcDigits == 4)  CalcSlippage = SlippagePips;
else if(CalcDigits == 3 || CalcDigits == 5) CalcSlippage = SlippagePips * 10;
return(CalcSlippage);
}

// UDF normalize double

double NormMe (string ins, double price)
{
  int dig = (int) SymbolInfoInteger (ins, SYMBOL_DIGITS);
  return (NormalizeDouble (price, dig));
}

//Check for a start signal 

double StartSignalPrice ()// later on, i will try to pass strings such as  buy/sell parameters to get relevant price for each cycle
{  
   
   double maf1 = iMA(NULL,0,ma1,0,MODE_EMA,PRICE_CLOSE,0);
   double maf2 = iMA(NULL,0,ma2,0,MODE_EMA,PRICE_CLOSE,0);
   double maf3 = iMA(NULL,0,ma3,0,MODE_EMA,PRICE_CLOSE,0);
   
   double startSignalPrice;

         if ( iHigh("",0,1) > maf1 && maf1 > maf2 && maf2 > maf3 )// when previous candle High is higher than all 3 first MAs, i get the low price of previous candle
         {
          
         startSignalPrice = Low[1];
         return (startSignalPrice);// return the low price
         
         }

         else if ( iLow("",0,1) < maf1 && maf1 < maf2 && maf2 < maf3 )// if previoius candle low is lower than all 3, i get previous high candle
          {
          startSignalPrice = High[1];
          return (startSignalPrice);
          }
         
         else 
         return (0.0);// This else to delete warning. However, i am not sure if this whole if statememts are doing what i need
      
}

 I feel i am close but still not correct

avatar
13008
WHRoeder 2015.07.12 20:03 #
 
if ( iHigh("",0,1)
  1. "" is not a valid pair. iHigh - MQL4 Documentation
  2. Why use a function call when you can use the predefined variables?
  3. Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it. It's use is always wrong
Back to topics list  

To add comments, please log in or register