Question for the Guru's

 

I have an idea for a advisory type of indicator.

1) Calculate the maximum risk of a account using a Risk/Reward ratio and convert into the number of pips allowed to risk.  <Got this covered.

2) Reset the Risk at midnight (Broker Time). < Got this covered

3) Check Order History for losing trades since the midnight restart. < Help !

4) Calculate the total amount of money lost since the reset, also get the risk in pips from any open trades and convert all that into the number of pips lost and used. < Help ! 

5) Subtract step 4 from the maximum number of available pips and Print the total. < Help !

 

This is for a scalping type of situation.

Example...

Maximum risk on a account is $200.

$200 = 20 pips for Standard lots or 200 pips for mini lots or 2000 pips for micro lots.

10 trades since reset equaling 50 pips in loss.

Open trades are totaling another 50 pips at risk.

There is 100 pips left using the maximum risk caculation.

I am not asking for anyone to do this for me, I am perfectly capable of coding this myself, for the most part anyhow. 

Any posted examples will greatly appreciated. 

 

 

I pray I described this clearly enough. 

 

If you are "perfectly capable of coding this yourself" then do it and ask again if you have specific problems.

 
We're not going to code it FOR you. We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem.
 
WHRoeder:
We're not going to code it FOR you. We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem.

Ok I get it. I didn't explain what I was doing clearly enough.

I am not looking for anyone to code this for me.

When I code my little programs I try to lay out a structure to follow, kinda like a flow chart.

My problem is, I haven't had much of a need to check order history. The examples I have found only show me how to check the usual trade details, ticket #, open time, closed at the stoploss etc.

What i want to is go through every order 1 at a time, get the loss in pips, add each loss together and the subtract that from the maximum pips I am allowed to risk and reset everything at midnight.

 

Is looping through order history the way to accomplish this?

If so..

Do I nest multiple loops? 

Would it be better to just store the information on each trade 1 at a time?

  

I am just asking for advice on where to start with this, of course and example would be nice.  

 
4x_Gypsy:

What i want to is go through every order 1 at a time, get the loss in pips, add each loss together and the subtract that from the maximum pips I am allowed to risk and reset everything at midnight.

Is looping through order history the way to accomplish this?

Do I nest multiple loops?

Would it be better to just store the information on each trade 1 at a time?

I am just asking for advice on where to start with this

  1. So do it, what's stopping you? We're not going to code it FOR you. We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem.
  2. How else can you read history?
  3. History only has one dimension (position,) why would you need nested loops?
  4. Why would you want to duplicate what is already stored in history? You can't store the loss/profit until you read it from history.
  5. So go through history "1 at a time," ignore previous day's orders, "get the loss in pips, add each loss together."  So do it.
 
WHRoeder:
4x_Gypsy:

What i want to is go through every order 1 at a time, get the loss in pips, add each loss together and the subtract that from the maximum pips I am allowed to risk and reset everything at midnight.

Is looping through order history the way to accomplish this?

Do I nest multiple loops?

Would it be better to just store the information on each trade 1 at a time?

I am just asking for advice on where to start with this

  1. So do it, what's stopping you? We're not going to code it FOR you. We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem.
  2. How else can you read history?
  3. History only has one dimension (position,) why would you need nested loops?
  4. Why would you want to duplicate what is already stored in history? You can't store the loss/profit until you read it from history.
  5. So go through history "1 at a time," ignore previous day's orders, "get the loss in pips, add each loss together."  So do it.

LMAO same ol WHRoeder

1) I never ask once for anyone to code anything for me at any time! I posted the "Nature" of the problem in my explanation of this exercise I have created for myself.

2) I know there is only 1 way to read history. As I have stated above I don't have much experience using history for anything, I am only asking for a bit of advice on that matter.

3) Why not use nested loops? Again read #2

4) Maybe duplicating each order is an easier way to use the closed trades for some kind of analysis? I don't know - Read #2.

5) That is the obvious path of course, but AGAIN READ #2.

 

To my knowledge I have never posted anything asking for someone to code for me, so get over that.

I posted this asking for advice and direction. I understand the obvious direction you have posted ( 5 ) but I am having trouble getting my head around what needs to be done and how.

If you or anyone else thinks all this is below them, DO NOT REPLY !, I don't need the drama. Some of us are not as advanced as some, give us a break.

 

There is a old saying... If you can't help, don't hurt. 

 
4x_Gypsy: I posted the "Nature" of the problem . give us a break.
  1. No you didn't. You stated what you want and that "I am perfectly capable of coding this myself."  You never even tried to code it, there is no problem.
  2. I told you to code it exactly like you stated, you haven't. You've wasted my time, eddie's time, and all the other people that have looked at your post, give us a break.
  3. Your #2, #3, #4 is about five lines of code total.
 
WHRoeder:
  1. No you didn't. You stated what you want and that "I am perfectly capable of coding this myself."  You never even tried to code it, there is no problem.
  2. I told you to code it exactly like you stated, you haven't. You've wasted my time, eddie's time, and all the other people that have looked at your post, give us a break.
  3. Your #2, #3, #4 is about five lines of code total.

Ok WHRoeder I am done with this and you.

"IF" I ever post anything again, don't bother yourself with anything I do or say.

All I needed was a push in the right direction and all I got was condescending comments, as usual.

1) How do you know I haven't even tried to code this, because I haven't posted anything? Maybe all this is just a exercise I came up with to further my learning. I don't spend hours in front of this computer coding, 75% of my coding is done on paper long before I type anything.

2) Wasted your Time? Then why are you still posting to my thread? Move along, stay away from anything I do, the last thing I want to do is waste anyone's time. You posted your reply, go away!

3) 5 lines of code? You come across with this condescending bs just for 5 lines of code???? I believe you are wasting my time!!

 

I am sorry to everyone else for the attention I given to post, I never intended it go in this direction. I will take my questions to another site until MetaQuotes takes more control of this forum, hopefully with a moderator who is newbie friendly. 

 
4x_Gypsy:

3) Check Order History for losing trades since the midnight restart. < Help !

You'll need to figure out when midnight was. Later on, you can then compare this to OrderCloseTime() ... or OrderOpenTime().

If you're using broker time, and only interested in today, you can just use the current D1 bar:

datetime midnight = iTime(NULL,PERIOD_D1,0);

Otherwise, you'll need to use one of the other methods e.g.

datetime now = TimeCurrent(); // or whatever time you plan to use  
datetime midnight = now - (now % 86400);

 

Looping through the orders is easy enough. A couple of points worth noting:

1. Loop backwards. This really only matters if you're closing orders, but you might as well always do it. See here for more info

2. You need to check all the orders, as the orders are apparently not always in chronological order. See here for more info

 

The basic loop is:

for(int i=OrdersHistoryTotal()-1; i>=0; i--)
  {

  }

 

You'll need to select each order before you can get access to things like OrderCloseTime() etc. If you can't select the order, move on:

for(int i=OrdersHistoryTotal()-1; i>=0; i--)
  {
   if(!OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) { continue; }

  }

 

Once you've selected an order, you can test for other conditions e.g. does the magic number match, does the symbol match, is it a buy/sell? You need to decide on your criteria then skip the orders you're not interested in.

for(int i=OrdersHistoryTotal()-1; i>=0; i--)
  {
   if(!OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) { continue; }
   if(OrderMagicNumber() != MagicNo)                { continue; } 
   if(OrderSymbol() != Symbol())                    { continue; }
   if(OrderType() != OP_BUY)                        { continue; }
  }

 

That should narrow you down to the orders you are interested in. Then you can start added together winners / losers etc.

 
honest_knave:

You'll need to figure out when midnight was. Later on, you can then compare this to OrderCloseTime() ... or OrderOpenTime().

If you're using broker time, and only interested in today, you can just use the current D1 bar:

Otherwise, you'll need to use one of the other methods e.g.

 

Looping through the orders is easy enough. A couple of points worth noting:

1. Loop backwards. This really only matters if you're closing orders, but you might as well always do it. See here for more info

2. You need to check all the orders, as the orders are apparently not always in chronological order. See here for more info

 

The basic loop is:

 

You'll need to select each order before you can get access to things like OrderCloseTime() etc. If you can't select the order, move on:

 

Once you've selected an order, you can test for other conditions e.g. does the magic number match, does the symbol match, is it a buy/sell? You need to decide on your criteria then skip the orders you're not interested in.

 

That should narrow you down to the orders you are interested in. Then you can start added together winners / losers etc.

Thank you very much!! 

 
void RiskManagement_Pips()
  {
/*-------------------------------------------------------------------------------------------------*/
   double Long_Count=0;
   double Short_Count=0;
   double Count=0;

   for(int a=OrdersHistoryTotal()-1;a>=0;a--)
      if(OrderSelect(a,SELECT_BY_POS,MODE_HISTORY))
        {
         if(OrderType()==OP_BUY)
            if(OrderClosePrice()<OrderOpenPrice())
              {
               Long_Count=OrderOpenPrice()-OrderClosePrice();
              }
               Long_Count++;
         if(OrderType()==OP_SELL)
            if(OrderClosePrice()>OrderOpenPrice())
              {
               Short_Count=OrderClosePrice()-OrderOpenPrice();
              }
               Short_Count++;
        }
   Print("Long_Count  "+DoubleToStr(Long_Count,Digits));
   Print("Short_Count  "+DoubleToStr(Short_Count,Digits));
   Count=Long_Count+Short_Count;
   Print("Count"+DoubleToStr(Count,Digits));
/*-------------------------------------------------------------------------------------------------*/
  }

This is what I have so far.

All I am trying to do with this is get the price totals, I will add Time, convert to pips and so on later.

 This is my order history..


Name: MT4_USD_PracticeCurrency: USDLeverage: 1:502016 July 4, 04:05
Closed Transactions:
TicketOpen TimeTypeSizeItemPriceS / LT / PClose TimePriceCommissionTaxesSwapProfit
2190742512016.07.01 16:45:08balanceInterest-0.06
2190836352016.07.02 16:46:58balanceInterest-0.06
2190905082016.07.03 16:45:58balanceInterest-0.06
2191003002016.07.03 18:06:47balanceInterest-0.01
2184922632016.06.30 07:15:30sell0.01nzdusd0.712260.000000.000002016.07.03 18:06:470.718620.000.000.00-6.36
2191003112016.07.03 18:06:49buy0.01nzdusd0.718610.000000.000002016.07.03 18:07:150.718200.000.000.00-0.41
2191003212016.07.03 18:06:50buy0.01nzdusd0.718610.000000.000002016.07.03 18:09:080.718190.000.000.00-0.42
2191003232016.07.03 18:06:52buy0.01nzdusd0.718610.000000.000002016.07.03 18:09:090.718180.000.000.00-0.43
2191003242016.07.03 18:06:52buy0.01nzdusd0.718610.000000.000002016.07.03 18:09:100.718180.000.000.00-0.43
2191003252016.07.03 18:06:53buy0.01nzdusd0.718610.000000.000002016.07.03 18:09:110.718180.000.000.00-0.43
2191011782016.07.03 18:12:20buy0.01nzdusd0.718880.713880.000002016.07.03 18:13:020.718480.000.000.00-0.40
2191011912016.07.03 18:12:23buy0.01nzdusd0.718870.713870.000002016.07.03 18:13:040.718480.000.000.00-0.39
2191011952016.07.03 18:12:24buy0.01nzdusd0.718870.713870.000002016.07.03 18:13:050.718480.000.000.00-0.39
2191011972016.07.03 18:12:25buy0.01nzdusd0.718870.713870.000002016.07.03 18:13:050.718480.000.000.00-0.39
2191833132016.07.04 03:50:27sell0.01nzdusd0.718490.723490.000002016.07.04 03:51:210.718800.000.000.00-0.31
2191833142016.07.04 03:50:28sell0.01nzdusd0.718450.723470.000002016.07.04 03:51:310.718830.000.000.00-0.38
2191833162016.07.04 03:50:29sell0.01nzdusd0.718450.723450.000002016.07.04 03:51:320.718830.000.000.00-0.38
2191833172016.07.04 03:50:30sell0.01nzdusd0.718450.723450.000002016.07.04 03:51:330.718830.000.000.00-0.38
2191833182016.07.04 03:50:30sell0.01nzdusd0.718450.723450.000002016.07.04 03:51:380.718860.000.000.00-0.41
2191833192016.07.04 03:50:30sell0.01nzdusd0.718450.723450.000002016.07.04 03:51:390.718860.000.000.00-0.41
 0.000.000.00-12.32
Closed P/L:-12.32

 

 Account History....

 2016.07.04 04:09:23.066 Trade_Asst_Analysis NZDUSD,M5: Count  7.00677

2016.07.04 04:09:23.066 Trade_Asst_Analysis NZDUSD,M5: Short_Count  1.00636

2016.07.04 04:09:23.066 Trade_Asst_Analysis NZDUSD,M5: Long_Count  6.00041

 


I am not getting the correct amounts, knowing me I am missing something very obvious. Any Help?