[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 863

 
IgorM:

what is the best way to save important data/variables in case the terminal hangs up (power failure)?

- global variables of the terminal? to a file?

- how often do they need to be saved? (the last equity value and some bools are important)

What's the problem, all to an array, and the array to a file on every tick, read the file in the initialization, and no problems
 

Hello!

I can not understand why I can not modify an open position, I typed the order (in the order select function)

//+------------------------------------------------------------------+
|| news trade.mq4 |
//| Copyright © 2010, MetaQuotes Software Corp.
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, MetaQuotes Software Corp.
#property link "http://www.metaquotes.net"


extern bool In_BUYSTOP=true;
extern intProfit_buy=100;
extern int StopLoss_buy=5;
extern double Lots_buy=0.01;
//+------------------------------------------------------------------+
extern bool In_SELLSTOP =true;
extern inttern TakeProfit_sell=100;
extern int StopLoss_sell =5;
extern double Lots_sell =0.01;
extern int LevelProfit = 25; // - Profit level in points, which is necessary to reach in order to transfer its stop to the Breakeven level.
extern int LevelWLoss = 1; // - Breakeven level in points, to which the stop position will be moved after its profit reaches the LevelProfit level in points.

//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
int profitbuy=((Bid - OrderOpenPrice())/Point); // BUY
int profitsell=((OrderOpenPrice()- Ask)/Point); // SELL
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
//----
{
int ticket;
if (Bid >iHigh(NULL,PERIOD_D1,1))
{
if(OrdersTotal() < 1)
ticket=OrderSend(Symbol(),OP_SELLSTOP,Lots_sell,iHigh(NULL,PERIOD_D1,1),3,iHigh(NULL,PERIOD_D1,1)+StopLoss_sell*Point,iHigh(NULL,PERIOD_D1,1)-TakeProfit_sell*Point,Hour() == 21 && Minute() == 59)
}
if (Ask <iLow(NULL,PERIOD_D1,1))
{
if(OrdersTotal() < 1)
ticket=OrderSend(Symbol(),OP_BUYSTOP,Lots_buy,iLow(NULL,PERIOD_D1,1),3,iLow(NULL,PERIOD_D1,1)-StopLoss_buy*Point,iLow(NULL,PERIOD_D1,1)+TakeProfit_buy*Point,Hour() == 21 && Minute() == 59)
}
//oooooooooooooooooooooooooooooooooooooooooooooooooooooooo
return(0);
}
//+------------------------------------------------------------------+
if(OrderSelect(0, SELECT_BY_POS,MODE_TRADES)==true)
{
int order_type=OrderType();
order_type=OP_SELL;
int profitsell=((OrderOpenPrice()- Ask)/Point);
if (profitsell>5)
ticket=OrderModify(OrderTicket(),OrderOpenPrice(),0,OrderTakeProfit(),0,Blue);
return(0);
}
if(OrderSelect(0, SELECT_BY_POS,MODE_TRADES)==true)
{
order_type=OP_BUY;
int profitbuy=((Bid - OrderOpenPrice())/Point);
if (profitbuy>5)
int stopmodify=OrderOpenPrice();
OrderModify(OrderTicket(),OrderOpenPrice(),stopmodify,OrderTakeProfit(),0,Blue);
return(0);
}
 

Dear developers, a question for you.

I cannot get the global variable of the indicator to work correctly when calling the indicator from an Expert Advisor.

Here is the code of the indicator (only the strings that are important for understanding the question).

double  price;
double  PriceBuffer[];

int init()
{
   SetIndexBuffer(0,PriceBuffer);
   return(0);
}
int start()
{
   int limit, i;
   int counted_bars=IndicatorCounted();
   
   //---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;

   for(i=limit-1; i>=0; i--)
   {
        PriceBuffer[i] = price;
        price = iClose(NULL,0,i);
   }
   return(0);
}

At every bar it saves the current price in the global variable price and displays it on the next bar. Thus, we should see the price chart delayed by one bar. If we attach the indicator to the chart, everything works fairly:

But if this indicator is called from the EA and performs a visual test, we will see at the end of the test: the indicator is only slightly similar to what it is supposed to be.

If now we recalculate the indicator on the visual testing chart (for example, open and close its properties), everything goes back to normal - we see the first picture again.

What am I doing wrong?

I did a search, but did not find any answer.

I use MT4 Version 4.00 Build 226.

 
I think it's because there aren't enough ticks in the story. That's why it's missing. In real time everything should be clear! ;)
 

Hello, please advise where in the code there is inaccuracy, as there is such an error in the log when the script is running:

15:40:29 11dP_real_symbol EURUSD,H4: <--- 2 correct charts found. --->

15:40:29 11dP_real_symbol EURUSD,H4: <--- To see the results, open the EURUSD,M1002 chart --->

15:40:29 11dP_real_symbol EURUSD,H4: symbol name for MarketInfo function must be a string

15:40:29 11dP_real_symbol: empty string parameter for FileWriteString function

15:40:29 11dP_real_symbol EURUSD,H4: symbol name for MarketInfo function must be a string

15:40:29 11dP_real_symbol EURUSD,H4: <--- To see results, open charts,M1002 --->

15:40:29 11dP_real_symbol EURUSD,H4: the first parameter for WindowHandle function must be an initialized string

15:40:30 11dP_real_symbol EURUSD,H4: the first parameter for WindowHandle function must be an initialized string

15:40:31 11dP_real_symbol EURUSD,H4: the first parameter for WindowHandle function must be an initialized string

I am attaching the code itself below:

Files:
11dp.mq4  15 kb
 
IgorM:

what is the best way to save important data/variables in case the terminal hangs up (power failure)?

- global variables of the terminal? to a file?

- how often do they need to be saved? (the last equity value and some bools of the advisor are important)


Unlike other variables, a GV variable can not only be created from any programme, but can also be deleted. The value of the GV variable remains on the hard disk of the computer even after the client terminal is closed. Once declared GV variable exists in client terminal for 4 weeks since last call. If no program accessed the GV variable during this period, the GV variable is deleted by the client terminal. A GV variable can only be of type double.
 
etroplus:

Hello!

I can not understand why I can not modify an open position, I typed the order (in the order select function)

//+------------------------------------------------------------------+
|| news trade.mq4 |
//| Copyright © 2010, MetaQuotes Software Corp.
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, MetaQuotes Software Corp.
#property link "http://www.metaquotes.net"


extern bool In_BUYSTOP=true;
extern intProfit_buy=100;
extern int StopLoss_buy=5;
extern double Lots_buy=0.01;
//+------------------------------------------------------------------+
extern bool In_SELLSTOP =true;
extern inttern TakeProfit_sell=100;
extern int StopLoss_sell =5;
extern double Lots_sell =0.01;
extern int LevelProfit = 25; // - Profit level in points, which is necessary to reach in order to transfer its stop to the Breakeven level.
extern int LevelWLoss = 1; // - Breakeven level in points, to which the stop position will be moved after its profit reaches the LevelProfit level in points.

//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
int profitbuy=((Bid - OrderOpenPrice())/Point); // BUY is redundant, first all variables equal 0
int profitsell=((OrderOpenPrice()- Ask)/Point); // SELL
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
//----
{
int ticket;
if (Bid >iHigh(NULL,PERIOD_D1,1))
{
if(OrdersTotal() < 1)
ticket=OrderSend(Symbol(),OP_SELLSTOP,Lots_sell,iHigh(NULL,PERIOD_D1,1),3,iHigh(NULL,PERIOD_D1,1)+StopLoss_sell*Point,iHigh(NULL,PERIOD_D1,1)-TakeProfit_sell*Point,Hour() == 21 && Minute() == 59)
}
if (Ask <iLow(NULL,PERIOD_D1,1))
{
if(OrdersTotal() < 1)
ticket=OrderSend(Symbol(),OP_BUYSTOP,Lots_buy,iLow(NULL,PERIOD_D1,1),3,iLow(NULL,PERIOD_D1,1)-StopLoss_buy*Point,iLow(NULL,PERIOD_D1,1)+TakeProfit_buy*Point,Hour() == 21 && Minute() == 59)
}
//oooooooooooooooooooooooooooooooooooooooooooooooooooooooo
return(0);
}
//+------------------------------------------------------------------+
if(OrderSelect(0, SELECT_BY_POS,MODE_TRADES)==true)
{
int order_type=OrderType();
order_type=OP_SELL;//maybeif(order_type==OP_SELL), then more brackets are needed
int profitsell=((OrderOpenPrice()- Ask)/Point);
if (profitsell>5)//sowill you try to modify the order every tick?
ticket=OrderModify(OrderTicket(),OrderOpenPrice(),0,OrderTakeProfit(),0,Blue);
return(0);
}
if(OrderSelect(0, SELECT_BY_POS,MODE_TRADES)==true)
{
order_type=OP_BUY;
int profitbuy=((Bid - OrderOpenPrice())/Point);
if (profitbuy>5)
int stopmodify=OrderOpenPrice();
OrderModify(OrderTicket(),OrderOpenPrice(),stopmodify,OrderTakeProfit(),0,Blue);
return(0);
}
 
Hello, please advise where in the code there is inaccuracy, since when the script works there is such an error in the log:


15:40:29 11dP_real_symbol EURUSD,H4: <--- 2 correct charts found. --->

15:40:29 11dP_real_symbol EURUSD,H4: <--- To see the results, open the EURUSD,M1002 chart --->

15:40:29 11dP_real_symbol EURUSD,H4: symbol name for MarketInfo function must be a string

15:40:29 11dP_real_symbol: empty string parameter for FileWriteString function

15:40:29 11dP_real_symbol EURUSD,H4: symbol name for MarketInfo function must be a string

15:40:29 11dP_real_symbol EURUSD,H4: <--- To see results, open charts,M1002 --->

15:40:29 11dP_real_symbol EURUSD,H4: the first parameter for WindowHandle function must be an initialized string

15:40:30 11dP_real_symbol EURUSD,H4: the first parameter for WindowHandle function must be an initialized string

15:40:31 11dP_real_symbol EURUSD,H4: the first parameter for WindowHandle function must be an initialized string

I am attaching the code itself below:
Files:
11dp_1.mq4  15 kb
 

Please tell me what "OP BUY"-variable expected means

here while(difference>Span)
( OrderSend (string symbol, OP_BUY, volume, double price, slippage,Bid-stoploss*Point,
Bid+takeprofit*Point, string comment=NULL, int magic=0, datetime expiration=0, color arrow_color=Red) )

while(0-different>Red)
( OrderSend (string symbol, OP_SELL, volume, double price, slippage,Ask+stoploss*Point,
Ask-takeprofit*Point, string comment=NULL, string comment=0, int magic=0, datetime expiration=0, color arrow_color=Black) )

 
How do I write a point on the chart in mql4? I need to write the price and time so that it stays in place at any timeframe
Reason: