[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 537

 
chief2000:

Here's a question.
Can I know from the code of a custom indicator whether the window in which it is running is currently active or not?
For example, the same Indicator is running in two windows - you need it to work only in the window which chart is active and inactive in the second window.

Thank you!

Once again the library helps :-)
 
Zhunko:
Again the library helps :-)
Thank you!
 
Good evening! I've started a quick rollover of the robot here, and even suddenly without errors procamped, and lo and behold, it suddenly opens two orders at once!!! That is, one order at a time, on the first and second tick. Here is the code, I will paste it below. The BUY variable is the number of buy orders that have already been opened and if it is above zero, even one order exists, then it should not open.
//+------------------------------------------------------------------+
//|                                                        антиб.mq4 |
//|                      Copyright © 2012, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2012, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

extern double volume=0.01;extern double stoploss=12,takeprofit=12;extern int magic=50001,I=5;
int ticket;double volumee ; 
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   volumee=volume;
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
        
int start()
  {   int BUY;
  
//----

 for( int i=OrdersHistoryTotal() -1;i>=0;i--){
    OrderSelect(i,SELECT_BY_POS,MODE_HISTORY); if (OrderMagicNumber( )== magic) { if(OrderSymbol()== Symbol()) {
      if(OrderType()==OP_BUY ) {   if ((OrderProfit( )-3*Point) <  OrderTakeProfit( ) && (OrderProfit( )+3*Point) >  OrderTakeProfit( ) ) { if( OrderTicket( ) == ticket ) {
               volumee = volumee+volumee;}}}}}}
if (volumee>volume*I){volumee=volume;}


              for ( i=OrdersTotal()-1;i>=0;i--)
   {
    if (OrderSelect(i, SELECT_BY_TICKET ) == true)    Alert ("Select error ", GetLastError( ) ) ;
     if(OrderMagicNumber( )== magic){
      if(OrderSymbol()== Symbol()) {
      if(OrderType()==OP_BUY ) {
                             BUY++;}}}}   
 if(BUY==0){

 ticket= OrderSend( Symbol(), OP_BUY, volumee, NormalizeDouble(( Ask),Digits),NormalizeDouble(( Point*3),Digits) , NormalizeDouble(( Ask-stoploss*Point),Digits), NormalizeDouble(( Ask+takeprofit*Point),Digits), NULL,  magic, 0, Red) ;}
 
 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
 
Here, two warrants! !
 

Do you know, maybe I've been fiddling with the for loop, there is one order, I minus one more and the loop condition is not fulfilled at all. Yes, yes, it looks like, and there are exactly two orders opening!

People, should I delete my last comments?

No, I still have two, and after the third or fourth tick Alert: Select error 4105 writes,

It seems that the order has not been selected and there is no error at first... This is correct for( int i=0;i<=OrdersHistoryTotal();i++){

and so for( int i=0;i<=OrdersTotal();i++){

And there are two orders all the same.

That's it, one. Phew. ;


 
Error 4105-order not selected-does not go away, but generally works adequately
 
Ivn:

Good afternoon how to write a standard advisor for another timeframe. I.e. put this indicator on the 1 hour chart which will show the 4 hour indicator.

пытался //+------------------------------------------------------------------+
//| vv at 4 o'clock.mq4 |
//| Copyright © 2012, MetaQuotes Software Corp. |
//| https://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2012, MetaQuotes Software Corp."
#property link "https://www.metaquotes.net/"

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 LightSeaGreen
#property indicator_color2 LightSeaGreen
#property indicator_color3 LightSeaGreen
//---- indicator parameters
extern int BandsPeriod=20;
extern inttern BandsShift=0;
extern double BandsDeviations=2.0;
//---- buffers
double MovingBuffer[];
double UpperBuffer[];
double LowerBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialisation function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,MovingBuffer);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,UpperBuffer);
SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(2,LowerBuffer);
//----
SetIndexDrawBegin(0,BandsPeriod+BandsShift);
SetIndexDrawBegin(1,BandsPeriod+BandsShift);
SetIndexDrawBegin(2,BandsPeriod+BandsShift);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Bollinger Bands |
//+------------------------------------------------------------------+
int start()
{
int i,k,counted_bars=IndicatorCounted();
double deviation;
double sum,oldval,newres;
int B=iBars( NULL,PERIOD_H4);
double C=iClose(NULL,PERIOD_H4,0);
//----
if(B <=BandsPeriod) return(0);
//---- initial zero
if(counted_bars<1)
for(i=1;i<=BandsPeriod;i++)
{
MovingBuffer[B-i]=EMPTY_VALUE;
UpperBuffer[B-i]=EMPTY_VALUE;
LowerBuffer[B-i]=EMPTY_VALUE;
}
//----
int limit=B-counted_bars;
if(counted_bars>0) limit++;
for(i=0; i<limit; i++)
MovingBuffer[i]=iMA(NULL,PERIOD_H4,BandsPeriod,BandsShift,MODE_SMA,PRICE_CLOSE,i);
//----
i=B-BandsPeriod+1;
if(counted_bars>BandsPeriod-1) i=B-counted_bars-1;
while(i>=0)
{
sum=0.0;
k=i+BandsPeriod-1;
oldval=MovingBuffer[i];
while(k>=i)
{
newres=C[k]-oldval;
sum+=newres*newres;
k--;
}
deviation=BandsDeviations*MathSqrt(sum/BandsPeriod);
UpperBuffer[i]=oldval+deviation;
LowerBuffer[i]=oldval-deviation;
i--;
}
//----
return(0);
}
//+------------------------------------------------------------------+

did not work

this newres=C[k]-oldval;- '[' - unexpected token

The Bollinger Bands indicator.


Instead of C[k] insert iClose(NULL,PERIOD_H4,k);

However, I have obtained a way to display the 1 o'clock chart and the 4 o'clock line in a more natural way.
When I translate this code to a chart, I see price leaving the channel; it seems that the Bollinger Band chart at 4 o'clock is not connected to the time line

thanks in advance

 

Guys, can you tell me from experience... Picked a company to rent VPS for trading via MT4 client terminal, I'm interested in how much traffic on average consumes one running terminal, for example, with ten sops? There will be several terminals running... So that I can choose the appropriate data plan from the offered ones:

P.S. They have a rate based on total traffic, i.e. incoming + outgoing.

 

Colleagues, who knows answer:

I have a strategy tester on the same time frame (01.05.2011 - 27.01.2012), EURUSD currency pair, on hour bars (H1), from one DC (Alpari), and the same advisor, but on different computers (laptop, desktop) gives opposite results! On the PC - $2000, on the laptop +3000. And there, and there checked on 2-3 times.

Please advise the cause and what to do and / or give me a link where that on the topic can be read.
 
Sersad:

Colleagues, who knows the answer:

I have a strategy tester on the same time interval (01.05.2011 - 27.01.2012), the currency pair EURUSD, on the hour bars (H1), from one DC (Alpari), and the same Expert Advisor, but on different computers (laptop, desktop) gives opposite results! On the PC - $2000, on the laptop +3000. And there, and there checked on 2-3 times.

Please advise the cause and what to do and / or give me a link where that on the topic can be read.


I've been caught up in this myself once... had a similar: 1st terminal was installed with Metacquotes, 2nd with Alparey, history also accordingly, there were significant discrepancies when testing the same owl, couldn't figure out what was wrong for a long time.

1. Download the terminals from Alpari. Download the Alpari quote history for the instrument and this window will appear:

If it does not pop up after pressing F2 followed by "Download", then you are downloading the history of the instrument. If you do not see this window popping up after pressing F2 followed by "Download", you will not be downloading the price history from Alpari.

2. In the Strategy Tester set all of the options equal + check the spread by clicking on the "Symbol Properties" button. Check the spread values in the strategy tester by clicking on the "Symbol properties" button.

Before you do that - wipe and reload the quotes history for the instrument you are interested in + check the testing period: in the screenshot H4 - so that it is the same in both cases.