Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 286

 
artmedia70:
At the zero bar the indicator data will not be fixed. It will practically change on every tick, as the zero bar has not yet been formed. Therefore, take data starting from the first bar. If you want to take it from the zero bar, then change PRICE_CLOSE to PRICE_OPEN - this is the only price that does not change on the zero bar, but the indicator will slightly differ from its standard representation - just a little.

It should be understood that this approach cuts off all the current dynamics - all price movements occurring on the current bar will only be "noticed" at the arrival of a new bar.
 
avtomat:

It should be understood that this approach cuts off all the current dynamics - all price movements occurring on the current bar will be "noticed" only with the arrival of a new bar.

And false positives - "chattering".

There is always a choice.

 
artmedia70:

And false positives - "chatter".

There's always a choice.



Rattling, of course, presents a definite problem. But such a solution is akin to treating a headache by truncating the head.
 
Shurkin:
The article "ShowCandleSize" published on 11.11.2013 07:54 is not displaying correctly and cannot be edited for some unknown reason.
Contacted support on November 15 with this issue at noreply@metaquotes.net, but did not receive a reply.
Can you please tell me the correct address for such a question.
Respectfully.
--
Vladislav Shurkin,
On November 20, 2013.

Give me a link to the publication to understand what it is about.
 

Can you please tell me why in the Strategy Tester the EA works, but in the demo account, even if I set a small timeframe, the EA just smiles and does not open a position?

beta version.0

extern double Minimal_lot = 1;//values:1;0.10;0.01

extern double Price_item = 10;

extern double Percent_profit = 20;

extern double Percent_risk = 20;

extern datetime time1 = D'24.11.2014 19:00';

extern double price1 = 1.3450;

extern datetime time2 = D'24.11.2014 19:00';

extern double price2 = 1.3560;

extern datetime time_close = D'24.11.2014 19:00:00';//format of time dd.mm.ggg hh:mm:ss

extern int AF = 100;

int init()

{

//----

//----

return(0);

}

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

//| expert start function |

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

int start()

{

double TP,SL,BBU,BBD,dLTU,dLTD,N;

string comment = NULL;

string LTU,LTD;

int ticket;

int DSL = ((Percent_Risk/100)*AccountBalance());

int DTP = ((Percent_Profit/100)*AccountBalance());

int Times = (Time_close/3600)-(TimeLocal())/3600;

BBU = iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_UPPER,0);

BBD = iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_LOWER,0);

N = ((AccountBalance()*(Percent_Risk/100))/(Point_price*AF))*Minimum_lot;

TP = (DSL+((Percent_Risk/100)*Times)/(Point_price*AF*(Percent_profit/100)))/Point_price;

SL = (DTP-((Percent_risk/100)*Times)/(Price_item*AF*(Percent_profit/100)))/Price_item;

if(price1<price2)

{

LTU = ObjectCreate("Trend Up",OBJ_TREND,0,time1,price1,time2);

dLTU = StrToDouble(LTU);

}

if(price1>price2)

{

LTD = ObjectCreate("TrendBack",OBJ_TREND,0,time1,price1,time2,price2);

dLTU = StrToDouble(LTD);

}

//----

if(BBU<dLTU)

{

ticket=OrderSend(Symbol(),OP_SELL,N,Bid,3,Bid+SL*Point,Ask-TP*Point,comment,365,Green);

}

if(Closing time==true)

{

OrderClose(OrderTicket(),OrderLots(),Ask,10);

}

if(BBD>dLTD)

{

ticket=OrderSend(Symbol(),OP_BUY,N,Ask,3,Bid-SL*Point,Ask+TP*Point,comment,367,Green);

}

if(Closing time==true)

{

OrderClose(OrderTicket(),OrderLots(),Bid,10);

}

return(0);

Files:
freedom.mq4  3 kb
 

Good afternoon all!

Please advise .

PROBLEM

- for real trading in the terminal there are 2 identical charts EUR-USD timeframe - 5 min.

I NEED THAT

- the number of candlesticks in these charts was different (for example - in the graph N1 - 500 bars, the graph N2- 600 bars)

I've deleted candlesticks through the window ARCHIVE QUOTES ..... but they are deleted simultaneously in both charts (I need only one)

Q1. Is it possible to have two identical charts with different number of candlesticks?

Q2 If it is possible to trade on two identical charts with different number of bars, how to format the code.


if (T == true ) // if condition for chart N1 has been fulfilled ( how can we specify that this condition concerns chart N1???)

OrderSend(Symbol(),OP_BUY,0.1,Ask,1,Bid-4710*Point,Bid+300*Point, "jfh",1); // open the order( how do we specify that this order should be opened in the N1 chart ???)

if ( S == true ) // if the condition for chart N2 has been met ( how should we specify that this condition refers to the N2chart ???)

OrderSend(Symbol(),OP_BUY,0.1,Ask,1,Bid-4710*Point,Bid+300*Point, "jfh",1); // open the order ( how do we specify that this order should be opened in the N2 chart???)

Thank you.

 

How can I add price selection to custom indicator? As an example - "Custom Moving Averages", the price in the code is set everywhere Close, although in the standard indicator "Moving Average" you can select a price from the list. This is the same for all indicators with open code from MT4 delivery.



 
evillive:

How can I add price selection to custom indicator? As an example - "Custom Moving Averages", the price in the code is set everywhere Close, although in the standard indicator "Moving Average" you can select a price from the list. This is the same for all indicators with open code from MT4 delivery.

You need to add to the code in this situation. You create an external variable, for example Appled_Price.

And you change all PRICE_CLOSE into Appled_Price in the code.

The Appled_Price values can be within:

Constant Value Description
PRICE_CLOSE 0 Closing price
PRICE_OPEN 1 Opening price
PRICE_HIGH 2 Maximum price
PRICE_LOW 3 Minimum price
PRICE_MEDIAN 4 Average price, (high+low)/2
PRICE_TYPICAL 5 Typical price, (high+low+close)/3
PRICE_WEIGHTED 6 Weighted closing price, (high+low+close+close)/4
 
solnce600:

Good afternoon all!

Can you please tell me .

I NEED THAT

- the number of candlesticks on these charts was different (for example on the chart N1 - 500 bars, on the chart N2- 600 bars)

Thank you.

Can you explain why you need it? I do not understand the sense of this mystery. Does the profit depend on it?

 
artmedia70:

You need to add to the code in this situation. Create an external variable, e.g. Appled_Price.

And you change all PRICE_CLOSE in the code to Appled_Price.


Ah, yes, sorry, I meant the new builds, and there's a little unusual code.

That's the thing, the code has no free-form price, everything is in arrays, you just can't change it, I've tried it (((

And if it worked, how to make a selection from a drop-down list (like in the picture from my question)?


//+------------------------------------------------------------------+
//|                                       Custom Moving Averages.mq4 |
//|                   Copyright 2005-2013, MetaQuotes Software Corp. |
//|                                              https://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright   "2005-2013, MetaQuotes Software Corp."
#property link        "https://www.mql4.com"
#property description "Moving Average"

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Red
//--- indicator parameters
input int            InpMAPeriod=13;        // Period
input int            InpMAShift=0;          // Shift
input ENUM_MA_METHOD InpMAMethod=MODE_SMA;  // Method
//--- indicator buffer
double ExtLineBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
  {
   string short_name;
   int    draw_begin=InpMAPeriod-1;
//--- indicator short name
   switch(InpMAMethod)
     {
      case MODE_SMA  : short_name="SMA(";                break;
      case MODE_EMA  : short_name="EMA(";  draw_begin=0; break;
      case MODE_SMMA : short_name="SMMA(";               break;
      case MODE_LWMA : short_name="LWMA(";               break;
      default :        return(INIT_FAILED);
     }
   IndicatorShortName(short_name+string(InpMAPeriod)+")");
   IndicatorDigits(Digits);
//--- check for input
   if(InpMAPeriod<2)
      return(INIT_FAILED);
//--- drawing settings
   SetIndexStyle(0,DRAW_LINE);
   SetIndexShift(0,InpMAShift);
   SetIndexDrawBegin(0,draw_begin);
//--- indicator buffers mapping
   SetIndexBuffer(0,ExtLineBuffer);
//--- initialization done
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//|  Moving Average                                                  |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//--- check for bars count
   if(rates_total<InpMAPeriod-1 || InpMAPeriod<2)
      return(0);
//--- counting from 0 to rates_total
   ArraySetAsSeries(ExtLineBuffer,false);
   ArraySetAsSeries(close,false);
//--- first calculation or number of bars was changed
   if(prev_calculated==0)
      ArrayInitialize(ExtLineBuffer,0);
//--- calculation
   switch(InpMAMethod)
     {
      case MODE_EMA:  CalculateEMA(rates_total,prev_calculated,close);        break;
      case MODE_LWMA: CalculateLWMA(rates_total,prev_calculated,close);       break;
      case MODE_SMMA: CalculateSmoothedMA(rates_total,prev_calculated,close); break;
      case MODE_SMA:  CalculateSimpleMA(rates_total,prev_calculated,close);   break;
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//|   simple moving average                                          |
//+------------------------------------------------------------------+
void CalculateSimpleMA(int rates_total,int prev_calculated,const double &price[])
  {
   int i,limit;
//--- first calculation or number of bars was changed
   if(prev_calculated==0)
   
     {
      limit=InpMAPeriod;
      //--- calculate first visible value
      double firstValue=0;
      for(i=0; i<limit; i++)
         firstValue+=price[i];
      firstValue/=InpMAPeriod;
      ExtLineBuffer[limit-1]=firstValue;
     }
   else
      limit=prev_calculated-1;
//--- main loop
   for(i=limit; i<rates_total && !IsStopped(); i++)
      ExtLineBuffer[i]=ExtLineBuffer[i-1]+(price[i]-price[i-InpMAPeriod])/InpMAPeriod;
//---
  }
//+------------------------------------------------------------------+
//|  exponential moving average                                      |
//+------------------------------------------------------------------+
void CalculateEMA(int rates_total,int prev_calculated,const double &price[])
  {
   int    i,limit;
   double SmoothFactor=2.0/(1.0+InpMAPeriod);
//--- first calculation or number of bars was changed
   if(prev_calculated==0)
     {
      limit=InpMAPeriod;
      ExtLineBuffer[0]=price[0];
      for(i=1; i<limit; i++)
         ExtLineBuffer[i]=price[i]*SmoothFactor+ExtLineBuffer[i-1]*(1.0-SmoothFactor);
     }
   else
      limit=prev_calculated-1;
//--- main loop
   for(i=limit; i<rates_total && !IsStopped(); i++)
      ExtLineBuffer[i]=price[i]*SmoothFactor+ExtLineBuffer[i-1]*(1.0-SmoothFactor);
//---
  }
//+------------------------------------------------------------------+
//|  linear weighted moving average                                  |
//+------------------------------------------------------------------+
void CalculateLWMA(int rates_total,int prev_calculated,const double &price[])
  {
   int        i,limit;
   static int weightsum;
   double     sum;
//--- first calculation or number of bars was changed
   if(prev_calculated==0)
     {
      weightsum=0;
      limit=InpMAPeriod;
      //--- calculate first visible value
      double firstValue=0;
      for(i=0;i<limit;i++)
        {
         int k=i-1;
         weightsum+=k;
         firstValue+=k*price[i];
        }
      firstValue/=(double)weightsum;
      ExtLineBuffer[limit-1]=firstValue;
     }
   else
      limit=prev_calculated-1;
//--- main loop
   for(i=limit; i<rates_total && !IsStopped(); i++)
     {
      sum=0;
      for(int j=0;j<InpMAPeriod;j++)
         sum+=(InpMAPeriod-j)*price[i-j];
      ExtLineBuffer[i]=sum/weightsum;
     }
//---
  }
//+------------------------------------------------------------------+
//|  smoothed moving average                                         |
//+------------------------------------------------------------------+
void CalculateSmoothedMA(int rates_total,int prev_calculated,const double &price[])
  {
   int i,limit;
//--- first calculation or number of bars was changed
   if(prev_calculated==0)
     {
      limit=InpMAPeriod;
      double firstValue=0;
      for(i=0; i<limit; i++)
         firstValue+=price[i];
      firstValue/=InpMAPeriod;
      ExtLineBuffer[limit-1]=firstValue;
     }
   else
      limit=prev_calculated-1;
//--- main loop
   for(i=limit; i<rates_total && !IsStopped(); i++)
      ExtLineBuffer[i]=(ExtLineBuffer[i-1]*(InpMAPeriod-1)+price[i])/InpMAPeriod;
//---
  }
//+------------------------------------------------------------------+