Bring chart into focus by Symbol Name

 

Hi,

Is it possible to bring a specific chart into focus by Symbol Name with some script, when you have a few charts open? Mt4 Platform.

I have scripts to do buy's and sell's for different instruments, but I can only get them to work correctly if the specific chart is in focus first. Even if I set the specific symbol name in the buy/sell script.

Thanks,

Joe

Documentation on MQL5: Market Info / SymbolName
Documentation on MQL5: Market Info / SymbolName
  • www.mql5.com
SymbolName - Market Info - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
system8: but I can only get them to work correctly if the specific chart is in focus first.
Then they are broken. Fix them.
 
William Roeder #:
Then they are broken. Fix them.

OK, I've tried, everywhere Symbol() appeared I put in the specific Symbol (extern string Instrument), as in the below "US30."

Will only work if "US30" chart is in focus.

Can you point me in the right direction to fix this?


#property copyright ""
#property link      ""
//#property show_inputs //

#include <OrderReliable_V1_1_1.mqh>
//+------------------------------------------------------------------+
extern int    Interest   = 20;      // 
extern int    DistSL     = 50;      // 
extern int    DistTP     = 70;      // 
extern bool   StopLoss   = true;    // 
extern bool   TakeProfit = true;    // 

extern string Instrument = "US30";

extern double Lots = 1.0;

//+------------------------------------------------------------------+
void start() 
{
int    ticket;
double SL=0,TP=0;
int    Dgts=MarketInfo(Instrument,MODE_DIGITS);     
   if(StopLoss==true) SL=Ask-DistSL*100*Point;
   if(TakeProfit==true) TP=Ask+DistTP*100*Point;
   ticket=OrderSendReliableMKT(Instrument,OP_BUY,LotsOptimized(),Ask,Ask-Bid,
                    NormalizeDouble(SL,Dgts),
                    NormalizeDouble(TP,Dgts),
                    "Hotkey",123456,0,CLR_NONE);
   if(ticket<=0) Alert("Error Open_BUY: ",ErrorDescription(OrderReliableLastErr())); 
   return(0);
}
//+------------------------------------------------------------------+


double LotsOptimized()
{
//----
  // double Lots=NormalizeDouble(AccountBalance()*Interest/100000.0,1);
   if(AccountFreeMargin()<(1000*Lots)){Lots=NormalizeDouble(AccountFreeMargin()*Interest/100000.0,1);}
   if(Lots>MarketInfo(Symbol(),MODE_MAXLOT)){Lots=MarketInfo(Instrument,MODE_MAXLOT);}
   if(Lots<MarketInfo(Symbol(),MODE_MINLOT)){Lots=MarketInfo(Instrument,MODE_MINLOT);}
//----
   return(Lots);
}
 
   if(StopLoss==true) SL=Ask-DistSL*100*Point;
   if(TakeProfit==true) TP=Ask+DistTP*100*Point;
   ticket=OrderSendReliableMKT(Instrument,OP_BUY,LotsOptimized(),Ask,Ask-Bid,
  1. Ask/Bid/Point are only the current chart, not valid for any other Instrument.

  2. You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit by the Ask.

    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

    2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close at a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25

    3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)

      Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes.
      My GBPJPY shows average spread = 26 points, average maximum spread = 134.
      My EURCHF shows average spread = 18 points, average maximum spread = 106.
      (your broker will be similar).
                Is it reasonable to have such a huge spreads (20 PIP spreads) in EURCHF? - General - MQL5 programming forum (2022)

  3. Spread has units of points, not prices.

 
system8 #:

OK, I've tried, everywhere Symbol() appeared I put in the specific Symbol (extern string Instrument), as in the below "US30."

Will only work if "US30" chart is in focus.

Can you point me in the right direction to fix this?


MarketInfo(Instrument,MODE_ASK)
etc