Help with coding, orders history total

Post Reply
User avatar
LittleCaro
Trader
Posts: 63
Joined: Tue May 19, 2015 7:09 am

Help with coding, orders history total

Post by LittleCaro »

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 !
User avatar
SteveHopwood
Owner
Posts: 9754
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Help with coding, orders history total

Post by SteveHopwood »

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:
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. [email protected] is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
User avatar
SteveHopwood
Owner
Posts: 9754
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Help with coding, orders history total

Post by SteveHopwood »

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:
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. [email protected] is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
User avatar
LittleCaro
Trader
Posts: 63
Joined: Tue May 19, 2015 7:09 am

Help with coding, orders history total

Post by LittleCaro »

Thanks for all Steve,

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


Thanks for your generosity. :!!:
Post Reply

Return to “Coders Hangout”