Why doesn't this EA only print changing Bids?

To add comments, please log in or register
nadiawicket
965
nadiawicket  
//+------------------------------------------------------------------+
//|                                                       Change.mq4 |
//|                        Copyright 2019, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

double BidPrevious;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---

   if(Bid!=BidPrevious)
      Print(Bid);

   BidPrevious=Bid;

   RefreshRates(); // WHY DOESNT IT ONLY PRINT OUT CHANGING BIDS?


  }
//+------------------------------------------------------------------+

Need it to only print CHANGING BIDS; *NOT the same Bid TWICE IN A ROW*.

Tried everything from Symbol() to _Symbol to DoubleToString using BidCurrent and a couple of more variables, arrays, using || to compare to > or <, can't figure this simple thing out. It keeps printing same Bids 2 times in a row no matter what.

Any ideas? THX

Keith Watford
Moderator
18548
Keith Watford  
Do you have it running on 2 charts with the same symbol?
nadiawicket
965
nadiawicket  
Keith Watford:
Do you have it running on 2 charts with the same symbol?

Its on the strategy tester on EURUSD only

iRick
227
iRick  
nadiawicket:

Its on the strategy tester on EURUSD only

Try: Print(DoubleToString(Bid));

nadiawicket
965
nadiawicket  
iRick:

Try: Print(DoubleToString(Bid));

Had already tried this approach to no avail
Amir Yacoby
1363
Amir Yacoby  
nadiawicket:
Had already tried this approach to no avail

look for how to compare double types

Ernst Van Der Merwe
6486
Ernst Van Der Merwe  
   if(MathAbs(Bid-BidPrevious)>=_Point)
      Print(Bid);
nadiawicket
965
nadiawicket  
Amir Yacoby:

look for how to compare double types

Many ways; what would your approach be?
nadiawicket
965
nadiawicket  
Ernst Van Der Merwe:

Still repeats the same Bid 2 times in a row sometimes. .

Thought you had it !!

Amir Yacoby
1363
Amir Yacoby  
nadiawicket:
Many ways; what would your approach be?
Not many.
if(NormalizeDouble(Bid-BidPrevious,8)!=0)
  {
     Print(Bid);
     BidPrevious=Bid;  // only when printed
   }
* actually with _Point as suggested by Ernst might be more correct but still need to assign BidPrevious only when printed
nadiawicket
965
nadiawicket  
Amir Yacoby:
Not many.
if(NormalizeDouble(Bid-BidPrevious,8)!=0)
  {
     Print(Bid);
     BidPrevious=Bid;  // only when printed
   }

AWESOME!!!!! That works!!!

Its all just 0 after Digits; why use 8? Working without it, but I'd like to know why you prefer 8? Much appreciated!!

12
To add comments, please log in or register