Hola, I have some trouble finding the correct Logic.
With this indicator I want to get a candle body that is X amount bigger than the previous (Works so far) and draw a line at the open price (also works). Now if the price crosses any of the lines, i would like to change its color and stop it from drawing once it's hit.
This last part is where most of my trouble sits. Right now it's obviously changing colors, but not the way I want. I am lost finding the right logic. i.e where and how to check and save if it has been hit.
Any help is greatly apreciated.
Here is the code:
#property indicator_chart_window#property indicator_buffers2#property indicator_color1 Green
#property indicator_color2 Red
externbool DrawArrows = true;
externint TimeFrame = 0;
externdouble CandleFactor = 1.8 ; // Min Candle Factorexterndouble CandleMinPip = 20 ; // Min Pips to show Candle (in pts)externint CountBars = 24;
externcolor Linecolor = Blue;
externcolor LinecolorHit = Red;
externint Width = 0;
externint ShiftLineRightBars = 6 ;
double Up[], Down[], EntryPriceArray[], OpenPriceArray[];
double close2, open2, close1, open1, pips1, pips2, EntryPrice, OpenPrice;
string can2, can1, label, period;
int i;
//+------------------------------------------------------------------+int init()
{
SetIndexBuffer(0,Up);
SetIndexBuffer(1,Down);
if(DrawArrows){SetIndexStyle(0,DRAW_ARROW);}else{SetIndexStyle(0,DRAW_NONE);}
if(DrawArrows){SetIndexStyle(1,DRAW_ARROW);}else{SetIndexStyle(1,DRAW_NONE);}
SetIndexArrow(0,233);
SetIndexArrow(1,234);
CandleMinPip = CandleMinPip*Point;
if (Period() == 1){period = "M1"; Width = 1; ShiftLineRightBars = ShiftLineRightBars + 5;}
if (Period() == 5){period = "M5"; Width = 2; ShiftLineRightBars = ShiftLineRightBars + 3;}
if (Period() == 15){period = "M15"; Width = 2; ShiftLineRightBars = ShiftLineRightBars + 2;}
if (Period() == 30){period = "M30"; Width = 3;}
if (Period() == 60){period = "H1"; Width = 3;}
if (Period() == 240){period = "H4"; Width = 4;}
if (Period() == 1440){period = "D1"; Width = 5;}
return(0);
}
//+------------------------------------------------------------------+int deinit()
{ if (CountBars == 0) {CountBars=Bars;}
for( i = 0; i < CountBars; i++) {
ObjectDelete("Line_"+period+"_"+Time[i+1]);
}
return(0);
}
//+------------------------------------------------------------------+int start() {
if (CountBars == 0) {CountBars=Bars;}
for( i = 0; i < CountBars; i++){
close1=iClose(NULL,TimeFrame,i+1);
close2=iClose(NULL,TimeFrame,i+2);
open1=iOpen(NULL,TimeFrame,i+1);
open2=iOpen(NULL,TimeFrame,i+2);
pips1 = (MathAbs(open1-close1));
pips2 = (MathAbs(open2-close2));
if ( pips1 > CandleMinPip){
if ( pips1 > pips2*CandleFactor){
int CandleTime = Time[i+1]; // Get the Candle time of Candle i+1// int CandleTimeClose = CandleTime+(Period()*60*ShiftLineRightBars);int CandleTimeClose = Time[0];
label = "Line_"+period+"_"+Time[i+1];
if (open1-close1 < 0){ // Candle 1 is Bullish
Up[i+1]=iLow(NULL,TimeFrame,i+1);
EntryPrice = iHigh(NULL,TimeFrame,i+1);
}
if (open1-close1 > 0){ // Candle 1 is Bearish
Down[i+1]=iHigh(NULL,TimeFrame,i+1);
EntryPrice = iLow(NULL,TimeFrame,i+1);
}
OpenPrice = iOpen(NULL,TimeFrame,i+1); // Open Price of BiggerCandleObjectCreate(label, OBJ_TREND, 0, CandleTime, OpenPrice, CandleTimeClose, OpenPrice, 0, 0);
ObjectSet(label, OBJPROP_RAY, 0);
ObjectSet(label, OBJPROP_COLOR, Linecolor);
ObjectSet(label, OBJPROP_WIDTH, Width);
ObjectSet(label, OBJPROP_STYLE, 0);
if (open1-close1 > 0 && Bid > OpenPrice) { // If Bid crosses/is above the OpenPrice, Change Line Color and Change CandleTimeCloseObjectSet(label, OBJPROP_COLOR, LinecolorHit);
CandleTimeClose = TimeCurrent();
ObjectSet(label, OBJPROP_TIME2, CandleTimeClose);
}
if (open1-close1 < 0 && Bid < OpenPrice) { // If Bid crosses/is below the OpenPrice, Change Line Color and Change CandleTimeCloseObjectSet(label, OBJPROP_COLOR, LinecolorHit);
CandleTimeClose = TimeCurrent();
ObjectSet(label, OBJPROP_TIME2, CandleTimeClose);
}
} // End CandleFactor
} // End CandleMinPip
} // End CountBarsreturn(0);
}
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Hola, I have some trouble finding the correct Logic.
With this indicator I want to get a candle body that is X amount bigger than the previous (Works so far) and draw a line at the open price (also works).
Now if the price crosses any of the lines, i would like to change its color and stop it from drawing once it's hit.
This last part is where most of my trouble sits. Right now it's obviously changing colors, but not the way I want.
I am lost finding the right logic. i.e where and how to check and save if it has been hit.
Any help is greatly apreciated.
Here is the code: