How to start with MQL5 - page 9

 
Vladimir Karputov:

is heiken ashi an indicator? Where is the link to the indicator?

it comes built-in in mt5 under custom indicators, im having trouble calling it to the expert advisor and accessing its values
 
GeorgeReji :
it comes built-in in mt5 under custom indicators , im having trouble calling it to the expert advisor and accessing its values

Example: get indicator data "Simple Heiken_Ashi.mq5"

Code: Simple Heiken_Ashi.mq5

//+------------------------------------------------------------------+
//|                                           Simple Heiken_Ashi.mq5 |
//|                              Copyright © 2019, Vladimir Karputov |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2019, Vladimir Karputov"
#property version   "1.000"
/*
   barabashkakvn Trading engine 3.025
*/
int    handle_iCustom;              // variable for storing the handle of the iCustom indicator 
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create handle of the indicator iCustom
   handle_iCustom=iCustom(Symbol(),Period(),"Examples\\Heiken_Ashi");
//--- if the handle is not created 
   if(handle_iCustom==INVALID_HANDLE)
     {
      //--- tell about the failure and output the error code 
      PrintFormat("Failed to create handle of the iCustom indicator for the symbol %s/%s, error code %d",
                  Symbol(),
                  EnumToString(Period()),
                  GetLastError());
      //--- the indicator is stopped early 
      return(INIT_FAILED);
     }
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   double heiken_ashi_open[],heiken_ashi_high[],heiken_ashi_low[],heiken_ashi_close[];
   ArraySetAsSeries(heiken_ashi_open,true);
   ArraySetAsSeries(heiken_ashi_high,true);
   ArraySetAsSeries(heiken_ashi_low,true);
   ArraySetAsSeries(heiken_ashi_close,true);
   int start_pos=0,count=3;
   if(!iGetArray(handle_iCustom,0,start_pos,count,heiken_ashi_open) || 
      !iGetArray(handle_iCustom,1,start_pos,count,heiken_ashi_high) || 
      !iGetArray(handle_iCustom,2,start_pos,count,heiken_ashi_low) || 
      !iGetArray(handle_iCustom,3,start_pos,count,heiken_ashi_close))
     {
      return;
     }
   Comment(DoubleToString(heiken_ashi_open[0],Digits()),"\n",
           DoubleToString(heiken_ashi_high[0],Digits()),"\n",
           DoubleToString(heiken_ashi_low[0],Digits()),"\n",
           DoubleToString(heiken_ashi_close[0],Digits()));
  }
//+------------------------------------------------------------------+
//| TradeTransaction function                                        |
//+------------------------------------------------------------------+
void OnTradeTransaction(const MqlTradeTransaction &trans,
                        const MqlTradeRequest &request,
                        const MqlTradeResult &result)
  {
//--- 

  }
//+------------------------------------------------------------------+
//| Get value of buffers                                             |
//+------------------------------------------------------------------+
double iGetArray(const int handle,const int buffer,const int start_pos,
                 const int count,double &arr_buffer[])
  {
   bool result=true;
   if(!ArrayIsDynamic(arr_buffer))
     {
      Print("This a no dynamic array!");
      return(false);
     }
   ArrayFree(arr_buffer);
//--- reset error code 
   ResetLastError();
//--- fill a part of the iBands array with values from the indicator buffer
   int copied=CopyBuffer(handle,buffer,start_pos,count,arr_buffer);
   if(copied!=count)
     {
      //--- if the copying fails, tell the error code 
      PrintFormat("Failed to copy data from the indicator, error code %d",GetLastError());
      //--- quit with zero result - it means that the indicator is considered as not calculated 
      return(false);
     }
   return(result);
  }
//+------------------------------------------------------------------+
Files:
 
Vladimir Karputov:

Example: get indicator data "Simple Heiken_Ashi.mq5"

Code: Simple Heiken_Ashi.mq5

Thank you for your quick responses and always providing solutions.
 
I want to use a custom template with the ChartOpen() but i do not understand how to do so, it will only open the default template when using ChartOpen function, please help
 
Ahmad861 :
I want to use a custom template with the ChartOpen() but i do not understand how to do so, it will only open the default template when using ChartOpen function , please help

Algorithm: issue the 'ChartOpen' command -> check the value, if the value is greater than '0' -> try the template using the 'ChartApplyTemplate' command.

Code: ChartOpen ChartApplyTemplate.mq5

//+------------------------------------------------------------------+
//|                                 ChartOpen ChartApplyTemplate.mq5 |
//|                              Copyright © 2020, Vladimir Karputov |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2020, Vladimir Karputov"
#property version   "1.00"
#property script_show_inputs
//--- input parameters
input string            InpSymbol   = "EURUSD";          // Chart Symbol name
input ENUM_TIMEFRAMES   Inp_period  = PERIOD_D1;         // Chart TimeFrame
input string            InpTemplate = "my_template.tpl"; // Template name
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   long chart_ID=ChartOpen(InpSymbol,Inp_period);
   if(chart_ID>0)
      ChartApplyTemplate(chart_ID,InpTemplate);
  }
//+------------------------------------------------------------------+
 
Can you help me how the logic of a bullish and bearish spinning top candlestick pattern works ?
 
GeorgeReji :
Can you help me how the logic of a bullish and bearish spinning top candlestick pattern works ?

Refine (draw a picture) your question.

 
Vladimir Karputov:

Refine (draw a picture) your question.

I've attached a picture of the candle pattern
Files:
 
GeorgeReji :
I've attached a picture of the candle pattern

In which program do you want to determine the type of candlestick: in an indicator or in an Expert Advisor?

 
Vladimir Karputov:

In which program do you want to determine the type of candlestick: in an indicator or in an Expert Advisor?

Expert Advisor
Reason: