Question for the Guru's

Publish programs in Code Base. Improve your rating!
498
2016.06.30 23:10

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.

158
2016.07.01 07:25

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

14532
2016.07.01 13:30
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.
498
2016.07.02 12:09
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?

14532
2016.07.03 13:05
498
2016.07.03 14:20
WHRoeder:

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.

14532
2016.07.03 18:42
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.
498
2016.07.03 20:03
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.

Moderator
2225
2016.07.03 23:04
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.

498
2016.07.04 07:27
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!!

498
2016.07.04 08:15
```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(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_Practice Currency: USD Leverage: 1:50 2016 July 4, 04:05 Closed Transactions: Ticket Open Time Type Size Item Price S / L T / P Close Time Price Commission Taxes Swap Profit 219074251 2016.07.01 16:45:08 balance Interest -0.06 219083635 2016.07.02 16:46:58 balance Interest -0.06 219090508 2016.07.03 16:45:58 balance Interest -0.06 219100300 2016.07.03 18:06:47 balance Interest -0.01 218492263 2016.06.30 07:15:30 sell 0.01 nzdusd 0.71226 0.00000 0.00000 2016.07.03 18:06:47 0.71862 0.00 0.00 0.00 -6.36 219100311 2016.07.03 18:06:49 buy 0.01 nzdusd 0.71861 0.00000 0.00000 2016.07.03 18:07:15 0.71820 0.00 0.00 0.00 -0.41 219100321 2016.07.03 18:06:50 buy 0.01 nzdusd 0.71861 0.00000 0.00000 2016.07.03 18:09:08 0.71819 0.00 0.00 0.00 -0.42 219100323 2016.07.03 18:06:52 buy 0.01 nzdusd 0.71861 0.00000 0.00000 2016.07.03 18:09:09 0.71818 0.00 0.00 0.00 -0.43 219100324 2016.07.03 18:06:52 buy 0.01 nzdusd 0.71861 0.00000 0.00000 2016.07.03 18:09:10 0.71818 0.00 0.00 0.00 -0.43 219100325 2016.07.03 18:06:53 buy 0.01 nzdusd 0.71861 0.00000 0.00000 2016.07.03 18:09:11 0.71818 0.00 0.00 0.00 -0.43 219101178 2016.07.03 18:12:20 buy 0.01 nzdusd 0.71888 0.71388 0.00000 2016.07.03 18:13:02 0.71848 0.00 0.00 0.00 -0.40 219101191 2016.07.03 18:12:23 buy 0.01 nzdusd 0.71887 0.71387 0.00000 2016.07.03 18:13:04 0.71848 0.00 0.00 0.00 -0.39 219101195 2016.07.03 18:12:24 buy 0.01 nzdusd 0.71887 0.71387 0.00000 2016.07.03 18:13:05 0.71848 0.00 0.00 0.00 -0.39 219101197 2016.07.03 18:12:25 buy 0.01 nzdusd 0.71887 0.71387 0.00000 2016.07.03 18:13:05 0.71848 0.00 0.00 0.00 -0.39 219183313 2016.07.04 03:50:27 sell 0.01 nzdusd 0.71849 0.72349 0.00000 2016.07.04 03:51:21 0.71880 0.00 0.00 0.00 -0.31 219183314 2016.07.04 03:50:28 sell 0.01 nzdusd 0.71845 0.72347 0.00000 2016.07.04 03:51:31 0.71883 0.00 0.00 0.00 -0.38 219183316 2016.07.04 03:50:29 sell 0.01 nzdusd 0.71845 0.72345 0.00000 2016.07.04 03:51:32 0.71883 0.00 0.00 0.00 -0.38 219183317 2016.07.04 03:50:30 sell 0.01 nzdusd 0.71845 0.72345 0.00000 2016.07.04 03:51:33 0.71883 0.00 0.00 0.00 -0.38 219183318 2016.07.04 03:50:30 sell 0.01 nzdusd 0.71845 0.72345 0.00000 2016.07.04 03:51:38 0.71886 0.00 0.00 0.00 -0.41 219183319 2016.07.04 03:50:30 sell 0.01 nzdusd 0.71845 0.72345 0.00000 2016.07.04 03:51:39 0.71886 0.00 0.00 0.00 -0.41 0.00 0.00 0.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?

123