stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

Scalping New York
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=6189
Page 20 of 31
Author:  pivotter [ Fri Jun 03, 2022 8:19 pm ]
Post subject:  Scalping New York

biobier » Fri Jun 03, 2022 11:56 am wrote:I have this issue only on my slow (busy) development system. I think that is the reason why only some ppl have that issue. The others run a proper sized system :P

However there still is something more than the previous error... Created a test script (attached).
See this part of the output especially the time for CADCHF:

Code: Select all

0	13:42:09.307	GetBarDetails AUDUSD,M5: Details last bar for AUDUSD 15: Time=2022.06.03 14:15:00, Open=0.7243000000000001, High=0.72514, Low=0.7242499999999999, Close=0.72484, Volume=1047
0	13:42:09.320	GetBarDetails AUDUSD,M5: Details last bar for CADCHF 15: Time=2022.04.28 12:45:00, Open=0.75662, High=0.7571099999999999, Low=0.75621, Close=0.7569900000000001, Volume=1800
0	13:42:09.336	GetBarDetails AUDUSD,M5: CADCHF Got error (4066): requested history data is in update state Will etry
0	13:42:09.336	GetBarDetails AUDUSD,M5: Details last bar for CADCHF 15: Time=2022.04.28 12:45:00, Open=0.75662, High=0.7571099999999999, Low=0.75621, Close=0.7569900000000001, Volume=1800
0	13:42:09.336	GetBarDetails AUDUSD,M5: Details last bar for CADJPY 15: Time=2022.06.03 14:15:00, Open=103.481, High=103.534, Low=103.466, Close=103.514, Volume=1720
Time=2022.04.28 12:45:00 WTF? 14:15 is the right one. Running the script again that symbol get the right time. Feel free to play around with the script. But I think we are getting closer....

Thanks Biobier

I adapted the code to prevent the loading of open and close data from the wrong candle by checking for the timestamp:(on the assumption that if the right candle time is retrieved the data for iopen and iclose will be there as well)


double copen = 0;
double cclose = 0;
int k = 0;
GetLastError();//reset possible uncatched error
int err=GetLastError();
while ((closeEnough(copen, 0) ) && (k < 200) && (!IsStopped())){
if (TimeHour(iTime(symbol, 60, 1)) == (TimeHour(TimeCurrent())-1)){
copen = iOpen(symbol, tf, 1);
err=GetLastError();
if(err>0) Sleep(10);
}
if (k==100) {RefreshRates();}
k++; }

//-----------
k = 0;
GetLastError();//reset possible uncatched error
err=GetLastError();
while ((closeEnough(cclose, 0) ) && (k < 200) && (!IsStopped())){
if (TimeHour(iTime(symbol, 60, 1)) == (TimeHour(TimeCurrent())-1)){
cclose = iClose(symbol, tf, 1);
err=GetLastError();
if(err>0) Sleep(10);}
if (k==100) {RefreshRates();}
k++; }

direction = noney;//Default, and unlikely to happen but does sometimes

if ((!closeEnough(copen, 0) ) && (!closeEnough(cclose, 0) )){
if (cclose >= copen)
{
direction = longy;
return;
}//if (cclose > copen)

if (cclose <= copen)
{
direction = shorty;
return;
}//if (cclose > copen)
}//if ((!closeEnough(copen, 0) ) && (!closeEnough(cclose, 0) )){
Author:  biobier [ Fri Jun 03, 2022 8:28 pm ]
Post subject:  Scalping New York

SteveHopwood » Fri Jun 03, 2022 7:58 pm wrote:
biobier » Fri Jun 03, 2022 8:02 am wrote:Spotted that in function testForAlreadyTradedThisHour it is checked for all orders (not for our magicnumber only)

Code: Select all

      if (OrderMagicNumber() != MagicNumber) continue;
Need to be added.
The reason I did not bother with this in the first place is that Scalpy is a whole position basket trader. Only an idiot then tries other strategies at the same time.

Leaving out the magic number check is a protection measure for the dimwits - and a deliberate one.

:xm: :rocket:
Agree from that point BUT it is good to have for testing ;-) With that I could change the magic number and wait minutes to trigger scalpy to send trades again.
Author:  biobier [ Fri Jun 03, 2022 8:39 pm ]
Post subject:  Scalping New York

pivotter » Fri Jun 03, 2022 9:19 pm wrote:[

Thanks Biobier

I adapted the code to prevent the loading of open and close data from the wrong candle by checking for the timestamp:(on the assumption that if the right candle time is retrieved the data for iopen and iclose will be there as well)

Code: Select all

 double copen = 0;
   double cclose = 0;
   int k = 0;
   GetLastError();//reset possible uncatched error
   int err=GetLastError();
   while ((closeEnough(copen, 0) ) && (k < 200) && (!IsStopped())){
   if (TimeHour(iTime(symbol, 60, 1)) == (TimeHour(TimeCurrent())-1)){
      copen = iOpen(symbol, tf, 1);
      err=GetLastError();
      if(err>0) Sleep(10);
      }
      if (k==100)  {RefreshRates();} 
      k++;   }

    //-----------
    k = 0;
   GetLastError();//reset possible uncatched error
   err=GetLastError(); 
   while ((closeEnough(cclose, 0) ) && (k < 200) && (!IsStopped())){
   if (TimeHour(iTime(symbol, 60, 1)) == (TimeHour(TimeCurrent())-1)){
      cclose = iClose(symbol, tf, 1); 
      err=GetLastError();
      if(err>0) Sleep(10);}
      if (k==100)  {RefreshRates();}
      k++;  }

   direction = noney;//Default, and unlikely to happen but does sometimes
   
   if ((!closeEnough(copen, 0) ) && (!closeEnough(cclose, 0) )){
   if (cclose >= copen)
   {
      direction = longy;
      return;
   }//if (cclose > copen)
   
   if (cclose <= copen)
   {
      direction = shorty;
      return;
   }//if (cclose > copen)
   }//if ((!closeEnough(copen, 0) ) && (!closeEnough(cclose, 0) )){
With that only the hour is compared so it would not work if any other TF is set.
As I understand the documentation of RefreshRates(), it only refreshes the predefined arrays and variables like Ask, Bid, Time[] etc. So that will not help in this case. I also thought about to compare iTime with iTime for the symbol the EA is loaded on but that did not work for some reason (I assume the milliseconds or so differ always).
Author:  pivotter [ Fri Jun 03, 2022 8:46 pm ]
Post subject:  Scalping New York

yes, we can replace 60 with TradingTimeFrame, np, as for the Empty4 documentation it is from time to time not up to date and it only refreshes once after 100 attempts.
I tested one run and had no H1 wrong direction trades, but i also cheated as i added ForceLoadHistoricalData() to the top of sendBasket() to make sure all H! and H4 candles are updated before all symbols are scanned,

Next week i'll run a version without loadhistory to see if it works as well
Author:  SteveHopwood [ Fri Jun 03, 2022 9:11 pm ]
Post subject:  Scalping New York

biobier » Fri Jun 03, 2022 8:39 pm wrote:
pivotter » Fri Jun 03, 2022 9:19 pm wrote:[

Thanks Biobier

I adapted the code to prevent the loading of open and close data from the wrong candle by checking for the timestamp:(on the assumption that if the right candle time is retrieved the data for iopen and iclose will be there as well)

Code: Select all

 double copen = 0;
   double cclose = 0;
   int k = 0;
   GetLastError();//reset possible uncatched error
   int err=GetLastError();
   while ((closeEnough(copen, 0) ) && (k < 200) && (!IsStopped())){
   if (TimeHour(iTime(symbol, 60, 1)) == (TimeHour(TimeCurrent())-1)){
      copen = iOpen(symbol, tf, 1);
      err=GetLastError();
      if(err>0) Sleep(10);
      }
      if (k==100)  {RefreshRates();} 
      k++;   }

    //-----------
    k = 0;
   GetLastError();//reset possible uncatched error
   err=GetLastError(); 
   while ((closeEnough(cclose, 0) ) && (k < 200) && (!IsStopped())){
   if (TimeHour(iTime(symbol, 60, 1)) == (TimeHour(TimeCurrent())-1)){
      cclose = iClose(symbol, tf, 1); 
      err=GetLastError();
      if(err>0) Sleep(10);}
      if (k==100)  {RefreshRates();}
      k++;  }

   direction = noney;//Default, and unlikely to happen but does sometimes
   
   if ((!closeEnough(copen, 0) ) && (!closeEnough(cclose, 0) )){
   if (cclose >= copen)
   {
      direction = longy;
      return;
   }//if (cclose > copen)
   
   if (cclose <= copen)
   {
      direction = shorty;
      return;
   }//if (cclose > copen)
   }//if ((!closeEnough(copen, 0) ) && (!closeEnough(cclose, 0) )){
With that only the hour is compared so it would not work if any other TF is set.
As I understand the documentation of RefreshRates(), it only refreshes the predefined arrays and variables like Ask, Bid, Time[] etc. So that will not help in this case. I also thought about to compare iTime with iTime for the symbol the EA is loaded on but that did not work for some reason (I assume the milliseconds or so differ always).
I believe I mentioned this earlier.

Can we put RefreshRates() to bed please, folks. I know you are trying to help and we are all deeply grateful. Just forget RefreshRates() here. It does not help. Truly. Honestly. Cross my heart and hope my pupils have done some practise over the break. Forlorn hope, I know, but you never know.

:xm: :rocket:
Author:  SteveHopwood [ Fri Jun 03, 2022 9:16 pm ]
Post subject:  Scalping New York

Consider this folks:

Scalpy is doing rather well.

How about letting him do his thingy for a while instead of endlessly angsting about the stuff that is not quite right.

Spend your life trying to hunt down and correct empty4 insanities and you will go bonkers. Guess how I know. ;)

:xm: :rocket:
Author:  pivotter [ Fri Jun 03, 2022 10:00 pm ]
Post subject:  Scalping New York

REfreshrates() is in de bin and looking forward to a new week with Scalpy!
Author:  tomele [ Sat Jun 04, 2022 10:28 am ]
Post subject:  Scalping New York

If I may kindly join your conversation.
To get symbol data using functions for accessing timeseries and indicators, make sure that the symbol exists in the MarketWatch window. If the symbols is not available in Market watch, enable it using the SymbolSelect(symbol_name, true) function before you request the data.

The symbol can be hidden from MarketWatch after 10 minutes since the last access to the symbol history, i.e. since the call of functions like iOpen(), iHigh(), CopyTime() etc. This is due to the fact that the terminal stores symbol data for 10 minutes since the last access to them; after that unused data are automatically deleted from the terminal memory.
This is why some users have the problem while others don't - different Market watch lists. Thus multisymbol EAs should always have a SymbolSelect() loop over all needed symbols (at least) in OnInit().

Cheers
Author:  SteveHopwood [ Sat Jun 04, 2022 1:37 pm ]
Post subject:  Scalping New York

pivotter » Fri Jun 03, 2022 8:46 pm wrote:but i also cheated as i added ForceLoadHistoricalData() to the top of sendBasket() to make sure all H! and H4 candles are updated before all symbols are scanned,
That is a great idea. Can you post the code please, so I can add it?

:xm: :rocket:
Author:  SteveHopwood [ Sat Jun 04, 2022 1:57 pm ]
Post subject:  Scalping New York

tomele » Sat Jun 04, 2022 10:28 am wrote:If I may kindly join your conversation.

This is why some users have the problem while others don't - different Market watch lists. Thus multisymbol EAs should always have a SymbolSelect() loop over all needed symbols (at least) in OnInit().

Cheers
Thanks Thomas

mql4 documentation mostly confuses me. My limited understanding is that SymbolSelect() returns 'false' if the symbol is not offered by the broker and so cannot be placed in the Watch window.

I have added this to void sendBasket(), just above the getDirection() command:

Code: Select all

      //Ensure the symbol is in the market watch window
      bool symbolExists = SymbolSelect(symbol, true);
      if (!symbolExists)
         continue;
Correct?

:xm: :rocket:
All times are UTC Page 20 of 31