Is there anybody with more coding knowledge than myself that could help please?
I have written this indicator which does what I want when the market is trading (right side of red line) but draws in the wrong places when dropped on a chart with historical data.
There are extra buffers there that I plan to use to put an arrow on the chart when conditions are met.
/
I have written this indicator which does what I want when the market is trading (right side of red line) but draws in the wrong places when dropped on a chart with historical data.
There are extra buffers there that I plan to use to put an arrow on the chart when conditions are met.
/
Inserted Code
/+------------------------------------------------------------------+
//| Trix Continuation.mq4 |
//| Copyright 2020, Gary Hoffmann |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, Gary Hoffmann"
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 6
double TrixDiff[];
double YellowUp[];
double YellowDown[];
double GreenUp[];
double RedDown[];
double Entry[];
double FastTRIX;
double SlowTRIX;
double pips;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,TrixDiff);
SetIndexStyle(0,DRAW_NONE);
SetIndexBuffer(1,YellowUp);
SetIndexStyle(1,DRAW_ARROW,STYLE_SOLID,3,clrYellow);
SetIndexArrow(1,159);
SetIndexLabel(1,"Lower Top");
SetIndexBuffer(2,YellowDown);
SetIndexStyle(2,DRAW_ARROW,STYLE_SOLID,3,clrYellow);
SetIndexArrow(2,159);
SetIndexLabel(2,"Higher Bottom");
SetIndexBuffer(3,GreenUp);
SetIndexStyle(3,DRAW_ARROW,STYLE_SOLID,4,clrGreen);
SetIndexArrow(3,SYMBOL_ARROWUP);
SetIndexLabel(3,"Buy Signal");
SetIndexBuffer(4,RedDown);
SetIndexStyle(4,DRAW_ARROW,STYLE_SOLID,4,clrRed);
SetIndexArrow(4,SYMBOL_ARROWDOWN);
SetIndexLabel(4,"Sell Signal");
SetIndexBuffer(5,Entry);
SetIndexStyle(5,DRAW_LINE,EMPTY,2,clrYellow);
SetIndexLabel(5,"Enter If Crossed");
//---
IndicatorShortName("TrixCont");
// Determine what a pip is.
pips=Point; //.00001 or .0001. .001 .01.
if(Digits==3 || Digits==5)
pips*=10;
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
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[])
{
int limit,i;
limit=rates_total-prev_calculated;
if(!prev_calculated)
limit--;
for(i=0; i<=limit; i++)
TrixDiff[i] = (iCustom(NULL, 0, "THV4 Trix called",6,i)-iCustom(NULL,0, "THV4 Trix called",7,i));
if(!prev_calculated)
limit--;
for(i=0; i<=limit; i++)
{
{
if((TrixDiff[i+1] > 0)&&(high[i+1] < high[i+2])&&(Entry[i+2]==EMPTY_VALUE))
{
YellowUp[i+1]= (high [i+2])+0.2*pips;
Entry[i+1]=(high [i+2])+0.2*pips;
// Entry[i+1]=(high [i+1])+0.2*pips;
}
else if((TrixDiff[i+1] > 0)&&(close[i+1] < YellowUp[i+2])&&(YellowUp[i+2]!=EMPTY_VALUE))
{
YellowUp[i+1]= YellowUp[i+2];
Entry[i+1] = Entry[i+2];
}
else if((TrixDiff[i+1] > 0)&&(close[i+1] > YellowUp[i+2])&&(YellowUp[i+2]!=EMPTY_VALUE))
{
YellowUp[i+1]= EMPTY_VALUE;
Entry[i+1] = EMPTY_VALUE;
}
else if((TrixDiff[i+1] < 0)&& (low[i+1] > low[i+2])&&(Entry[i+2]==EMPTY_VALUE))
{
YellowDown[i+1]= (low [i+2])-0.2*pips;
Entry[i+1]=(low [i+2])-0.2*pips;
// Entry[i+1]=(low [i+1])-0.2*pips;
}
else if((TrixDiff[i+1] < 0)&& (close[i+1] > YellowDown[i+2])&&(YellowDown[i+2]!=EMPTY_VALUE))
{
YellowDown[i+1]= YellowDown[i+2];
Entry[i+1] = Entry[i+2];
}
else if((TrixDiff[i+1] < 0)&& (close[i+1] < YellowDown[i+2])&&(YellowDown[i+2]!=EMPTY_VALUE))
{
YellowDown[i+1]= EMPTY_VALUE;
Entry[i+1] = EMPTY_VALUE;
} }
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+