Capturing a lagging indicator - page 2

 

Wow little harsh reception. I am BOTHERING to learn code. Its how I learn I will play with existing code and see what the effects of my changes are. Its called experimenting and is used in daily life! I don't want you to code it for me. I'm asking specific advice but thought I would past the full code to get the bigger picture. I apologise for pissing on your chips!

 

Back to task. 

 

I have got this working for the buy. 

 

 bool FracUp=false;
   for(int i=0; i<5; i++)
     {
      if(iFractals(NULL,0,MODE_UPPER,i)>0)
        {
         FracUp=true;
         break;
        }
     }
   if(FracUp)
     {
      //do your thing
     }

 

How do you combine multiple logics? For example bool fracdown? I need it to break out in. In VB you would use "then" after the logic true.

 

bool FracUP=false;
bool FracDown=false;
     
     
    for( int current=0 ; Current <5; Current++)
     {
      if(ZIGZAGUP>0)
        {
         FracUP=true;
         break;
        }
      if (ZIGZAGDOWN >0
         Fracdown=true;
         break;

     }
   if((FracUP && CCI1 < -100)) // Here is your open buy rule

if ((FracDown && CCI1 > 100)) Enter a sell.
 
marine1983:

I understand an EA builder is not the way to go but at least it creates a basic code so I can manipulate it, just how I learn I suppose.

 

Its basically meant to open a buy if CCI is below -100 and  fractal appears. I thought it would be easy but its getting difficult very fast ha. 

It is a way to learn, but you need to start with something simpler.

To be able to modify code you have to be able to understand what the code is doing. 

 
bool FracUP=false;
bool FracDown=false;
     
     
    for( int current=0 ; Current <5; Current++)
     {
      if(ZIGZAGUP>0)
        {
         FracUP=true;
         break;
        }
      if (ZIGZAGDOWN >0
         Fracdown=true;
         break;

     }
   if((FracUP && CCI1 < -100)) // Here is your open buy rule

if ((FracDown && CCI1 > 100)) Enter a sell.

What are ZIGZAGUP and ZIGZAGDOWN?

Their values are not being changed in the loop, so they will stay the same value as they were before implementing the loop. 

 

Hi thanks for your reply. ZIGZAG is an Icustom indicator. Hence why I pasted the full code for the bigger picture.

 

double ZIGZAGUP = iCustom(NULL,0,"FractalZigZagNoRepaint",0, Current);
double ZIGZAGDown = iCustom(NULL,0,"FractalZigZagNoRepaint",1, Current);

 

What im trying to do is what i thought is easy. Basically the ZIGZAG indicator lags behind between 1 & 5 previous bars. I wanted to capture when it does this and make a trade from the signal.

The loop cycles through those previous 5 bars. If an arrow appears for example up. Im basically after a GOTO scenario if that exists in MQL4

 

Fracup = true  then execute the buy line command.

Fracdown = trued then execute the sell line command

 

the fractal appears on bar 3


so to have the signal without any repaint :

 

 if(  iFractals(NULL, 0, MODE_LOWER, 3) != 0.0 ) open_buy_order();


or

  if(  iFractals(NULL, 0, MODE_LOWER, 3) != EMPTY_VALUE ) open_buy_order();


It is needed to know the EMPTY VALUE, checking it into the code of the indicator


following what you want to do , here is the expert, it should open buy order  :



int start()
  { 
        static datetime time_0;if( time_0 == Time[0] ) return(0); time_0 = Time[0];


 int ticket = -1;
   if( iCCI(NULL, 0, 14, PRICE_CLOSE, 1) > 0 && iFractals(NULL, 0, MODE_LOWER, 3) != 0.0 )
     {
     ticket =-1;      
     ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"",MagicNumber,0,Blue);
     if( ticket > 0 ) Print("OEDER OPENED");
   }
                    
  
  //------
  return(0);
 }  
//+------------------------------------------------------------------+

 
 

Hi,

 

My last statement is the correct one. Buffer zero is the UP arrow. If it has a value > 0 FracUp = True it should check this upto 5 bars back I have pasted what at least compiles but i'm not sure if the logic is correct..

 

double ZIGZAGUP = iCustom(NULL,0,"FractalZigZagNoRepaint",0, Current);
double ZIGZAGDown = iCustom(NULL,0,"FractalZigZagNoRepaint",1, Current);

 

  for( int current=0 ; Current <5; Current++)
 {
      if(ZIGZAGUP>0)
        {
         FracUP=true; 
         
         
        result=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,0,"EA Generator www.ForexEAdvisor.com",MagicNumber,0,Blue);
        if(result>0)
        {TheStopLoss=0;
         TheTakeProfit=0;
         if(TakeProfit>0) TheTakeProfit=Ask-TakeProfit*MyPoint;
         if(StopLoss>0) TheStopLoss=Ask+StopLoss*MyPoint;
         OrderSelect(result,SELECT_BY_TICKET);
         OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
         }
        return(0);}
        
//////////////////// SELL Line ////////////////////////        
     if (ZIGZAGDOWN > 0)
     {
      FracDown= true;
      
      result=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,0,0,"EA Generator www.ForexEAdvisor.com",MagicNumber,0,Red);
        if(result>0)
        {
        TheStopLoss=0;
         TheTakeProfit=0;
         if(TakeProfit>0) TheTakeProfit=Bid+TakeProfit*MyPoint;
         if(StopLoss>0) TheStopLoss=Bid-StopLoss*MyPoint;
         OrderSelect(result,SELECT_BY_TICKET);
         OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
        }
        
        return(0);}
      
      
      
 

it work, it should be sell order instead of buy order,

 Now you get the base, ust develop it

extern int MagicNumber;
extern double Lots = 0.1;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
        static datetime time_0;if( time_0 == Time[0] ) return; time_0 = Time[0];


 int ticket = -1;
   if( iCCI(NULL, 0, 14, PRICE_CLOSE, 1) > 0 && iFractals(NULL, 0, MODE_LOWER, 3) != 0.0 )
     {
     ticket =-1;      
     ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"",MagicNumber,0,Blue);
     if( ticket > 0 ) Print("OEDER OPENED");
     }
                    
  
  //------
  return;
 }  
//+------------------------------------------------------------------+


 

look at this image to undeerstand better what the expert does :


https://www.mql5.com/en/charts/4181438/eurusd-h1-fxpro-financial-services

 
That is exactly what I was after. I think I have just got there myself. I dont need to know if its true I just need to know if it has a value within the last 5 bars. Really appreciate your help.
 

you welcome,

you have to get the signal on bar 3 with fractal