Signal bar indicator. Which bar should you take a signal from? Drawing indicators.

Signal bar indicator. Which bar should you take a signal from? Drawing indicators.

Exp – Swing strategy (Pendulum). Automatic opening of 2 opposite pending orders, OCO orders.
Metatrader Error Codes – MQL error codes received by the trading expert in the terminal. Solutions.
Exp – Swing strategy (Pendulum). Automatic opening of 2 opposite pending orders, OCO orders.
Metatrader Error Codes – MQL error codes received by the trading expert in the terminal. Solutions.

Description

Let’s look at examples of the operation of indicators that draw and do not draw. 

Difference of signals during programming. Using the shift parameter

In order to better understand the operation of indicators, it is useful to examine examples of indicators that draw and those that do not draw.

Indicators that draw are those that plot on the price chart, while those that do not draw simply display their output in a separate window.

The difference in signals between these two types of indicators can be significant, so it is important to understand how they work when programming trading strategies.

One way to adjust the behavior of indicators is by using the shift parameter, which allows you to shift the indicator output forward or backward in time.

By experimenting with different values of the shift parameter, you can fine-tune your indicators to better match your trading strategy and improve your chances of success in the markets.

Foreword

This article was written at the request of our friends.

When ordering an advisor programming, you can adjust the signal bar in all my advisors. 

Quite often on the Internet, you can find complaints that some Expert Advisors do not work correctly based on indicators. 

I will try to talk in detail about such signals and prove the opposite: all indicators draw, and they must be used correctly. 

There is a video version in this article, but before watching the video, I still recommend reading the text version. 

shift (0,1,2…..) Bar number

This parameter represents the number of the Bar from which your indicators will take a signal. When ordering an Expert Advisor, you must specify the following signal definition parameters: Open a deal immediately after the signal, or wait until the signal is formed on a closed bar and open a deal only at the opening of the next Bar. Due to their algorithms, some indicators have a clear definition: on which bar is the signal given? If we talk about the clarity and correct execution of the order, then the deal must be processed only on a closed bar, i.e., parameter shift=1. If it is necessary to open a DEAL immediately upon the occurrence of a signal on the current Bar and the indicator allows this, it is required to set shift=0. 

Expert Advisor

The EA is written using our template for writing an EA. All functions of the advisor are described on this page:  Forex advisor functions

You can download the package from the link  Signal bar testing package

1. Moving Average indicator

The standard indicator of the MT4 terminal has the averaging period, averaging prices, and the type of averaging in the settings. 

Trading strategy: Crossover of averages. The intersection of slow MA and fast MA

Strategy code:

double ExampleMA=iMA(Symbol(),0,20,0,MODE_SMA,PRICE_CLOSE,shift); // MA Call Example      
double ExampleMA2=iMA(Symbol(),0,50,0,MODE_SMA,PRICE_CLOSE,shift); // MA Call Example      
double ExampleMA23=iMA(Symbol(),0,20,0,MODE_SMA,PRICE_CLOSE,shift+1); // MA Call Example      
double ExampleMA22=iMA(Symbol(),0,50,0,MODE_SMA,PRICE_CLOSE,shift+1); // MA Call Example

      if(ExampleMA23<ExampleMA22 && ExampleMA>ExampleMA2)Sig=1;
      if(ExampleMA23>ExampleMA22 && ExampleMA<ExampleMA2)Sig=2;

     

Examples of work with shift = 0 

Examples of work with shift = 1

Explanation: This indicator, in principle, does not draw so that it can be used with any shift. 

Video example :

https://youtube.com/watch?v=E3EPbBWn8ik%3Fstart%3D288

2. Indicator cross

A custom indicator based on the MA crossing strategy + some chips. Draws strongly with cunning. Those. Crossing 1 bar draws an arrow at 0 bar and constantly redraws it. 

Trading strategy:  Arrow trading

Strategy code:

int Sig=0;
   if(shift!=-1)
     {
      double UP=iCustom(Symbol(),0,"cross",0,shift);
      double DN=iCustom(Symbol(),0,"cross",1,shift);
     }
   if(shift==-1)
      for(int i=1;i<=100;i++)
        {
         UP=iCustom(Symbol(),0,"cross",0,i);
         DN=iCustom(Symbol(),0,"cross",1,i);
         if(UP!=EMPTY_VALUE || DN!=EMPTY_VALUE)break;

        }

   if(UP!=EMPTY_VALUE){Sig=1;}
   if(DN!=EMPTY_VALUE){Sig=2;}

Examples of work with shift = 0 

Examples of work with shift = 1

Examples of work with shift = -1

Explanation:  This indicator draws strongly, and the developer deliberately redraws the signal. Therefore, it is dangerous to use this indicator as a signal indicator. 

Video example :

https://youtube.com/watch?v=E3EPbBWn8ik%3Fstart%3D464

3. CurrencyPowerMeter indicator

A custom indicator that measures the strength of currencies. This indicator works on objects, so shift doesn’t matter. the trading strategy for this indicator is based on pulling the value not from the indicator buffer but from the indication of the object on the chart

Trading strategy:  Trading the difference between currency strengths

Strategy code:

double EUR_HOUR[1];
   double GBP_HOUR[1];
   double AUD_HOUR[1];
   double NZD_HOUR[1];
   double USD_HOUR[1];
   double CAD_HOUR[1];
   double CHF_HOUR[1];
   double JPY_HOUR[1];

   double PervayaValuta;
   double VtorayaValuta;
   string note=" Authentication SETTINGS ==";
   string username = "";
   string password = "";
   double trend;
   string DATATRend;

   trend=iCustom(Symbol(),0,"CurrencyPowerMeter",0,0);

   EUR_HOUR[0]=StringToDouble(ObjectDescription("CPMEUR_Str_h"));
   GBP_HOUR[0]=StringToDouble(ObjectDescription("CPMGBP_Str_h"));
   AUD_HOUR[0]=StringToDouble(ObjectDescription("CPMAUD_Str_h"));
   NZD_HOUR[0]=StringToDouble(ObjectDescription("CPMNZD_Str_h"));
   USD_HOUR[0]=StringToDouble(ObjectDescription("CPMUSD_Str_h"));
   CAD_HOUR[0]=StringToDouble(ObjectDescription("CPMCAD_Str_h"));
   CHF_HOUR[0]=StringToDouble(ObjectDescription("CPMCHF_Str_h"));
   JPY_HOUR[0]=StringToDouble(ObjectDescription("CPMJPY_Str_h"));

   if(StringSubstr(Symbol(),0,3)=="USD")PervayaValuta=USD_HOUR[0];
   if(StringSubstr(Symbol(),0,3)=="GBP")PervayaValuta=GBP_HOUR[0];
   if(StringSubstr(Symbol(),0,3)=="EUR")PervayaValuta=EUR_HOUR[0];
   if(StringSubstr(Symbol(),0,3)=="AUD")PervayaValuta=AUD_HOUR[0];
   if(StringSubstr(Symbol(),0,3)=="NZD")PervayaValuta=NZD_HOUR[0];
   if(StringSubstr(Symbol(),0,3)=="CAD")PervayaValuta=CAD_HOUR[0];
   if(StringSubstr(Symbol(),0,3)=="CHF")PervayaValuta=CHF_HOUR[0];
   if(StringSubstr(Symbol(),0,3)=="JPY")PervayaValuta=JPY_HOUR[0];

   if(StringSubstr(Symbol(),3,3)=="USD")VtorayaValuta=USD_HOUR[0];
   if(StringSubstr(Symbol(),3,3)=="GBP")VtorayaValuta=GBP_HOUR[0];
   if(StringSubstr(Symbol(),3,3)=="EUR")VtorayaValuta=EUR_HOUR[0];
   if(StringSubstr(Symbol(),3,3)=="AUD")VtorayaValuta=AUD_HOUR[0];
   if(StringSubstr(Symbol(),3,3)=="NZD")VtorayaValuta=NZD_HOUR[0];
   if(StringSubstr(Symbol(),3,3)=="CAD")VtorayaValuta=CAD_HOUR[0];
   if(StringSubstr(Symbol(),3,3)=="CHF")VtorayaValuta=CHF_HOUR[0];
   if(StringSubstr(Symbol(),3,3)=="JPY")VtorayaValuta=JPY_HOUR[0];

   if(PervayaValuta-VtorayaValuta>0)return(1);   
if(PervayaValuta-VtorayaValuta<0)return(2);   return(0);

Work examples

Explanation:  This indicator does not have indicator buffers and is based on objects. Therefore, the signal bar does not matter. Such indicators cannot be tested or optimized. Work only in real-time. 

Video example :

https://youtube.com/watch?v=E3EPbBWn8ik%3Fstart%3D683

4. Fiji Trend Indicator

A custom indicator that works on MA and ATR signals in the form of arrows does not draw the indicator, but with a little trick, the indicator takes data from closed bars but puts an arrow on the current 0 bar. It’s an illusion of deceit. 

Trading strategy:  trading on the arrows of the indicator

Strategy code:

int Sig=0;

double DNSignal=iCustom(Symbol(),0,"Fiji Trend",3,shift); // An example of calling a custom indicator   
double UPSignal=iCustom(Symbol(),0,"Fiji Trend",2,shift); // An example of calling a custom indicator   
double DNTrend=iCustom(Symbol(),0,"Fiji Trend",1,shift); // An example of calling a custom indicator   
double UPTrend=iCustom(Symbol(),0,"Fiji Trend",0,shift); // An example of calling a custom indicator

                                                            //Specify Signals for opening:   
if( UPSignal!=EMPTY_VALUE)Sig=1;   if( DNSignal!=EMPTY_VALUE)Sig=2;

Examples of work with shift = 0 

Examples of work with shift = 1

Explanation:  This indicator does not draw. But he puts signals with the trick that I indicated above. One of the few indicators that gives reasonably good signals

Video example :

https://youtube.com/watch?v=E3EPbBWn8ik%3Fstart%3D780

5. Fisher indicator

A custom indicator that works on  Hi-Lo bars and calculates a signal based on its formulas. Draws as shown by the tests. Redraws 3-5 bars on closed bars. made in the form of a histogram

Trading strategy:  histogram trading. Histogram crossing 0 marks

Strategy code:

int Sig=0;

   double DNSignal=iCustom(Symbol(),0,"Fiji Trend",3,shift); // An example of calling a custom indicator

   double Fisher1=iCustom(Symbol(),0,"fisher",0,shift);
   double Fisher2=iCustom(Symbol(),0,"fisher",0,shift);

   if( Fisher1>0 && Fisher2>0 ){Sig=1; }
   if( Fisher1<0 && Fisher2<0 ){Sig=2;}

// 1 - buy 2 - sell   

return(Sig);

Examples of work with shift = 0 

Examples of work with shift = 1

Explanation:  This indicator draws, so I do not recommend taking signals from it.

Video example :

https://youtube.com/watch?v=E3EPbBWn8ik%3Fstart%3D887

6. HMA color indicator

A custom indicator that works on  MA and calculates a signal based on its formulas.

Trading Strategy:  Color Change Trading

Strategy code:

int Sig=0;

   double HMARED=iCustom(Symbol(),0,"HMA Color",3,shift);
   double HMAGREEN=iCustom(Symbol(),0,"HMA Color",1,shift);

   double HMARED2=iCustom(Symbol(),0,"HMA Color",3,shift+1);
   double HMAGREEN2=iCustom(Symbol(),0,"HMA Color",1,shift+1);

//Specify Signals for opening:   
if(HMAGREEN!=EMPTY_VALUE && HMAGREEN2==EMPTY_VALUE)Sig=1;   
if(HMARED!=EMPTY_VALUE && HMARED2==EMPTY_VALUE)Sig=2;

Examples of work with shift = 0 

Examples of work with shift = 1

Explanation:  This indicator builds its signal based on a single line on the chart. The line changes color, so to take a signal, you need to calculate the color change of the line.

Video example :

https://youtube.com/watch?v=E3EPbBWn8ik%3Fstart%3D1039

7. MACD indicator

Standard MT terminal indicator. 

Trading strategy:  trading on the intersection of the signal line and the histogram

Strategy code:

int Sig=0;

   double MACD_SIGNAL1=iMACD(Symbol(),0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,shift); //MA Call Example   

double MACD_SIGNAL2=iMACD(Symbol(),0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,shift+1); //MA Call Example

   double MACD_MAIN1=iMACD(Symbol(),0,12,26,9,PRICE_CLOSE,MODE_MAIN,shift); //MA Call Example   

double MACD_MAIN2=iMACD(Symbol(),0,12,26,9,PRICE_CLOSE,MODE_MAIN,shift+1); //MA Call Example

   if(MACD_SIGNAL2<MACD_MAIN2 && MACD_SIGNAL1>MACD_MAIN1)Sig=1;
   if(MACD_SIGNAL2>MACD_MAIN2 && MACD_SIGNAL1<MACD_MAIN1)Sig=2;

Examples of work with shift = 0 

Examples of work with shift = 1

Explanation:  This indicator does not redraw on 1 closed bar, so you can freely use shift=1

Video example :

https://youtube.com/watch?v=E3EPbBWn8ik%3Fstart%3D1195

8. ZIGZAG indicator

Standard MT terminal indicator. Builds tops and bottoms on the high-low of a specific area.

Trading strategy:  trade on the formation of tops and bottoms. It is not recommended to play on the indicator with positions. That’s a good limit strategy.

Strategy code:

int Sig=0;

double PriceZZ1=GetExtremumZZPrice(Symbol(),0,1);   
double PriceZZ2=GetExtremumZZPrice(Symbol(),0,2);

   double priceUP,priceDN;

   if(PriceZZ2>PriceZZ1 ){priceUP=PriceZZ2;priceDN=PriceZZ1;Sig=2;}   if(PriceZZ2<PriceZZ1 ){priceUP=PriceZZ1;priceDN=PriceZZ2;Sig=1;}

Examples of work with shift = 0 

Explanation:  This indicator draws tops and bottoms, so shift doesn’t matter. The unique conditions of the strategy allow trading on this indicator quite successfully.

Video example :

https://youtube.com/watch?v=E3EPbBWn8ik%3Fstart%3D1316

9. Work on request

Work at the usual bars of the MT terminal. 

Trading strategy:  If the Bar is bullish, open a buy; if the Bar is bearish, open a sell. 

Strategy code:

int Sig=0;

   if(Open[shift]<Close[shift])Sig=1;
   if(Open[shift]>Close[shift])Sig=2;

Examples of work with shift = 0 

Examples of work with shift = 1

Explanation: A perfect example of how the shift parameter works, showing how you can play strategies for this parameter

Video example :

https://youtube.com/watch?v=E3EPbBWn8ik%3Fstart%3D1473

Conclusions

This informative article provides helpful examples of using various indicators with different values of the shift parameter. Each indicator is unique; thus, when creating an Expert Advisor, the type of indicator and its signal must be taken into account. Before hiring a programmer to create an Expert Advisor, it is important to first test your indicator for any potential issues with redrawing. This is crucial since the reliability and effectiveness of your robot’s trades will depend on the accuracy of your indicator. Therefore, it is recommended that you thoroughly check and test your indicator before proceeding with the creation of your Expert Advisor.

Advisor

The EA is written using our template for writing an EA

All advisor functions are described on this page: Forex advisor functions.

If you want to create an alert for your indicator, please read our article:

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

This website uses cookies to improve your experience. By using this website you agree to our Data Protection Policy.
Read more