How to stop printing or trading

 
Hi

For any MACD crosses, or EMA crosses or candle patterns is seems that my print statements print continuously.

I understand that the condition is true and continues to be true for each tick, and many of my strategies are position trades and thus I don't need ticks but more of closed bars etc.

How do you print or trade only once the condition is true and only once ?

For example see this code I'm working on now

int i=0;
   int ticket,total,result;
   total = OrdersTotal();                 
   val1=iFractals(NULL, 0, MODE_UPPER,3);
   val2=iFractals(NULL, 0, MODE_LOWER,3); 
   double   faster = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,3), //MODE_MAIN
            slower = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,3); //MODE_SIGNAL


     
     if(val1 > 0 && faster > slower) 
     //Print(iFractals(NULL, 0, MODE_UPPER,3));
     double B = val1;
     if(B!=0)
     Print(B, " B upper"); //this prints all the time (might just print val1) need to revise but no matter)
     
     if(val2 > 0 && faster < slower)
     B = iFractals(NULL, 0, MODE_LOWER, 3);
     //Print(B, " B lower");


Please advise

Thanks

 

Hi, my name is <-^>RunnerUp. ;)


Firstly, it seems like you want to submit a SINGLE order at a SPECIFIC signal. Correct? (personally, I would advise you to prioritize your "ORDER SIGNALS" before working on "PRINTING" a string.

Once you figure out your trading strategy, THEN worry about all the "bells and whistles" ;) ("bells and whistles" = "PRINTING" a string.) "The only way I can get shit done is to do one thing at a time... ;)


I have *two* questions for you...

1. What indicators do you wish to use for a trading signal?

2. What indicator parameters do you wish for your "ea" to submit a trading signal?


I want you to answer my questions. After solving your "Order Signals", then you "could" work on the printing issues.

Hope I have been useful ;)


<-^>RunnerUp out bitch3s ;)
 

All you do is have a bool variable on the global scope i.e. I did notice that you hadn't put in any { } for your if's so it was running the if and not finding anything. I could be wrong but I use them just to be on the safe side and only don't include then when everything is on one line.

bool traded=false;

int start()
{
int i=0;
   int ticket,total,result;
   total = OrdersTotal();                 
   val1=iFractals(NULL, 0, MODE_UPPER,3);
   val2=iFractals(NULL, 0, MODE_LOWER,3); 
   double   faster = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,3), //MODE_MAIN
            slower = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,3); //MODE_SIGNAL


     
     if(val1 > 0 && faster > slower&&traded==false) 
 {
     //Print(iFractals(NULL, 0, MODE_UPPER,3));
     double B = val1;
     if(B!=0)
     Print(B, " B upper"); //this should only trade once
     traded=true;
 }else if(val1 > 0 && faster > slower){
   / This is here in case you want to run the trade again or close positions just set traded = false;
if(/* Some checks */)traded=false;
 }    
     if(val2 > 0 && faster < slower&&traded==false)
 {
     B = iFractals(NULL, 0, MODE_LOWER, 3);
     //Print(B, " B lower");
     traded=true;
 }else if(val1 > 0 && faster < slower){
   // This is here in case you want to run the trade again or close positions just set traded = false;
if(/* Some checks */)traded=false;
 }

}
 
WhooDoo22:

Hi, my name is <-^>RunnerUp. ;)


Firstly, it seems like you want to submit a SINGLE order at a SPECIFIC signal. Correct? (personally, I would advise you to prioritize your "ORDER SIGNALS" before working on "PRINTING" a string.

Once you figure out your trading strategy, THEN worry about all the "bells and whistles" ;) ("bells and whistles" = "PRINTING" a string.) "The only way I can get shit done is to do one thing at a time... ;)


I have *two* questions for you...

1. What indicators do you wish to use for a trading signal?

2. What indicator parameters do you wish for your "ea" to submit a trading signal?


I want you to answer my questions. After solving your "Order Signals", then you "could" work on the printing issues.

Hope I have been useful ;)


<-^>RunnerUp out bitch3s ;)
Thanks,

I have so many strategies to test, but I am new to MQL so I have to learn to code first
Which is why I was printing instead of just putting all the send order entries in so I can understand first what it's doing.

As far as the indicators go it can be anything but I always seem to run into this same topic of either multiple print statements and/or continuous order entries and I never knew exactly why or if there was some typical method to pause things while the condition is true. So that it's not true,true,true,print,print,print or worse Bid,Bid,Bid etc.
I think I'm starting to understand this now a little more
 
heelflip43:

All you do is have a bool variable on the global scope i.e. I did notice that you hadn't put in any { } for your if's so it was running the if and not finding anything. I could be wrong but I use them just to be on the safe side and only don't include then when everything is on one line.


Ah this makes sense to me now a little better.
I'm Noob and have not used bool extensively yet although I have written a few EA's so far on my own.

So this I think I can understand what you did and made some edits to my code

Here is the changes which is not exactly like your code but your code but your code definately helped me think things through a bit.
I really need to experiment with bool a bit more I think this is where I'm missing most of my understanding on my code problems


//+------------------------------------------------------------------+
//|                                                  Agent86_5min.mq4 |
//|                                                    Unfinished POS |
//|                                    
//+------------------------------------------------------------------+
#property copyright "Unfinished POS by Agent86"


//---- input parameters
extern double    TakeProfit=20.0;
extern double    Lots=0.1;
extern double    StopLoss=10.0;
extern int MagicNumber=123486;

double val1;
double val2;


//++++ These are adjusted for 5 digit brokers.

int     pips2points;    // slippage  3 pips    3=points    30=points
double  pips2dbl;       // Stoploss 15 pips    0.0015      0.00150
int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)

    // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
   if (Digits == 5 || Digits == 3)
   {    // Adjust for five (5) digit brokers.
      pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
   } 
   else 
    {    
      pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; 
    }
    // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
     
   
    
//---- 

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   return(0);
  }
  bool traded = false; 
    
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
   
        
   int i=0;
   int ticket,total,result;
   total = OrdersTotal();                 
   val1=iFractals(NULL, 0, MODE_UPPER,3);
   val2=iFractals(NULL, 0, MODE_LOWER,3); 
   double   faster = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,3), //MODE_MAIN
            slower = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,3); //MODE_SIGNAL


     
     if(val1 > 0 && faster > slower && traded == false)
     { 
     //Print(iFractals(NULL, 0, MODE_UPPER,3));
     double B = val1;
     Print(B, " B upper");
     traded=true;
     }
     
     if(val2 > 0 && faster < slower && traded == true)
     {
     B = val2;
     Print(B, " B lower");
     traded=false;
     }
                         
                
   return(0);
  }    

//+------------------------------------------------------------------+


What do you think of this solution ?

And thanks again this was a great help

Check the results here:

2011.10.20 20:07:52 2011.01.10 04:35 Unfinished_POS EURUSD,M5: 1.2888 B lower
2011.10.20 20:07:52 2011.01.10 03:30 Unfinished_POS EURUSD,M5: 1.2924 B upper
2011.10.20 20:07:52 2011.01.10 02:55 Unfinished_POS EURUSD,M5: 1.2876 B lower
2011.10.20 20:07:52 2011.01.10 01:35 Unfinished_POS EURUSD,M5: 1.291 B upper
2011.10.20 20:07:52 2011.01.10 01:15 Unfinished_POS EURUSD,M5: 1.2892 B lower
2011.10.20 20:07:52 2011.01.09 23:55 Unfinished_POS EURUSD,M5: 1.291 B upper
2011.10.20 20:07:52 2011.01.09 22:20 Unfinished_POS EURUSD,M5: 1.291 B lower
2011.10.20 20:07:51 2011.01.09 19:50 Unfinished_POS EURUSD,M5: 1.2905 B upper
2011.10.20 20:07:51 2011.01.09 19:05 Unfinished_POS EURUSD,M5: 1.2888 B lower
2011.10.20 20:07:51 2011.01.09 18:55 Unfinished_POS EURUSD,M5: 1.2905 B upper
2011.10.20 20:07:51 2011.01.09 18:15 Unfinished_POS EURUSD,M5: 1.2895 B lower
2011.10.20 20:07:51 2011.01.09 18:00 Unfinished_POS EURUSD,M5: 1.2917 B upper
2011.10.20 20:07:51 2011.01.07 15:30 Unfinished_POS EURUSD,M5: 1.2925 B lower


But I did notice that on some of the fractals that you see the arrow on the chart and you see the fractal time, the print statement sometimes prints at a time much later then the ifractal arrow and value.

For example:

2011.10.20 20:07:52 2011.01.10 03:30 Unfinished_POS EURUSD,M5: 1.2924 B upper

The actual arrow and fractal was at 3:15 and yet the value was correct.

So now the question will be if I were to OrderSend at this point of the code when will it actually take a trade ?
at 3:30 or 3:15 where the arrow is.

If I need it to trade at 3:15 this will be a problem placing a trade 15min late LOL

Anyhow what do you think

And thanks again everyone for the help this is good learning progress for me.


 
The reason for that is that is when using the fractals function the last number is the bar shift. iFractals(NULL, 0, MODE_UPPER,3) so in your case it is looking 3 bars behind (current bar is 0) and since your on a 5 min chart that would mean a 15 minute delay. I'm relatively new to fractals but am looking to use them more in the future and from what I understand, the minimum for a fractal to happen is a 2 bar shift i.e. the fractal bar then the confirmation bar then the new bar. So I'd use them as a confirmation rather than a main indicator.
 
Latest trials

This is going to be a sort of ABCD scheme with the ability to select different indicators but for now I'm playing with MACD for learning.

Anyhow here is the currently non-working code

//+------------------------------------------------------------------+
//|                                                  Agent86_5min.mq4 |
//|                                                    Unfinished POS |
//|                                    
//+------------------------------------------------------------------+
#property copyright "Unfinished POS by Agent86"


//---- input parameters
extern double    TakeProfit=20.0;
extern double    Lots=0.1;
extern double    StopLoss=10.0;
extern int MagicNumber=123486;

double val1;
double val2;


//++++ These are adjusted for 5 digit brokers.

int     pips2points;    // slippage  3 pips    3=points    30=points
double  pips2dbl;       // Stoploss 15 pips    0.0015      0.00150
int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)

    // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
   if (Digits == 5 || Digits == 3)
   {    // Adjust for five (5) digit brokers.
      pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
   } 
   else 
    {    
      pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; 
    }
    // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
     
   
    
//---- 

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   return(0);
  }
  bool traded = false; 
    
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
   
        
   int i=0;
   int ticket,total,result;
   total = OrdersTotal();                 
   val1=iFractals(NULL, 0, MODE_UPPER,3);
   val2=iFractals(NULL, 0, MODE_LOWER,3); 
   double   faster = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,3), //MODE_MAIN
            slower = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,3); //MODE_SIGNAL


     
     if(val1 > 0 && faster > slower && traded == false)
      { 
      //Print(iFractals(NULL, 0, MODE_UPPER,3));
      double B = val1;
      Print(B, " B upper");
      traded=true;
      }
     
     if(val2 > 0 && faster < slower && traded == true)
      {
      B = val2;
      Print(B, " B lower");
      traded=false;
      }
     
     if(B == val1)
      {
      double A = val2; //but this will be empty value atm so this won't work
      Print (A, " A = val2 = Low A");
      }
     if(B == val2)
      {
      A = val1; //but now this will be empty value atm so this won't work either
      //back to the drawing board
      Print (A, "A = val1 = High A");
      }
                        
                
   return(0);
  }    

//+------------------------------------------------------------------+


Anyhow you can see what I was trying to do here but I can't seem to think it through.

read the notes explains what's not working

Please advise

Thanks all



 
heelflip43:
The reason for that is that is when using the fractals function the last number is the bar shift. iFractals(NULL, 0, MODE_UPPER,3) so in your case it is looking 3 bars behind (current bar is 0) and since your on a 5 min chart that would mean a 15 minute delay. I'm relatively new to fractals but am looking to use them more in the future and from what I understand, the minimum for a fractal to happen is a 2 bar shift i.e. the fractal bar then the confirmation bar then the new bar. So I'd use them as a confirmation rather than a main indicator.

Ahh makes sense, thanks

For some reason I was thinking that that for a fractal to really be confirmed it should be a shift of 3 since the fractal is 2 closed candles to the right and thus Bar[0] is fluctuating so if you only have a shift of 2, then you have the fractal which is 3, then bars 2 and 1 to the right, and the Bar 0 which is in flux

I mean to say that Bar 0 becomes Bar1 as soon as it closes so Bar1+Bar2 and Bar3 is the indicator.

Maybe I don't understand it well enough, but that is how I was thinking about it.
I would like to know more about this and what is the real fractal confirmed minimum

Thanks
Reason: