<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Forex Software — Move Trades in Profit to Break Even]]></title>
		<link>https://forexsb.com/forum/topic/7518/move-trades-in-profit-to-break-even/</link>
		<atom:link href="https://forexsb.com/forum/feed/rss/topic/7518/" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Move Trades in Profit to Break Even.]]></description>
		<lastBuildDate>Thu, 04 Oct 2018 06:30:07 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Move Trades in Profit to Break Even]]></title>
			<link>https://forexsb.com/forum/post/52461/#p52461</link>
			<description><![CDATA[<p>You can easily do that:</p><p>Put your BreakEven call in the OnTick event handler.</p><p>Modify:<br /></p><div class="codebox"><pre><code>void OnTick()
  {
   if(Time[0]&gt;barTime)
     {
      barTime=Time[0];
      OnBar();
     }
  }</code></pre></div><p>to:</p><div class="codebox"><pre><code>void OnTick()
  {
   if(Time[0]&gt;barTime)
     {
      barTime=Time[0];
      OnBar();
     }
   else
    {
      UpdatePosition();
      ManageBreakEven();
    }
  }</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Popov)]]></author>
			<pubDate>Thu, 04 Oct 2018 06:30:07 +0000</pubDate>
			<guid>https://forexsb.com/forum/post/52461/#p52461</guid>
		</item>
		<item>
			<title><![CDATA[Re: Move Trades in Profit to Break Even]]></title>
			<link>https://forexsb.com/forum/post/52458/#p52458</link>
			<description><![CDATA[<p>Now i have tried to implement from this to ea studio..</p><br /><div class="codebox"><pre><code>//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
   void ActionTrade::SetBreakEvenStop()
     {
      if(SetAggregatePosition(position)&lt;=0)
         return;

      double breakeven=stopLevel;
      if(breakeven&lt;breakEven)
         breakeven=breakEven;

      double breakprice = 0; // Break Even price including commission.
      double commission = 0; // Commission in points.
      if(position.Commission!=0)
         commission=MathAbs(position.Commission)/MarketInfo(_Symbol,MODE_TICKVALUE);

      double bid = MarketInfo(_Symbol, MODE_BID);
      double ask = MarketInfo(_Symbol, MODE_ASK);

      if(position.PosType==OP_BUY)
        {
         breakprice=NormalizeEntryPrice(position.OpenPrice+
                                        _Point*commission/position.Lots);
         if(bid-breakprice&gt;=_Point*breakeven)
           {
            if(position.StopLossPrice&lt;breakprice)
              {
               if(WriteLogFile)
                  logger.WriteLogRequest(&quot;SetBreakEvenStop&quot;,
                                         &quot;BreakPrice=&quot;+DoubleToString(breakprice,_Digits));

               ModifyPosition(breakprice,position.TakeProfitPrice);

               Print(&quot;SetBreakEvenStop(&quot;,breakEven,
                     &quot;) set StopLoss to &quot;,DoubleToString(breakprice,_Digits),
                     &quot;, Bid=&quot;,DoubleToString(bid,_Digits));
              }
           }
        }
      else if(position.PosType==OP_SELL)
        {
         breakprice=NormalizeEntryPrice(position.OpenPrice -
                                        _Point*commission/position.Lots);
         if(breakprice-ask&gt;=_Point*breakeven)
           {
            if(position.StopLossPrice==0 || position.StopLossPrice&gt;breakprice)
              {
               if(WriteLogFile)
                  logger.WriteLogRequest(&quot;SetBreakEvenStop&quot;,&quot;BreakPrice=&quot;+
                                         DoubleToString(breakprice,_Digits));

               ModifyPosition(breakprice,position.TakeProfitPrice);

               Print(&quot;SetBreakEvenStop(&quot;,breakEven,&quot;) set StopLoss to &quot;,
                     DoubleToString(breakprice,_Digits),
                     &quot;, Ask=&quot;,DoubleToString(ask,_Digits));
              }
           }
        }
     }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+</code></pre></div><p>from<a href="https://github.com/PopovMP/FSB_Expert_Advisor_Code/blob/master/Forexsb.com/ActionTrade4.mqh">https://github.com/PopovMP/FSB_Expert_A … Trade4.mqh</a></p><br /><p>ADDED now that into eastudio</p><div class="codebox"><pre><code>  //+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double NormalizeEntryPrice(double price)
     {
      double tickSize=MarketInfo(_Symbol,MODE_TICKSIZE);
      if(tickSize!=0)
         return (NormalizeDouble(MathRound(price / tickSize) * tickSize, _Digits));
      return (NormalizeDouble(price, _Digits));
     }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+  
  void ManageBreakEven()
     {
      double breakeven=Breakeven;

      double breakprice = 0; // Break Even price including commission.
   [color=red]   double commission = OrderCommission(); // Commission in points.[/color]
   [color=red]      commission=MathAbs(commission)/MarketInfo(_Symbol,MODE_TICKVALUE);[/color]

      double bid = MarketInfo(_Symbol, MODE_BID);
      double ask = MarketInfo(_Symbol, MODE_ASK);

      if(OrderType()==OP_BUY)
        {
[color=red]         breakprice=NormalizeEntryPrice(OrderOpenPrice()+
                                        _Point*commission/Entry_Amount);[/color]
         if(bid-breakprice&gt;=_Point*breakeven)
           {
            if(OrderStopLoss()&lt;breakprice)
              {
               posStopLoss=breakprice;
               posTakeProfit=OrderTakeProfit();
               ModifyPosition();

               Print(&quot;SetBreakEvenStop(&quot;,breakeven,
                     &quot;) set StopLoss to &quot;,DoubleToString(breakprice,_Digits),
                     &quot;, Bid=&quot;,DoubleToString(bid,_Digits));
              }
           }
        }
      else if(OrderType()==OP_SELL)
        {
         breakprice=NormalizeEntryPrice(OrderOpenPrice() -
                                        _Point*commission/Entry_Amount);
         if(breakprice-ask&gt;=_Point*breakeven)
           {
            if(OrderStopLoss()==0 || OrderStopLoss()&gt;breakprice)
              {
               posStopLoss=breakprice;
               posTakeProfit=OrderTakeProfit();
               ModifyPosition();

               Print(&quot;SetBreakEvenStop(&quot;,breakeven,&quot;) set StopLoss to &quot;,
                     DoubleToString(breakprice,_Digits),
                     &quot;, Ask=&quot;,DoubleToString(ask,_Digits));
              }
           }
        }
     }  
 //+------------------------------------------------------------------+
 //|                                                                  |
 //+------------------------------------------------------------------+</code></pre></div><p>dont know what this with commission is but at first check it is working.</p><p>Added this in OnBar()</p><div class="codebox"><pre><code>     if(posType!=OP_FLAT &amp;&amp; useBreakeven)
     {
      ManageBreakEven();
      UpdatePosition();
     }  </code></pre></div><p>but what to do that it works in on tick? put it in ontick?</p><p>Cause i dont know if it is really good idea..BE is 50pips away from entry point than the BE will be only modifiy on next bar. isnt it better to do with ontick?</p>]]></description>
			<author><![CDATA[null@example.com (deadlef)]]></author>
			<pubDate>Wed, 03 Oct 2018 17:04:16 +0000</pubDate>
			<guid>https://forexsb.com/forum/post/52458/#p52458</guid>
		</item>
		<item>
			<title><![CDATA[Re: Move Trades in Profit to Break Even]]></title>
			<link>https://forexsb.com/forum/post/52456/#p52456</link>
			<description><![CDATA[<p>Nobody an idea?</p><p>I have tried this.</p><div class="codebox"><pre><code>   if(posType!=OP_FLAT &amp;&amp; useBreakeven)
     {
      UpdateBE();
      UpdatePosition();
     }   </code></pre></div><p>added this to onbar</p><p>and added this function.</p><div class="codebox"><pre><code>void UpdateBE()
{
      bool modified;
      int lastError=0;
 for(int i = OrdersTotal() - 1; i &gt;= 0; i--)
   {
    if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
      {
       if(OrderType() == OP_BUY &amp;&amp; OrderOpenPrice() &gt; OrderStopLoss() &amp;&amp; Bid - OrderOpenPrice() &gt;= Breakeven * _Point)
       {
        modified=OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice(), OrderTakeProfit(), 0);
         lastError=GetLastError();
       }
           
      if(OrderType() == OP_SELL &amp;&amp; OrderOpenPrice() &lt; OrderStopLoss() &amp;&amp; OrderOpenPrice() - Ask &gt;= Breakeven * _Point)
       {
        modified=OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice(), OrderTakeProfit(), 0);
        lastError=GetLastError();
       }
      }
    }
}</code></pre></div><p>but it seems not working..what wrong here?</p><p>also input useBreakeven and int Breakeven was added as input parameters... so if an open order have reached xx pips( Breakeven variable) than set SL to OrderOpenprice.</p>]]></description>
			<author><![CDATA[null@example.com (deadlef)]]></author>
			<pubDate>Wed, 03 Oct 2018 13:14:00 +0000</pubDate>
			<guid>https://forexsb.com/forum/post/52456/#p52456</guid>
		</item>
		<item>
			<title><![CDATA[Move Trades in Profit to Break Even]]></title>
			<link>https://forexsb.com/forum/post/52333/#p52333</link>
			<description><![CDATA[<p>Hi,</p><p>can someone help me out how can i modding the eas that when a open order is xx pips in profit than modify the stop loss to break even?</p>]]></description>
			<author><![CDATA[null@example.com (deadlef)]]></author>
			<pubDate>Sat, 22 Sep 2018 12:19:27 +0000</pubDate>
			<guid>https://forexsb.com/forum/post/52333/#p52333</guid>
		</item>
	</channel>
</rss>
