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

Help with coding, orders history total
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=5861
Page 1 of 1
Author:  LittleCaro [ Thu Jun 11, 2020 8:51 am ]
Post subject:  Help with coding, orders history total

Hello guys,

I'm trying to filter the trades with the history, so a buy follows a sell, and it works good.

But, in the morning when there is no trades, i don't know how to say there's no trades (so the expert could fire a buy or a sell), and i need filtering by magic number.

Here is the code i use to find if the previous trade was a buy or a sell (it's working) :

Code: Select all

bool Isprevioustradelong ()
{
 
  if (OrdersHistoryTotal() == 0) return(false);
   
   for (int cc = OrdersHistoryTotal() - 1; cc >= 0; cc--)
   {
      if (!OrderSelect(cc, SELECT_BY_POS, MODE_HISTORY) ) continue;
      if (OrderMagicNumber() != MagicNumber) continue;
      if (OrderSymbol() != Symbol() ) continue;
      if (OrderType() == OP_BUY) return(true);
      
 
//Got this far, so the order was a buy
return(false);
 }// bool Isprevioustradelong ()
}//for (int cc = OrdersHistoryTotal() - 1; cc >= 0; cc--)



bool Isprevioustradeshort ()
{
 
if (OrdersHistoryTotal() == 0) return(false);
   
   for (int cc = OrdersHistoryTotal() - 1; cc >= 0; cc--)
   {
      if (!OrderSelect(cc, SELECT_BY_POS, MODE_HISTORY) ) continue;
      if (OrderMagicNumber() != MagicNumber) continue;
      if (OrderSymbol() != Symbol() ) continue;
      if (OrderType() == OP_SELL) return(true);
      
 
//Got this far, so the order was  a sell
return(false);
 }// bool Isprevioustradeshort ()
}// for (int cc = OrdersHistoryTotal() - 1; cc >= 0; cc--)  
  
Now i used the same protocol, but i don't know how to say there was no trades, i tried with OrdersTotal but not working:

Code: Select all

bool Isthehistoryclear()
{
 
  
   for (int cc = OrdersHistoryTotal() - 1; cc >= 0; cc--)
   {
      if (!OrderSelect(cc, SELECT_BY_POS, MODE_HISTORY) ) continue;
      if (OrderMagicNumber() != MagicNumber) continue;
      if (OrderSymbol() != Symbol() ) continue;
      if (OrdersTotal() == 0 I'M LOST HERE PLEASE HELP ) return (true);   
      
 
//Got this far, so the history is clear
return(false);
 }// bool Isthehistoryclear ()
}//for (int cc = OrdersHistoryTotal() - 1; cc >= 0; cc--)

Any help, will be greatly appreciated, thanks guys !
Author:  SteveHopwood [ Thu Jun 11, 2020 4:19 pm ]
Post subject:  Help with coding, orders history total

I am not sure you have your true and false in the correct order. I am assuming that your call to the function is:
if (Isthehistoryclear() )
DoSomething;

If not and your call is
if (Isthehistoryclear() = false) then reverse my changes.

You had a couple of lines of code in the wrong place

Code: Select all

bool Isthehistoryclear()
{
 
   //Extra test
   if(OrdersHistoryTotal() == 0)
         return(true);//No orders in the history tab, so there are not trades to examine.

   for (int cc = OrdersHistoryTotal() - 1; cc >= 0; cc--)
   {
      if (!OrderSelect(cc, SELECT_BY_POS, MODE_HISTORY) ) continue;
      if (OrderMagicNumber() != MagicNumber) continue;
      if (OrderSymbol() != Symbol() ) continue;
      //if (OrdersTotal() == 0 I'M LOST HERE PLEASE HELP ) return (true);   This is wrong
      
     //We have found a trade, so the history is not clear
     return(false);

  }//for (int cc = OrdersHistoryTotal() - 1; cc >= 0; cc--)

  //Got this far, so the history is clear
  return(true);
}// bool Isthehistoryclear ()



:xm: :rocket:
Author:  SteveHopwood [ Thu Jun 11, 2020 7:47 pm ]
Post subject:  Help with coding, orders history total

I forgot to explain why your OrdersTotal() code is incorrect, so here is an addition to my reply.

OrdersTotal() is the total of market, stop or limit orders on the platform. You are examining the closed trades in your History tab, so only OrdersHistoryTotal() is relevant here.

Keep at it. You will never regret learning to code this stuff.

:xm: :rocket:
Author:  LittleCaro [ Fri Jun 12, 2020 7:19 am ]
Post subject:  Help with coding, orders history total

Thanks for all Steve,

It works ok, it's wonderful, i'm learning everyday.


Thanks for your generosity. :!!:
All times are UTC Page 1 of 1