Questions from Beginners MQL5 MT5 MetaTrader 5 - page 462

 

Or will such a design not help if there is no tick on the instrument in question?

#property strict

extern bool USE_Info=true;

static datetime TimeN=0;

//+------------------------------------------------------------------+

//| Expert tick function                                             |

//+------------------------------------------------------------------+

int start()

  {

   datetime TimeC=iTime("GBPUSD",5,0);

   if(TimeN==0)TimeN=TimeC;

   if(TimeN==TimeC) return(0);

   TimeN=TimeC;

   return(INIT_SUCCEEDED);

  } 

 

Help me figure this out.

For example, I need to open a position on EURUSD with a stop of 30 pips and TakeProfit of 30 pips. Before opening the position, I need to specify the lot volume, so that a loss on a losing trade would be 100 USD. How can it be calculated using MQL5?

SL=30;

Lot=Formula for calculation

I would like to use my trading robot as a reference.

 
PabloEs:

Help me figure this out.

For example, I need to open a position on EURUSD with a stop of 30 pips and TakeProfit of 30 pips. Before opening the position, I need to specify the lot volume, so that a loss on a losing trade would be 100 USD. How can it be calculated using MQL5?

SL=30;

Lot=Formula for calculation

I thank you in advance.

For 4, you can calculate it this way:

Lot=Money / (Hundred_in_points*MarketInfo(Symbol(),MODE_TICKVALUE))

 
Artyom Trishkin:

For a quadruplet, you can calculate it this way:

Lot=Money / (Hundred_in_points*MarketInfo(Symbol(),MODE_TICKVALUE))

Thanks, but it didn't work for me.
 
PabloEs:
Thanks, but it didn't help me.

See SymbolInfoDouble() instead of MarketInfo()

And what do you mean it didn't help? I didn't give you a fish, I gave you a fishing rod.

 
Artyom Trishkin:

See SymbolInfoDouble() not MarketInfo()

And what do you mean it didn't work? I didn't give you the fish, I gave you the rod.

I'm too young to use a fishing rod)

I have written a script using the above formula

void OnStart()

{

//---

double Test=100/(300*_Point*SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_VALUE));

Alert(Test);

Gives out 33333.33, maybe the troll is wrong?

 
PabloEs:

I'm still too young to use a fishing rod)

Here's a script written using the formula above

void OnStart()

{

//---

double Test=100/(300*_Point*SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_VALUE));

Alert(Test);

Gives out 33333.33, maybe the troll is wrong?

Money /(Stoplos_in_points*MarketInfo(Symbol(),MODE_TICKVALUE))

And you count it in price

 
PabloEs:

I'm still too young to use a fishing rod)

Here's a script written using the formula above

void OnStart()

{

//---

double Test=100/(300*_Point*SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_VALUE));

Alert(Test);

Gives out 33333.33, maybe the troll is wrong?

I used to write such formula

Lot = AccountFreeMargin()*Risk/100*_Point/(StopLoss*MarketInfo(Symbol(), MODE_TICKVALUE))

AccountFreeMargin()*Risk/100 --- this is your $100

StopLoss --- Difference between the order open and SL prices (not in points)

Correspondingly, MarketInfo() must be replaced with SymbolInfoDouble()

 
PabloEs:

I'm still too young to use a fishing rod)

Here's a script written using the formula above

void OnStart()

{

//---

double Test=100/(300*_Point*SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_VALUE));

Alert(Test);

Gives out 33333.33, maybe the troll is wrong?

See what you have, if in Russian, and at _Point, equal to 0.00001:

To make $100 at a take of 0.003 point (300*0.00001), the lot must be 33333.33. So the troll is definitely wrong ;)

 
Artyom Trishkin:

Money /(Staples_in_points*MarketInfo(Symbol(),MODE_TICKVALUE))

And you count it in price

Exactly. When I wrote this formula, the SL was not defined by a specified value but was calculated as the difference between the order open price and some level, that's why I had to multiply the risk amount by _Point
Reason: