Get Marketinfo value

 

Hi everyone, I'm new here, also this is my first day using MQL4.

Is there a way to use MarketInfo MODE_STOPLEVEL to be the actual value of the min stop loss and take profit in the input and aftwards change the value based on user's input?


//+------------------------------------------------------------------+
//|                                                        first.mq4 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, The Forx Coder."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property show_inputs
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
enum Trading_Decisions{
Take_Profit,
Stop_Loss,
Both
};

input Trading_Decisions myDecision;

double minStopVal = MarketInfo(Symbol(),MODE_STOPLEVEL);

input double sl = 0;
input double tp = 0;
void OnStart()
  {
//---
Alert(minStopVal);

//understanding the pip value
double pipVal = 0;

if (Digits == 5){
pipVal = 0.0001;
}else if (Digits == 3){
pipVal = 0.01;
}

if (myDecision == Take_Profit){

double takeProfit = Bid + tp * pipVal;
Alert("price: " , Bid , " Take Profit: " , takeProfit);

}else if (myDecision == Stop_Loss){

double stopLoss = Bid - sl * pipVal;
Alert("price: " , Bid , " Stop Loss: " , stopLoss);

  }else if(myDecision == Both) {
  
  double takeProfit = Bid + tp * pipVal;
Alert("price: " , Bid , " Take Profit: " , takeProfit);
double stopLoss = Bid - sl * pipVal;
Alert("price: " , Bid , " Stop Loss: " , stopLoss);

  }
  else{
  Alert("There's a problem mate!");
  }
  }
 
TheForexDev: Is there a way to use MarketInfo MODE_STOPLEVEL to be the actual value of the min stop loss and take profit in the input and aftwards change the value based on user's input?
  1. double minStopVal = MarketInfo(Symbol(),MODE_STOPLEVEL);
    That is not an assignment; it's initialization of a common (globally declared,) or static variable with a constant. They work exactly the same way in MT4/MT5/C/C++.
    1. They are initialized once on program load.

    2. They don't update unless you assign to them.

    3. In C/C++ you can only initialize them with constants, and they default to zero. In MTx you should only initialize them with constants. There is no default in MT5, or MT4 with strict (which you should always use.)

      MT4/MT5 actually compiles with non-constants, but the order that they are initialized is unspecified and don't try to use any price or server related functions in OnInit (or on load,) as there may be no connection/chart yet:

      1. Terminal starts.
      2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
      3. OnInit is called.
      4. For indicators OnCalculate is called with any existing history.
      5. Human may have to enter password, connection to server begins.
      6. New history is received, OnCalculate called again.
      7. New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.

    4. Unlike indicators, EAs are not reloaded on chart change so you must reinitialize them, if necessary.
                external static variable - MQL4 programming forum

  2. You are running a script the variables are reset once it exits and you call it again.

    You could save a terminal variable and read it back on next run.