How To Calculate Breakeven?

Your basic questions about running EA's
Radar
Trader
Posts: 437
Joined: Fri Mar 23, 2012 5:39 pm
Location: Round the bend ;)

How To Calculate Breakeven?

Post by Radar »

Hey Gang,

I'm trying to work out how to automatically calculate breakeven on any pair that an EA is dropped onto, but haven't been able to find a formula on the 'net.

I did find how to calculate pip values, but what to do with that info has me kinda lost...

Is it (PipValue x NumberOfLots) + Spread?

Using USDJPY as an example, this yields:

(.01/130.46) x USD10,000 = $0.77 or 77 cents per pip

so 77 cents per pip x 0.03 Lots = 0.0231

Plus a 5 pip spread would give me a breakeven target of 130.53 ?

That's just the start of the problem, though... Wouldn't we have to calculate our entry cost based on the currency we're using to trade with, then work out breakeven from there? e.g. I'm trading with an Aus crim, using AUD, so I have to work out how much in AUD it would cost me to enter 0.03 lots of USDJPY @ 130.46 then convert that to USD, and then what? :?

My head hurts!

I guess the code to do that in a trading EA would be a severe buttpain to run, but would it be useful as a script or EA to give you the info to put into a trading EA?

I sure hope someone can unravel my ramblings and show me how this is done.

Have fun!

Radar =8^)
Check out my new, (well, old now), manual trade & automatic scale-in manager,
StackManV2
User avatar
NeoTrader
Trader
Posts: 436
Joined: Wed Apr 04, 2012 2:52 pm
Location: small Village at Lake Chiemsee, Bavaria, Germany

Re: How To Calculate Breakeven?

Post by NeoTrader »

Hi Radar,

i think you get here some things mixed up... break even is when the current price passes your entry price in your favor. this means as soon as you see a 0 or a positive value in your profit you are break even.

e.g. if ( currentPrice > entryPrice ) breakeven; for a long position
if ( currentPrice < entryPrice ) breakeven; for a short position

Or did i just misunderstand you?

happy trading,

NeoTrader
Radar
Trader
Posts: 437
Joined: Fri Mar 23, 2012 5:39 pm
Location: Round the bend ;)

Re: How To Calculate Breakeven?

Post by Radar »

Hi NeoTrader,
NeoTrader wrote:Hi Radar,

i think you get here some things mixed up... break even is when the current price passes your entry price in your favor. this means as soon as you see a 0 or a positive value in your profit you are break even.

e.g. if ( currentPrice > entryPrice ) breakeven; for a long position
if ( currentPrice < entryPrice ) breakeven; for a short position

Or did i just misunderstand you?

happy trading,

NeoTrader
That much I figured out, thanks ;)

A lot of EA's ask for "BreakEvenPips" in their settings, and I would just guess what to put in there... I suppose I could put the spread plus 1 pip, but with brokers that have variable spreads, you could end up being a bit short... The biggest spread I've seen with my broker was 13.5 pips:(

Am I wrong in thinking that break-even can be set by simply getting the spread at the time of opening a trade, and setting BreakEvenPips to that? Or maybe adding 1 pip to the spread, and setting that as breakeven? How to pass the spread (or spread + ?) from the open trade routine to the breakeven routine, though? Global variable? Write it in the comment, then read it in the breakeven routine? Either of those, or just set a maximum spread. and use that as your breakeven?

By doing something like...

Code: Select all


	double Spread = (MarketInfo(OrderSymbol(), MODE_SPREAD);

...And setting that as a global variable, just before or after sending an order, you could pull that into your breakeven routine.

Now, if the above works, or can be made to work, we no longer have to have BE in the setfile, as it's calculated at the time of each trade, so you can just have BreakEvenProfit in the setfile, and add, (since I don't know how to set GV's and read them, I've just called it "GVSpread")...

Code: Select all


	if (BreakEvenProfit >0)
	   {
	      double BreakEven = (GVSpread + (point*BreakEvenProfit));  //Incorrect code, but you get the picture, I hope ;)
	   }

...Well, I hope it's that easy ;) I copied the breakeven code from MPTM, added a check for StopLevel to stop Error:130's, (Cowboy IBFX has a StopLevel of 0, so Steve never sees errors caused by this) and just put "GVSpread" where the proper code should go.

Code: Select all


void BreakEvenStopLoss() // Move stop loss to breakeven
{
   if (!BreakEven) return(0); // User has not chosen this option, so abort
   int ticket;
   double StopLevel = MarketInfo(OrderSymbol(), MODE_STOPLEVEL);
   double BreakEvenPoints = GVSpread; // I don't know the code to pull a global variable, so this needs fixing

       if (BreakEvenProfit >0)
   	 {
	      BreakEvenPoints = (GVSpread + (BreakEvenProfit*point));  //Incorrect code, but you get the picture, I hope ;)
   	 }
           
   if (OrderType()==OP_BUY)
         {
            if ((bid - StopLevel) >= (OrderOpenPrice() + BreakEvenPoints) && 
                (OrderStopLoss()<OrderOpenPrice()|| OrderStopLoss()==0))
            {
               ticket = OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice() + BreakEvenPoints,OrderTakeProfit(),0,CLR_NONE);
               if (ticket>0 && ShowAlerts==true) Alert("Breakeven set on ", OrderSymbol(), " ticket no ", OrderTicket());
            }
   	   }               			         
          
   if (OrderType()==OP_SELL)
         {
           if ((ask + StopLevel) <= (OrderOpenPrice() - BreakEvenPoints) &&
              (OrderStopLoss()>OrderOpenPrice()|| OrderStopLoss()==0)) 
            {
               ticket = OederModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice() - BreakEvenPoints,OrderTakeProfit(),0,CLR_NONE);
               if (ticket>0 && ShowAlerts==true) Alert("Breakeven set on ", OrderSymbol(), " ticket no ", OrderTicket());
            }    
         }
      

} // End BreakevenStopLoss sub

My guess is that some brokers will be using points for stoplevel, whist others will be using pips, just to add to the confuzzlement, though.

Is any of this making sense, or am I in lala land? ;)

Take care,

&

Have fun!

Radar =8^)
Check out my new, (well, old now), manual trade & automatic scale-in manager,
StackManV2
dietcoke
Trader
Posts: 162
Joined: Tue Nov 15, 2011 9:59 pm

Re: How To Calculate Breakeven?

Post by dietcoke »

Radar wrote:Hi NeoTrader,
NeoTrader wrote:Hi Radar,

i think you get here some things mixed up... break even is when the current price passes your entry price in your favor. this means as soon as you see a 0 or a positive value in your profit you are break even.

e.g. if ( currentPrice > entryPrice ) breakeven; for a long position
if ( currentPrice < entryPrice ) breakeven; for a short position

Or did i just misunderstand you?

happy trading,

NeoTrader
That much I figured out, thanks ;)

A lot of EA's ask for "BreakEvenPips" in their settings, and I would just guess what to put in there... I suppose I could put the spread plus 1 pip, but with criminals that have variable spreads, you could end up being a bit short... The biggest spread I've seen with my criminal was 13.5 pips:(

Am I wrong in thinking that break-even can be set by simply getting the spread at the time of opening a trade, and setting BreakEvenPips to that? Or maybe adding 1 pip to the spread, and setting that as breakeven? How to pass the spread (or spread + ?) from the open trade routine to the breakeven routine, though? Global variable? Write it in the comment, then read it in the breakeven routine? Either of those, or just set a maximum spread. and use that as your breakeven?.

Radar =8^)

I'm not sure what you mean Radar. BreakEvenPips is the number of pips into profit at which you decide to move your stop to breakeven. Are you suggesting that you want this number to be variable depending on the spread for that pair?

if that is the case, you can do this by converting the current spread to pips and just adding it to the breakEvenPips setting.
Radar
Trader
Posts: 437
Joined: Fri Mar 23, 2012 5:39 pm
Location: Round the bend ;)

Re: How To Calculate Breakeven?

Post by Radar »

Hi Dietcoke,
dietcoke wrote:
Radar wrote:Hi NeoTrader

A lot of EA's ask for "BreakEvenPips" in their settings, and I would just guess what to put in there... I suppose I could put the spread plus 1 pip, but with criminals that have variable spreads, you could end up being a bit short... The biggest spread I've seen with my criminal was 13.5 pips:(

Am I wrong in thinking that break-even can be set by simply getting the spread at the time of opening a trade, and setting BreakEvenPips to that? Or maybe adding 1 pip to the spread, and setting that as breakeven? How to pass the spread (or spread + ?) from the open trade routine to the breakeven routine, though? Global variable? Write it in the comment, then read it in the breakeven routine? Either of those, or just set a maximum spread. and use that as your breakeven?.

Radar =8^)

I'm not sure what you mean Radar. BreakEvenPips is the number of pips into profit at which you decide to move your stop to breakeven. Are you suggesting that you want this number to be variable depending on the spread for that pair?

if that is the case, you can do this by converting the current spread to pips and just adding it to the breakEvenPips setting.
My crim has variable spreads, so I could open one position with a spread of 2 pips, and 10 seconds later, open another position on the same pair with a spread of 5 pips, and another with a 12 pip spread, (the worst I've seen was a 13.5 pip spread on my crim), so I want to be able to set the correct breakeven for each position, then add a few pips profit (BreakEvenProfit in Steve's EA's) on top of that.

So, what I need to do in that case is get the spread at the moment each position was opened, rather than constantly monitor the spread and check if price has moved that far my way yet.

I'm looking at how to set and read global variables now, and it will sink in over a few weeks, but I'm not really a coder... I can see an "Ooops" in simple code, and can eventually nail it with a sledgehammer, but I just can't seem to be able to get my head around the structure of a programme to be able to put one together properly :(

I am slowly putting an EA together, but it's more misses than hits at the moment ;) I'll eventually have it set the spread plus BEP for each ticket number in a global variable, then delete the GV once BEP is reached and locked in.

One day... ;)

Have fun!

Radar =8^)
Check out my new, (well, old now), manual trade & automatic scale-in manager,
StackManV2
Radar
Trader
Posts: 437
Joined: Fri Mar 23, 2012 5:39 pm
Location: Round the bend ;)

Re: How To Calculate Breakeven?

Post by Radar »

Hi DietCoke
dietcoke wrote:
I'm not sure what you mean Radar. BreakEvenPips is the number of pips into profit at which you decide to move your stop to breakeven.
That line finally bounced off the inside of my skull at the right angle to hit that poor, lonely synapse, and turned on the light ;)

D'oh!
Check out my new, (well, old now), manual trade & automatic scale-in manager,
StackManV2
whpatton
Posts: 2
Joined: Sun Sep 01, 2013 2:21 am

Re: How To Calculate Breakeven?

Post by whpatton »

Hello,
I was looking for a place to post this and I think this is the spot.

I read through this and I think there are some important things missing.

The question is "How To Calculate Breakeven?"

It should go like this correct?:
for a sell Breakeven=entryprice-spread-swap-crim_commision
for a buy the opposite.

All of which can be found here:
http://docs.mql4.com/constants/marketinfo

excepting crim_commison, but I have found that with global prime it has been about 7 cents.

Does anyone know of an MQL syntax to pull this from the server?

Thanks,
whpatton
User avatar
fxdaytrader
Trader
Posts: 190
Joined: Sun Jun 10, 2012 7:03 am
Location: Poon-Town (germany, se-asia, se-europe) ...

Re: How To Calculate Breakeven?

Post by fxdaytrader »

whpatton wrote: Does anyone know of an MQL syntax to pull this from the server?
first the order must be selected by orderselect-command (look to the expert advisors around here, enough examples :xm: ), then you could calculate:

Code: Select all

double profit = OrderProfit()+OrderSwap()+OrderCommission();
if profit==0.0 your are at BreakEven, if profit>0.0 your are in profit and if profit <0.0 you are losing ... :yahoo:
Radar
Trader
Posts: 437
Joined: Fri Mar 23, 2012 5:39 pm
Location: Round the bend ;)

Re: How To Calculate Breakeven?

Post by Radar »

Very old thread, started by an old fart newbie trader ;)

Was confuzzled by the BreakEven setting in a lot of EA's, not realizing that it meant that price had to be x number of pips into profit before moving your stoploss to break-even, (or break-even plus some profit).
Check out my new, (well, old now), manual trade & automatic scale-in manager,
StackManV2
whpatton
Posts: 2
Joined: Sun Sep 01, 2013 2:21 am

Re: How To Calculate Breakeven?

Post by whpatton »

fxdaytrader wrote: first the order must be selected by orderselect-command (look to the expert advisors around here, enough examples :xm: ), then you could calculate:

Code: Select all

double profit = OrderProfit()+OrderSwap()+OrderCommission();
if profit==0.0 your are at BreakEven, if profit>0.0 your are in profit and if profit <0.0 you are losing ... :yahoo:
Yes indeed this would tell me that I am at breakeven, but when I am at break even I cannot move my stoploss to it. I must be above break even at least to the spread. I know that moving stoploss to break even isn't really the question, but i thought I might try to muddle my way through it.


sell:
breakeven=entry price - ((orderswap+ordercommision)*Points)
but I cannot move my stoploss to breakeven until the ask is at least the spread distance from the price.
so..
if ask-(spread*points) is < than breakeven ordermodify SL=breakeven



I guess the question that I have now is: Is this still a solid way to manage trades? at least this is an easy way to make sure you not losing money if the trade doesn't swing the entire way in your direction.
Post Reply

Return to “Automated trading (Rookies)”