Activate pending order when the bar close under him. - page 3

 

I make this and results haven't changed and also i try with this

datetime LastBar;
 
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
  
   if(LastBar!=Time[0]){
     
      Alert("here ",Time[0]);
      
      LastBar=Time[0];
   }

And The strategy tester send me alert every one hour (if I put this timeframe)

this is my code

 
domdix27:

I make this and results haven't changed and also i try with this

And The strategy tester send me alert every one hour (if I put this timeframe)

this is my code

Did I not just give you a perfectly good explanation and even supplied you with example code?

Why did you not try it (or at least show an attempt even if it produced errors, so we could analyse it and take it to then next step)?

Why then, have you decided to instead try something completely different that was not even discussed, and for which you did not even think logically about what the consequence could be?

Well, if you wish to ignore the information from someone more experience and knowledgeable in this matter, that is completely up to you, but if it fails to meet expectations, then you have only yourself to blame!

 
Fernando Carreiro:

Did I not just give you a perfectly good explanation and even supplied you with example code?

Why did you not try it (or at least show an attempt even if it produced errors, so we could analyse it and take it to then next step)?

Why then, have you decided to instead try something completely different that was not even discussed, and for which you did not even think logically about what the consequence could be?

Well, if you wish to ignore the information from someone more experience and knowledgeable in this matter, that is completely up to you, but if it fails to meet expectations, then you have only yourself to blame!



I would never let you doubt her I just searched the problem and I found this other solution and I tried to apply it I apologize.

Now obviously I tried your code and nothing is changed the strategy tester doesnt give me error and the allert repeat every millisecond.

Sorry if i was rude.Oh i m sorry i just noticed I havent send you my code I have only write this is my code sorry for this.

Now this is the code:

#include <stderror.mqh>
#include <stdlib.mqh>
#define PivotPoint "PivotPoint"

#define  PivotPoint_P 0
extern int x = 1;



int OnInit()
  {

//----
   return(0);
   return(INIT_SUCCEEDED);
  }


void OnTick ()
 
  {
  //int Spread=(Ask-Bid);

static bool AlertDP=true;

 double DailyPivot = iCustom(_Symbol,PERIOD_CURRENT,"PivotPoint",x,PivotPoint_P,0);


if(Bid+1*Point >= DailyPivot  ){
if(AlertDP=true){

   Alert("here");
  //int ticket = OrderSend(Symbol(),OP_BUY,0.10,Ask,3,Bid-30*Point+Spread,Bid+30*Point+Spread,"Buy Order",0,0,Blue);
  AlertDP=false;
   
  }
else 
AlertDP=true;
}
  
 /*if (Bid-1*Point <= DailyPivot)

{
//if (DP=true){

 Alert("here");
//int ticket = OrderSend(Symbol(),OP_SELL,0.10,Bid,3,(Ask+30*Point)+Spread,Ask-30*Point +Spread,"Buy Order",0,0,Blue);
//DP=false;
}
  */
  
  
 
 
  }
 
domdix27: I would never let you doubt her I just searched the problem and I found this other solution and I tried to apply it I apologize.

Now obviously I tried your code and nothing is changed the strategy tester doesnt give me error and the allert repeat every millisecond.

Sorry if i was rude.Oh i m sorry i just noticed I havent send you my code I have only write this is my code sorry for this.

Now this is the code:

That is because you did it incorrectly a placed the "else" in the wrong place.

You must learn to "style", indent and space your code properly to prevent such mistakes and to allow the code to be readable. Obviously, you can use your own "style", not necessarily mine, but it should be easy to read and be indented to show the levels and blocks of code.

EDIT: Please remember NOT to share the same Alert flag for both Buy and Sell conditions. Use a BuyAlertFlag and a SellAlertFlag! For this reason, I revised the code in my original post

#include <stderror.mqh>
#include <stdlib.mqh>

#define PivotPoint "PivotPoint"
#define PivotPoint_P 0

extern int x = 1;

int OnInit()
{
   return(INIT_SUCCEEDED);
}

void OnTick ()
{
   static bool
      AlertBuyDP  = true,
      AlertSellDP = true;
   double
      Offset      = 1 * _Point,
      BuyLevel    = Bid + Offset,
      SellLevel   = Bid - Offset,
      DailyPivot  = iCustom( _Symbol, PERIOD_CURRENT, "PivotPoint", x, PivotPoint_P, 0 );

   if( BuyLevel > DailyPivot  )
   {
      if( AlertBuyDP )
      {
         Alert( "Buy here" );
         AlertBuyDP = false;
      }
   }
   else 
      AlertBuyDP = true;

   if( SellLevel < DailyPivot )
   {
      if( AlertSellDP )
      {
         Alert( "Sell here" );
         AlertSellDP = false;
      }
   }
   else 
      AlertSellDP = true;
}
 
Your code.
 if( BuyLevel > DailyPivot  )
   {
      if( AlertBuyDP )
      {
         Alert( "Buy here" );
         AlertBuyDP = false;
      }
   }
   else 
      AlertBuyDP = true;
Alternative, look for a change in condition.
static bool AlertBuyDP     = false;
bool        AlertBuyDPprev = AlertBuyDP;
AlertBuyDP = BuyLevel > DailyPivot;
if(AlertBuyDP && !AlertBuyDPprev)
   {
         Alert( "Buy here" );
   }
 
Fernando Carreiro:

That is because you did it incorrectly a placed the "else" in the wrong place.

You must learn to "style", indent and space your code properly to prevent such mistakes and to allow the code to be readable. Obviously, you can use your own "style", not necessarily mine, but it should be easy to read and be indented to show the levels and blocks of code.

EDIT: Please remember NOT to share the same Alert flag for both Buy and Sell conditions. Use a BuyAlertFlag and a SellAlertFlag! For this reason, I revised the code in my original post


thank you so much now it work 

Reason: