<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Forex Software — Risk Percent]]></title>
		<link>https://forexsb.com/forum/topic/8020/risk-percent/</link>
		<atom:link href="https://forexsb.com/forum/feed/rss/topic/8020/" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Risk Percent.]]></description>
		<lastBuildDate>Sun, 25 Apr 2021 06:46:53 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Risk Percent]]></title>
			<link>https://forexsb.com/forum/post/64825/#p64825</link>
			<description><![CDATA[<p>Mr. Popov I was thinking to add 5 experts with 1%-2% but anyway, it is ok also to have a code similar to the post from Roughey. Unfortunately, I inserted several times in the last year and it is not working for me. And I have no idea about programming...</p><p>Please, if is not such a big work for you, just give us a general code (which works) to be inserted manually.. </p><p>thanks<br />Sebastian</p>]]></description>
			<author><![CDATA[null@example.com (mentosan)]]></author>
			<pubDate>Sun, 25 Apr 2021 06:46:53 +0000</pubDate>
			<guid>https://forexsb.com/forum/post/64825/#p64825</guid>
		</item>
		<item>
			<title><![CDATA[Re: Risk Percent]]></title>
			<link>https://forexsb.com/forum/post/64824/#p64824</link>
			<description><![CDATA[<p>What will happen if you enter 50% and run 3 experts?</p>]]></description>
			<author><![CDATA[null@example.com (Popov)]]></author>
			<pubDate>Sun, 25 Apr 2021 06:03:28 +0000</pubDate>
			<guid>https://forexsb.com/forum/post/64824/#p64824</guid>
		</item>
		<item>
			<title><![CDATA[Re: Risk Percent]]></title>
			<link>https://forexsb.com/forum/post/64823/#p64823</link>
			<description><![CDATA[<p>is it not possible to add the percentage risk as a trade option into the expert advisor?</p>]]></description>
			<author><![CDATA[null@example.com (mentosan)]]></author>
			<pubDate>Sun, 25 Apr 2021 05:59:54 +0000</pubDate>
			<guid>https://forexsb.com/forum/post/64823/#p64823</guid>
		</item>
		<item>
			<title><![CDATA[Re: Risk Percent]]></title>
			<link>https://forexsb.com/forum/post/57687/#p57687</link>
			<description><![CDATA[<p>Hello Roughey,</p><p>So i have been trying out the code for one week now, and it works, but there is still something missing.</p><p>When i put 10 in the Entry Percent input, the EA dont risk 10% of the account balance/equity but risk only 2-3%.</p><br /><p>Why and do i miss something?</p><br /><p>Thanks and happy weekend guys!</p>]]></description>
			<author><![CDATA[null@example.com (Riuzk)]]></author>
			<pubDate>Fri, 25 Oct 2019 16:00:41 +0000</pubDate>
			<guid>https://forexsb.com/forum/post/57687/#p57687</guid>
		</item>
		<item>
			<title><![CDATA[Re: Risk Percent]]></title>
			<link>https://forexsb.com/forum/post/57605/#p57605</link>
			<description><![CDATA[<p>One more thing, if it&#039;s not to much to ask.</p><p>Is it possible to make the EA only have 1 trade open at once?</p><p>So if there is an open position no new trade will be executed before the old position is closed</p><p>Thanks.</p>]]></description>
			<author><![CDATA[null@example.com (Riuzk)]]></author>
			<pubDate>Fri, 18 Oct 2019 18:51:48 +0000</pubDate>
			<guid>https://forexsb.com/forum/post/57605/#p57605</guid>
		</item>
		<item>
			<title><![CDATA[Re: Risk Percent]]></title>
			<link>https://forexsb.com/forum/post/57604/#p57604</link>
			<description><![CDATA[<p>Roughey! It finally works!</p><p>Did several tests, and it seems like it works perfectly. Will be putting out some EA&#039;s next week and see how it goes.</p><p>Thank you again for helping me out, really appreciate it Roughey.</p>]]></description>
			<author><![CDATA[null@example.com (Riuzk)]]></author>
			<pubDate>Fri, 18 Oct 2019 15:34:18 +0000</pubDate>
			<guid>https://forexsb.com/forum/post/57604/#p57604</guid>
		</item>
		<item>
			<title><![CDATA[Re: Risk Percent]]></title>
			<link>https://forexsb.com/forum/post/57589/#p57589</link>
			<description><![CDATA[<p>you are using Entry_Amount 2 times.. one time for your calculation and one time here</p><div class="codebox"><pre><code>void OpenPosition(Signal &amp;signal)
  {
   for(int attempt=0; attempt&lt;TRADE_RETRY_COUNT; attempt++)
     {
      int    ticket     = 0;
      int    lastError  = 0;
      bool   modified   = false;
      int    command    = OrderDirectionToCommand(signal.Direction);
      double amount     = Entry_Amount;</code></pre></div><p>So he is taking the 0,01 lots.</p><br /><p><strong>So you make it like this</strong></p><div class="codebox"><pre><code>#define OP_FLAT           -1

// Session time is set in seconds from 00:00
const int sessionSundayOpen           = 0;     // 00:00
const int sessionSundayClose          = 86400; // 24:00
const int sessionMondayThursdayOpen   = 36000; // 10:00
const int sessionMondayThursdayClose  = 61200; // 17:00
const int sessionFridayOpen           = 36000; // 10:00
const int sessionFridayClose          = 61200; // 17:00
const bool sessionIgnoreSunday        = true;
const bool sessionCloseAtSessionClose = false;
const bool sessionCloseAtFridayClose  = false;


input bool useFixLot = false; //Use Fix Lot
input double FixLot = 0.01; // Fix Lotsize
input bool                usePercent                        = true;                // Use Risk Percent base on AccountBalance
input double             Entry_Percent              = 2.00;                 // ENTRY PERCENT



const int    strategiesCount = 10;
const double sigma           = 0.000001;

datetime barTime;
int      digits;
double   stopLevel;
double   pip;
bool     setProtectionSeparately = false;
double Entry_Amount;

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+</code></pre></div><br /><p>AND IN ONTICK ADD THIS</p><div class="codebox"><pre><code>if(usePercent==true)
      {
      int margin=(int) MarketInfo(_Symbol,MODE_MARGINREQUIRED);
         Entry_Amount =(Entry_Percent/100)*AccountEquity()/margin;
         Entry_Amount = NormalizeEntrySize(Entry_Amount);
Comment(&quot;Next Lotsize: &quot;+DoubleToString(Entry_Amount));    &lt;---Optional
      }
if(useFixLot == true)
{
Entry_Amount = FixLot;
}</code></pre></div><br /><p>This must working!!!</p>]]></description>
			<author><![CDATA[null@example.com (Roughey)]]></author>
			<pubDate>Thu, 17 Oct 2019 20:14:26 +0000</pubDate>
			<guid>https://forexsb.com/forum/post/57589/#p57589</guid>
		</item>
		<item>
			<title><![CDATA[Re: Risk Percent]]></title>
			<link>https://forexsb.com/forum/post/57588/#p57588</link>
			<description><![CDATA[<p>Here is a picture of the whole EA</p><p><a href="https://imgur.com/a/zoNr4kh">https://imgur.com/a/zoNr4kh</a></p>]]></description>
			<author><![CDATA[null@example.com (Riuzk)]]></author>
			<pubDate>Thu, 17 Oct 2019 17:46:10 +0000</pubDate>
			<guid>https://forexsb.com/forum/post/57588/#p57588</guid>
		</item>
		<item>
			<title><![CDATA[Re: Risk Percent]]></title>
			<link>https://forexsb.com/forum/post/57584/#p57584</link>
			<description><![CDATA[<p>Error: &#039;Entry_Amount&#039; - constant cannot be modified</p><p>Picture of error:<br /><a href="https://imgur.com/a/7Kcipnt">https://imgur.com/a/7Kcipnt</a></p>]]></description>
			<author><![CDATA[null@example.com (Riuzk)]]></author>
			<pubDate>Thu, 17 Oct 2019 15:48:36 +0000</pubDate>
			<guid>https://forexsb.com/forum/post/57584/#p57584</guid>
		</item>
		<item>
			<title><![CDATA[Re: Risk Percent]]></title>
			<link>https://forexsb.com/forum/post/57583/#p57583</link>
			<description><![CDATA[<p>send error code.</p>]]></description>
			<author><![CDATA[null@example.com (Roughey)]]></author>
			<pubDate>Thu, 17 Oct 2019 15:39:37 +0000</pubDate>
			<guid>https://forexsb.com/forum/post/57583/#p57583</guid>
		</item>
		<item>
			<title><![CDATA[Re: Risk Percent]]></title>
			<link>https://forexsb.com/forum/post/57569/#p57569</link>
			<description><![CDATA[<p>So i did the change, but it seems like the Entry_Amount error is still the problem.</p><p>So i removed the static from the Entry_Amount</p><div class="codebox"><pre><code>//
// EA Studio Portfolio Expert Advisor
//
// Created with: Expert Advisor Studio
// Website: https://eaforexacademy.com/expert-advisor-studio/
//
// Copyright 2019, Forex Software Ltd.
//
// This Portfolio Expert works in MetaTrader 4.
// It opens separate positions for each strategy.
// Every position has an unique magic number,
// which corresponds to the index of the strategy.
//

#property copyright &quot;Forex Software Ltd.&quot;
#property version   &quot;2.4&quot;
#property strict

input double Entry_Amount      = 0.01; // Entry lots &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;Removed static
static input int    Base_Magic_Number = 100;  // Base Magic Number

#define TRADE_RETRY_COUNT 4
#define TRADE_RETRY_WAIT  100
#define OP_FLAT           -1

// Session time is set in seconds from 00:00
const int sessionSundayOpen           = 0;     // 00:00
const int sessionSundayClose          = 86400; // 24:00
const int sessionMondayThursdayOpen   = 36000; // 10:00
const int sessionMondayThursdayClose  = 61200; // 17:00
const int sessionFridayOpen           = 36000; // 10:00
const int sessionFridayClose          = 61200; // 17:00
const bool sessionIgnoreSunday        = true;
const bool sessionCloseAtSessionClose = false;
const bool sessionCloseAtFridayClose  = false;

input bool                usePercent                        = true;                // Use Risk Percent base on AccountBalance
input double               Entry_Percent              = 2.00;                 // ENTRY PERCENT



const int    strategiesCount = 10;
const double sigma           = 0.000001;

datetime barTime;
int      digits;
double   stopLevel;
double   pip;
bool     setProtectionSeparately = false;

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+</code></pre></div><br /><br /><p>Added the normalize in, and the last part outside ontick</p><br /><br /><div class="codebox"><pre><code>//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick()

  {
   if(IsForceSessionClose())
     {
      CloseAllPositions();
      return;
     }

   if(Time[0]&gt;barTime)
     {
      barTime=Time[0];
      OnBar();
     }
     
   if(usePercent==true)
      {
      int margin=(int) MarketInfo(_Symbol,MODE_MARGINREQUIRED);
         Entry_Amount =(Entry_Percent/100)*AccountEquity()/margin;
         Entry_Amount = NormalizeEntrySize(Entry_Amount);
      }
    
  }
  
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
  
  
 double NormalizeEntrySize(double size) {
   double minlot  = MarketInfo(_Symbol, MODE_MINLOT);
   double maxlot  = MarketInfo(_Symbol, MODE_MAXLOT);
   double lotstep = MarketInfo(_Symbol, MODE_LOTSTEP);

   if (size &lt;= minlot)
       return (minlot);

   int steps = (int) MathRound((size - minlot) / lotstep);
   size = minlot + steps * lotstep;

   if (size &gt;= maxlot)
       size = maxlot;
       
   size = NormalizeDouble(size, digits);   

   return (size);
}    
  
  
  
  
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+</code></pre></div><p>Have i forgot something?</p><p>Thanks guys <img src="https://forexsb.com/forum/img/smilies/smile.png" width="15" height="15" alt="smile" /></p>]]></description>
			<author><![CDATA[null@example.com (Riuzk)]]></author>
			<pubDate>Thu, 17 Oct 2019 04:17:09 +0000</pubDate>
			<guid>https://forexsb.com/forum/post/57569/#p57569</guid>
		</item>
		<item>
			<title><![CDATA[Re: Risk Percent]]></title>
			<link>https://forexsb.com/forum/post/57566/#p57566</link>
			<description><![CDATA[<p>yes delete the static and than it must work..also you have to check if entry amount is possible to your broker..so you have to normalize it.</p><div class="codebox"><pre><code>      int margin=(int) MarketInfo(_Symbol,MODE_MARGINREQUIRED);
         Entry_Amount=(Entry_Percent/100)*AccountEquity()/margin;}
ADD THIS---&gt;        Entry_Amount = NormalizeEntrySize(Entry_Amount);</code></pre></div><p>add this</p><br /><p>and add this outside ontick</p><div class="codebox"><pre><code>double NormalizeEntrySize(double size) {
   double minlot  = MarketInfo(_Symbol, MODE_MINLOT);
   double maxlot  = MarketInfo(_Symbol, MODE_MAXLOT);
   double lotstep = MarketInfo(_Symbol, MODE_LOTSTEP);

   if (size &lt;= minlot)
       return (minlot);

   int steps = (int) MathRound((size - minlot) / lotstep);
   size = minlot + steps * lotstep;

   if (size &gt;= maxlot)
       size = maxlot;
       
   size = NormalizeDouble(size, digits);   

   return (size);
}   </code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Roughey)]]></author>
			<pubDate>Wed, 16 Oct 2019 20:59:25 +0000</pubDate>
			<guid>https://forexsb.com/forum/post/57566/#p57566</guid>
		</item>
		<item>
			<title><![CDATA[Re: Risk Percent]]></title>
			<link>https://forexsb.com/forum/post/57565/#p57565</link>
			<description><![CDATA[<div class="quotebox"><cite>Riuzk wrote:</cite><blockquote><p>Thank you Roughey, appreciate your effort helping out members <img src="https://forexsb.com/forum/img/smilies/smile.png" width="15" height="15" alt="smile" /></p><p>But it seems like i have some issue inserting it to my EA</p><p>This i what i did:</p><p>I inserted these two lines, almost at the begining</p><p>input bool&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; usePercent&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = true;&nbsp; &nbsp; &nbsp;// Use Risk Percent base on AccountBalance<br />input double&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Entry_Percent&nbsp; &nbsp; &nbsp; &nbsp; = 2.00;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// ENTRY PERCENT</p><br /><br /><div class="codebox"><pre><code>//
// EA Studio Portfolio Expert Advisor
//
// Created with: Expert Advisor Studio
// Website: https://eaforexacademy.com/expert-advisor-studio/
//
// Copyright 2019, Forex Software Ltd.
//
// This Portfolio Expert works in MetaTrader 4.
// It opens separate positions for each strategy.
// Every position has an unique magic number,
// which corresponds to the index of the strategy.
//

#property copyright &quot;Forex Software Ltd.&quot;
#property version   &quot;2.4&quot;
#property strict

static input double Entry_Amount      = 0.01; // Entry lots
static input int    Base_Magic_Number = 100;  // Base Magic Number

#define TRADE_RETRY_COUNT 4
#define TRADE_RETRY_WAIT  100
#define OP_FLAT           -1

// Session time is set in seconds from 00:00
const int sessionSundayOpen           = 0;     // 00:00
const int sessionSundayClose          = 86400; // 24:00
const int sessionMondayThursdayOpen   = 36000; // 10:00
const int sessionMondayThursdayClose  = 61200; // 17:00
const int sessionFridayOpen           = 36000; // 10:00
const int sessionFridayClose          = 61200; // 17:00
const bool sessionIgnoreSunday        = true;
const bool sessionCloseAtSessionClose = false;
const bool sessionCloseAtFridayClose  = false;

input bool                usePercent                        = true;                // Use Risk Percent base on AccountBalance
input double               Entry_Percent              = 2.00;                 // ENTRY PERCENT


const int    strategiesCount = 10;
const double sigma           = 0.000001;

datetime barTime;
int      digits;
double   stopLevel;
double   pip;
bool     setProtectionSeparately = false;

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+</code></pre></div><p>And the other part here</p><div class="codebox"><pre><code>//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick()

  {
   if(IsForceSessionClose())
     {
      CloseAllPositions();
      return;
     }

   if(Time[0]&gt;barTime)
     {
      barTime=Time[0];
      OnBar();
     }
     
   if(usePercent==true)
      {
      int margin=(int) MarketInfo(_Symbol,MODE_MARGINREQUIRED);
         Entry_Amount =(Entry_Percent/100)*AccountEquity()/margin;
      }
    
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+</code></pre></div><br /><p>I got 1 error when im trying to compile it:<br />&#039;Entry_Amount&#039; - constant cannot be modified</p><p>Could you help me out on what i did wrong here or maybe send an EA with the code inserted aldready.</p><p>Thanks <img src="https://forexsb.com/forum/img/smilies/smile.png" width="15" height="15" alt="smile" /></p></blockquote></div><p>I may be wrong but I believe it is because you have Entry amount as a Static Input. Trying removing the word static and compile</p>]]></description>
			<author><![CDATA[null@example.com (Michael1)]]></author>
			<pubDate>Wed, 16 Oct 2019 20:37:28 +0000</pubDate>
			<guid>https://forexsb.com/forum/post/57565/#p57565</guid>
		</item>
		<item>
			<title><![CDATA[Re: Risk Percent]]></title>
			<link>https://forexsb.com/forum/post/57564/#p57564</link>
			<description><![CDATA[<p>Thank you Roughey, appreciate your effort helping out members <img src="https://forexsb.com/forum/img/smilies/smile.png" width="15" height="15" alt="smile" /></p><p>But it seems like i have some issue inserting it to my EA</p><p>This i what i did:</p><p>I inserted these two lines, almost at the begining</p><p>input bool&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; usePercent&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = true;&nbsp; &nbsp; &nbsp;// Use Risk Percent base on AccountBalance<br />input double&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Entry_Percent&nbsp; &nbsp; &nbsp; &nbsp; = 2.00;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// ENTRY PERCENT</p><br /><br /><div class="codebox"><pre><code>//
// EA Studio Portfolio Expert Advisor
//
// Created with: Expert Advisor Studio
// Website: https://eaforexacademy.com/expert-advisor-studio/
//
// Copyright 2019, Forex Software Ltd.
//
// This Portfolio Expert works in MetaTrader 4.
// It opens separate positions for each strategy.
// Every position has an unique magic number,
// which corresponds to the index of the strategy.
//

#property copyright &quot;Forex Software Ltd.&quot;
#property version   &quot;2.4&quot;
#property strict

static input double Entry_Amount      = 0.01; // Entry lots
static input int    Base_Magic_Number = 100;  // Base Magic Number

#define TRADE_RETRY_COUNT 4
#define TRADE_RETRY_WAIT  100
#define OP_FLAT           -1

// Session time is set in seconds from 00:00
const int sessionSundayOpen           = 0;     // 00:00
const int sessionSundayClose          = 86400; // 24:00
const int sessionMondayThursdayOpen   = 36000; // 10:00
const int sessionMondayThursdayClose  = 61200; // 17:00
const int sessionFridayOpen           = 36000; // 10:00
const int sessionFridayClose          = 61200; // 17:00
const bool sessionIgnoreSunday        = true;
const bool sessionCloseAtSessionClose = false;
const bool sessionCloseAtFridayClose  = false;

input bool                usePercent                        = true;                // Use Risk Percent base on AccountBalance
input double               Entry_Percent              = 2.00;                 // ENTRY PERCENT


const int    strategiesCount = 10;
const double sigma           = 0.000001;

datetime barTime;
int      digits;
double   stopLevel;
double   pip;
bool     setProtectionSeparately = false;

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+</code></pre></div><p>And the other part here</p><div class="codebox"><pre><code>//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick()

  {
   if(IsForceSessionClose())
     {
      CloseAllPositions();
      return;
     }

   if(Time[0]&gt;barTime)
     {
      barTime=Time[0];
      OnBar();
     }
     
   if(usePercent==true)
      {
      int margin=(int) MarketInfo(_Symbol,MODE_MARGINREQUIRED);
         Entry_Amount =(Entry_Percent/100)*AccountEquity()/margin;
      }
    
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+</code></pre></div><br /><p>I got 1 error when im trying to compile it:<br />&#039;Entry_Amount&#039; - constant cannot be modified</p><p>Could you help me out on what i did wrong here or maybe send an EA with the code inserted aldready.</p><p>Thanks <img src="https://forexsb.com/forum/img/smilies/smile.png" width="15" height="15" alt="smile" /></p>]]></description>
			<author><![CDATA[null@example.com (Riuzk)]]></author>
			<pubDate>Wed, 16 Oct 2019 19:07:29 +0000</pubDate>
			<guid>https://forexsb.com/forum/post/57564/#p57564</guid>
		</item>
		<item>
			<title><![CDATA[Re: Risk Percent]]></title>
			<link>https://forexsb.com/forum/post/57561/#p57561</link>
			<description><![CDATA[<div class="codebox"><pre><code>input bool                usePercent                        = true;                // Use Risk Percent base on AccountBalance
input double               Entry_Percent              = 2.00;                 // ENTRY PERCENT
Put in OnTick this:
if(usePercent==true)
      int margin=(int) MarketInfo(_Symbol,MODE_MARGINREQUIRED);
         Entry_Amount=(Entry_Percent/100)*AccountEquity()/margin;}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Roughey)]]></author>
			<pubDate>Wed, 16 Oct 2019 16:08:16 +0000</pubDate>
			<guid>https://forexsb.com/forum/post/57561/#p57561</guid>
		</item>
	</channel>
</rss>
